Important Coding Standards and Best Practices to Follow

Important Coding Standards and Best Practices to Follow


Use meaningful names with correct naming scopes:

Use meaningful names for variables, functions, classes, arguments, modules, packages, directories, etc. The names should be self-explanatory and should convey the purpose of the code.

For Example:

  • Variable names: Variable names should be in lowercase, camelCase, and use underscores to separate words. For example, first_name or last_name or firstName or lastName
  • Function names: Function names should also be in lowercase and use underscores to separate words—for example, calculate_area or reverse_string.
  • Class names: Class names should start with a capital letter and use camel case to separate words. For example, Car or PersonDetails
  • Module names: Module names should be in lowercase and use underscores to separate words. For example, date_utils or string_operations
  • Package names: Package names should be in lowercase and use underscores to separate words. For example, data_utils or string_operations
  • Avoid writing unnecessary comments: Comments should be used sparingly and only when necessary. The code should be self-explanatory and easy to understand without comments. However, when adding a code comment, consider following these code comments best practices:


Not to use Unnecessary and unwanted comments,

Comments should be used sparingly and only when necessary. The code should be self-explanatory and easy to understand without comments. However, when adding a code comment, consider following these code comments best practices:

  • Make comments meaningful. Comments should not duplicate the code.
  • Try to make it shorter?
  • Comment on your classes, methods, and functions.
  • Use clear and concise language.
  • Use correct grammar and punctuation.
  • Be consistent with your commenting style.
  • Include reference links when relevant.
  • Write comments at the same time you’re writing the code.comments are necessary but unused words in the comment are a bad habit, always try to avoid it, always try to avoid meaning less comments.

// This function checks if a number is even.
function isEven(number) {
//checking if reminder is equal to zero
  if (number % 2 == 0) { //if its equal to zero return true else false
    return true;
  } else {
    return false;
  }
}        

Write readable code for people:

Code should be written for people to read, not just for machines to execute. It should be easy to read and understand for other developers.

For example bad readable code 
// This function checks if a number is even.
function e(n) {
  if (n % 2 == 0) {
    return true;
  } else {
    return false;
  }
}        
// This function checks if a number is even.
function isEven(number) {
//checking if reminder is equal to zero
  if (number % 2 == 0) { //if its equal to zero return true else false
    return true;
  } else {
    return false;
  }
}        

if you compare them you will find differences such as good variable name, current function name that is telling about itself by own, and yes with good and readable comments


Use version control, good developers use version control like git

Version control like git or SVN, etc is essential for managing changes to the codebase. It allows you to track changes, collaborate with others, and revert to previous versions if necessary.

There are many version control tools available, but one of the most popular and widely used is git but the good practice is the same for all types of version controls.

  1. Keep your code clean and organized: Version control is not only about tracking changes but also about maintaining the quality and readability of your code. You should follow consistent coding standards and conventions, such as indentation, spacing, naming, comments, etc. You should also refactor your code regularly, and remove any unused or redundant code. This will make your code easier to understand, debug, and maintain.
  2. Use branches for different features or tasks: A branch is a parallel version of your code that diverges from the main line (usually called master or main). You should create a new branch whenever you want to work on a new feature, fix a bug, or try something out. This way, you can isolate your changes from the rest of the codebase, and avoid conflicts or errors. You should also name your branches according to their function or purpose, such as feature/login, bugfix/typo, or experiment/animation.
  3. Commit often and with meaningful messages: A commit is a snapshot of your code at a certain point in time. You should commit your code frequently, preferably after completing a small and coherent task. This way, you can easily track your progress, revert to a previous state if needed, and identify the source of bugs or errors. You should also write clear and concise commit messages that describe what you did and why. This will help you and others understand the history and purpose of your code.


Thats all, This article focusing was solely on good aspects for having strong coding habits and becoming a good developer. In short this article is only for beginers but that does not mean its useless for pro-developers with experiece.


要查看或添加评论,请登录

Rajneesh T.的更多文章

社区洞察

其他会员也浏览了