Question: write a comment on this I'm going to go with repeating what the code does and explaining complex code in comments. Repeat Code Comments: This

write a comment on this

I'm going to go with repeating what the code does and explaining complex code in comments.

Repeat Code Comments:

This method of commenting involves leaving a comment on the code that plainly says what the code does. For example if a code in python says print("Hello World") the comment might say # print hello world. A pro of this method is that anyone who reads the code will know the purpose of the code. Therefore it makes debugging and editing more simple. A con is that this way of commenting doesn't add much value and can cause clutter. It explains the code, but the explanation is just a literal repeat of what the code obviously does.

Complex Code Comments:

This method involves explaining the code in a full manner. It'll explain in full what the portions of the code do, why it does it, and how it does it. Lets use the same hello world code from the previous example. The comment might look something like this:

""" This code demonstrates the use of the print() function in Python, which outputs text to the console.

The print() function is called with the argument "Hello, World!". - The argument is a string literal, enclosed in double quotes. - The print() function outputs the string to the console."""

A pro of using this method is that the code gets a full explanation and the developers will always know the exact purpose of the code and how it is supposed to operate. Therefore when working with a team the rest of the team won't have to spend as much time trying to communicate with one another figuring out what a section of code is supposed to do. It also helps with debugging and such. A con of this method is this may be overbearing to use on a simple program such as the hello world example I used. That much explanation isn't needed. Another con is when changes need to be made to the code, the entire comment will probably have to be rewritten as well which impacts time it takes to complete a project.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Business Writing Questions!