During my journey of Software Development, I am always indulged by doing research and coding, and learning new technologies as technology is changing rapidly day by day. Technological advancements are happening at an exponential rate, and the pace of change is only getting faster. New technologies are being developed and improved daily, leading to new opportunities, products, and services.
Hence as a developer, we constantly shift from one project to another but the previous projects are still modified as per requirements so the hectic code that we wrote by doing too much research has to be gone through by someone who has the responsibility of that project. So here the value of commenting into code has to take place.
Commenting is an important aspect of software development that involves adding descriptive notes or explanations to the code. The value of commenting in code during software development includes:
- Improved readability: Commenting makes code more readable and understandable for other developers who may need to work on the code. It provides context and clarifies the purpose of the code.
#Python comments start with the # character and extend to the end of the line.
name = “Sanchit Pahwa” # employee name id = 00175 # employee id role = “Software Developer”2. Easier maintenance: Comments can help make the code easier to maintain. When developers come back to the code to make changes or fix bugs, comments can help them quickly understand the code’s purpose and behavior, which can save time and reduce errors.# Comments for function
#This is a function that returns multiplication of two numbers def mul(a,b): return a*b #Calling function by specifying parameters and printing its value print(mul(10,20))3. Documentation: Comments can serve as documentation for the codebase. They can provide a record of the code’s design decisions, assumptions, and limitations, which can be useful for future reference.
#Using Python Docstring as Multiline Comment ”’ Used to provide documentation for functions, classes, and modules It is used as multiline Comment ”’ #While making API’s we use it ”’ Description: Used to fetching category name from database Body: category id, should be string Return: category name ”’ def category_name(id): ctg_name=category_database.find({“_id”:id},{“category_name”:1}) return ctg_name ”’ For every function write its description,parameters,return before start writing function and inside it if there is any mapping, looping or high complexity code write it in statements so that it is easier to read instead of debugging it. ”’4. Collaboration: Comments can help team members collaborate on a codebase by providing context and insights into the thought process behind a particular piece of code.
5. Debugging: Comments can be helpful for debugging purposes. They can help developers identify the source of a problem and narrow down the scope of their investigation.
Some extensions that help you with automatic code commenting in VS-Code Editior specifically for Python:
a. AutoComment
b. AutoDocstring
c. Python Docstring Generator
d. Pylance
Conclusion
Overall, commenting on code is a valuable practice that can improve the quality of software development. It makes code more readable, maintainable, collaborative, documented, and easier to debug.
Happy Learning!!😀😀