This is How Senior developers name their functions and variables

When learning to code,one learns very early on about variables and functions and the naming conventions, However very few courses teach beginners how to name the right way. For some beginners naming the right way doesnt matter and is not a subject of interest to them. If you have decided to read this article then you probably already now know the importance of properly naming your classes, Variables, Functions, Interfaces and so on properly. You are aware of the mental load required to understand logic that uses poorly named variables, the wasted efforts and frustration involved in finding a variable or function.In this article I will be showing you how to properly name constructs such as variables, functions,classes etc and I will show you how to position variables,functions or components such that very little mental effort is required to understand the flow and logic of the codebase or functions. HOW TO NAME Your Name Should Reveal the Intention of it's Use. When you name a construct you want to be able to remember what you named it without have to reference or scroll back to its point of declaration and you also want others who work with your code to be able to work with it seamlessly.The name should tell the reader what the variable/function is doing so you need to avoid vague names like data, temp, or info you should avoid using witty names as you yourself are likely to forget it when next you visit the code again. Avoid Names that Misrepresents value or functionality When working with multiple contributors on a codebase you generally want to avoid anti patterns as well as usage of terms that could confuse or throw other contributors off. The same goes for naming. You want to avoid naming a variable with the word list when the value to be held by that variable will be a map or a set, you also want to avoid naming a function after only a part of what it does for example a function that iterables to a list, it would be unwise to name such a function "arrayToList" this could lead to under use of such function and a possible waste of time in creating a function that does what the poorly named "arrayToList" function does. Use pronounceable and searchable names A good name needs to be pronounceable and searchable especially in a codebase that is medium to large or has atleast 3 or more contributors, hence there is a need to avoid unnecessary abbreviations and acronyms not populary known (if you cannot confirm that everyone will get the abbreviation do not use it). avoid names like "blnc" use "balance" instead.This would make debugging and collaboration a lot easier and you will also benefit when walking through the logic you have written as there will be no mental effort inputed into translating an unconventional name in your head. Ditch the prefixes The reason for this is pretty simple most modern languages no longer need prefixes or hungarian notations like m_ (for member variables) they are just unnecessary and good naming conventions will cover the need for this. Your Naming Conventions Need to be Consistent When starting a project you need to have some conventions in mind and stick to them if for example you decide to name functions that make get request with a prefix of "fetch" in their name like "fetchScores()" please stick to that do not use "fetch" for one function then use "get" and then "request" your consistency will make naming easier for you and make referencing them more intuitive. Your Class and Function Names should be Nouns/Verbs Your classes should be nouns and you function should be verbs. ` class DataConverter{ } function convertData(){ } ` HOW TO POSITION When working with a codebase where by the variables and functions are terribly positioned, the cognitive effort required to read, understand, and modify the code increases significantly. This mental strain usually leads to frustration, significantly reduced efficiency, and a much higher chance of making mistakes. Thus it becomes important that the position of our variables and functions are intentionally placed. Lets look at how to do this such that the reader of our code do not strain. Functions should be ordered top-down When writing functions especially if you use the declarative approach you want the Higher order functions or the more declarative functions to come first. If a series of functions work together you want the function above to be the one that uses the function or functions below kind of like a russian Matryoshka Doll whereby as you come across the use of the function you almost immediately get to its implementation. so the functions at the top should describe more of what is happening and one scrolls down the lower level function apppear and they would describe how things are happening.This way, the reader can understand the program and logice flow by reading from top to bottom without scrolling back and forth. Declare Variables as close as Possible to Where they are Used If you de

Mar 28, 2025 - 02:01
 0
This is How Senior developers name their functions and variables

When learning to code,one learns very early on about variables and functions and the naming conventions, However very few courses teach beginners how to name the right way. For some beginners naming the right way doesnt matter and is not a subject of interest to them. If you have decided to read this article then you probably already now know the importance of properly naming your classes, Variables, Functions, Interfaces and so on properly. You are aware of the mental load required to understand logic that uses poorly named variables, the wasted efforts and frustration involved in finding a variable or function.In this article I will be showing you how to properly name constructs such as variables, functions,classes etc and I will show you how to position variables,functions or components such that very little mental effort is required to understand the flow and logic of the codebase or functions.

