“In programming, the only standard is its syntax.”
There’s no standard on how a programmer write his program. It’s always a matter of how a programmer should know how he will solve the problem in his own style. The only thing that matters is that the program should behave the way it must be. Eventhough, there are things that a good programmer should practice. Let me show you this list.
Best Practices in Programming
1. Naming Conventions
This practice was always taught in College. If you are going a variable, name it in a way that it could be recognized easily.
intAge >> an integer that returns age
douSalary >> a double that returns salary
strAddress >> a string that returns an address
In this way, a programmer can easily recognize the use of variables and the data type they should return. Another thing is naming a method/ functions/ subroutines.
Most of the times, we used comments to define what our method/ function/ subroutine will do. Instead of doing this, why not give it a name where it’s purpose could be easily recognize?
I believe that you already understood what these functions will do even I do not put a definition as comment beside them.
Honestly, I am often guilty for not using it. But, I am only guilty on short programs. But for working on a large project, I use that style. On my previous post How Important Is A Program’s Documentation, I explained how important the program’s documentation is. And by following this practice, the code will serve as the documentation itself.
2. Case Sensitivity
This practice is applicable if you plan to run your program on different platforms. By the way, some programming languages are case sensitive itself. I think, the best example I could give here is the Java language which has the capability of being executed on different platform as long as there is JVM.
When working with Java in Windows OS, intAge is the same as IntAge and intAGE. But your program will encounter errors if you run it on Linux.
So, the best practice is, always think it’s case sensitive.
I mean, the brackets, curly braces, semicolons, etc. Though there are good IDE which already gave solutions with this problem, it’s better to practice it.
I will just use an example for languages that use semicolons because using brackets, curly braces, and parentheses are common sense.
printf (“Hello World!”);
How do you used to write that code? Of course, you will type printf first. Isn’t it? Most of the times, semicolon in the end was forgotten. So, my tip is, put the semicolon first everytime.
4. That’s all!
Again, those are not standard. They are the best practices. You may use them or not for your own purpose. Again, the important thing is that your program should run the way it must be.
I hope you’ve learned something.