How to Write Good Doc Comments for a Class/Method?

Well, software engineers love to jump to the code (minus document) once design is completed. Majority of them do not write the help text around the class or methods. Some of them do write but they do not provide enough information. There are various reasons for the lack of enough comments within a class. Some of them are lack of time, lack of writing/articulation skills etc.

Following are some of the questions which would you like to answer as part of comments for method or a class:

  • Functionality: What does the class or the method do? You may want to provide information regarding the business requirement that the component fulfills. You may also want to write about the key attributes and behaviors of the class.
  • Inbound Communication: Who uses the class or calls the method on the class and why? This is also called as inbound communication of the class.
  • Outbound Communication: Which classes are called by the methods of the class? This is also called as outbound communication of the class.
  • Failure Scenarios: You may want to mention about key scenarios when failure happens and also how the failures are handled. This can be used to represent reliability aspect of the software code.

Above is the set of minimum information that you can provide for a class and their methods. The information increases the understandability of the method and the class and hence, enhances usability aspect of software quality. Thus, that increases overall quality of the software code written by you.

Ajitesh Kumar

I have been recently working in the area of Data analytics including Data Science and Machine Learning / Deep Learning. I am also passionate about different technologies including programming languages such as Java/JEE, Javascript, Python, R, Julia, etc, and technologies such as Blockchain, mobile computing, cloud-native technologies, application security, cloud computing platforms, big data, etc. I would love to connect with you on Linkedin. Check out my latest book titled as First Principles Thinking: Building winning products using first principles thinking.

Recent Posts

Agentic Reasoning Design Patterns in AI: Examples

In recent years, artificial intelligence (AI) has evolved to include more sophisticated and capable agents,…

3 weeks ago

LLMs for Adaptive Learning & Personalized Education

Adaptive learning helps in tailoring learning experiences to fit the unique needs of each student.…

4 weeks ago

Sparse Mixture of Experts (MoE) Models: Examples

With the increasing demand for more powerful machine learning (ML) systems that can handle diverse…

1 month ago

Anxiety Disorder Detection & Machine Learning Techniques

Anxiety is a common mental health condition that affects millions of people around the world.…

1 month ago

Confounder Features & Machine Learning Models: Examples

In machine learning, confounder features or variables can significantly affect the accuracy and validity of…

1 month ago

Credit Card Fraud Detection & Machine Learning

Last updated: 26 Sept, 2024 Credit card fraud detection is a major concern for credit…

1 month ago