HOW TO NAME

  1. Your Name Should Reveal the Intention of it's Use.
    When you name a construct you want to be able to remember what you named it without have to reference or scroll back to its point of declaration and you also want others who work with your code to be able to work with it seamlessly.The name should tell the reader what the variable/function is doing so you need to avoid vague names like data, temp, or info you should avoid using witty names as you yourself are likely to forget it when next you visit the code again.

  2. Avoid Names that Misrepresents value or functionality
    When working with multiple contributors on a codebase you generally want to avoid anti patterns as well as usage of terms that could confuse or throw other contributors off. The same goes for naming. You want to avoid naming a variable with the word list when the value to be held by that variable will be a map or a set, you also want to avoid naming a function after only a part of what it does for example a function that iterables to a list, it would be unwise to name such a function "arrayToList" this could lead to under use of such function and a possible waste of time in creating a function that does what the poorly named "arrayToList" function does.

  3. Use pronounceable and searchable names
    A good name needs to be pronounceable and searchable especially in a codebase that is medium to large or has atleast 3 or more contributors, hence there is a need to avoid unnecessary abbreviations and acronyms not populary known (if you cannot confirm that everyone will get the abbreviation do not use it).
    avoid names like "blnc" use "balance" instead.This would make debugging and collaboration a lot easier and you will also benefit when walking through the logic you have written as there will be no mental effort inputed into translating an unconventional name in your head.

  4. Ditch the prefixes
    The reason for this is pretty simple most modern languages no longer need prefixes or hungarian notations like m_ (for member variables) they are just unnecessary and good naming conventions will cover the need for this.

  5. Your Naming Conventions Need to be Consistent
    When starting a project you need to have some conventions in mind and stick to them if for example you decide to name functions that make get request with a prefix of "fetch" in their name like "fetchScores()" please stick to that do not use "fetch" for one function then use "get" and then "request" your consistency will make naming easier for you and make referencing them more intuitive.

  6. Your Class and Function Names should be Nouns/Verbs
    Your classes should be nouns and you function should be verbs.

`

class DataConverter{
}

function convertData(){
}

`

HOW TO POSITION

When working with a codebase where by the variables and functions are terribly positioned, the cognitive effort required to read, understand, and modify the code increases significantly. This mental strain usually leads to frustration, significantly reduced efficiency, and a much higher chance of making mistakes. Thus it becomes important that the position of our variables and functions are intentionally placed. Lets look at how to do this such that the reader of our code do not strain.

  1. Functions should be ordered top-down
    When writing functions especially if you use the declarative approach you want the Higher order functions or the more declarative functions to come first. If a series of functions work together you want the function above to be the one that uses the function or functions below kind of like a russian Matryoshka Doll whereby as you come across the use of the function you almost immediately get to its implementation. so the functions at the top should describe more of what is happening and one scrolls down the lower level function apppear and they would describe how things are happening.This way, the reader can understand the program and logice flow by reading from top to bottom without scrolling back and forth.

  2. Declare Variables as close as Possible to Where they are Used
    If you declare a variable far from it's point of use, the reader would have to jump around to track its changes requiring more mental strain and increased debug time.

  3. Avoid global variables as Much as Possible
    Nothing is inherntly wrong with using global variables however If a variable is only used within a small scope, just define it inside that scope instead of doing so on a global scale.
    excessive use of global variables will make reasoning about state harder and brings about a higher risk of unintended side effects as it is easier to accidentally modify important state.

  4. Always Group Relate Code Together
    If two functions are closely related say one calls the other, then place them near each other Similarly, if a variable is mainly used by one function, keep it close to that function. Doing this help to avoid Breaking logical flow beacuse When helper functions are placed above main functions, it forces developers to read the details before understanding the high-level logic which is in no way ideal.

  5. Do not shy away from making your functions smaller
    This tip helps more with reusablity and so it is worth mentioning. A function should do one thing and do it well. If a function is too large, break it into smaller, more focused functions beacuse if a function is buried deep within another function when it could be useful elsewhere, it would be reducing maintainability which is a whole other can of worms .

Bad naming and poor function and variable placement always force developers to work harder just to understand the code before they even make a single change, However a well-structured codebase, on the other hand, should minimize unnecessary thinking while letting developers focus on solving real problems rather than struggling to navigate the code.

I hope the above tips have been helpfull and if you do have questions or need clarity relating to something above feel free to ask in the comment section or contact me and I will respond as soon as I can