answersLogoWhite

0

What is comment statement?

User Avatar

Anonymous

9y ago
Updated: 3/10/2022

In programming a comment is not a statement. Comments are completely ignored by compilers. In some languages, such as C, the compiler doesn't even see the comments because they were stripped out by the precompiler (which also processes macros, precompiler directives and precompiler definitions). As such, the compiler only sees the resultant C code and nothing else.

Even if a compiler could "see" a comment, it wouldn't understand it. Comments are specifically intended for code maintainers and implementers, and are used solely to explain a concept that cannot be expressed directly in code.

Comments are often a distraction. We see this in tutorial code where virtually every line has a comment because, all too often, these comments do not add anything to the code, they simply repeat what the code does in plain English:

int i = 42; // assign 42 to the variable i

i *= 2; // double the value of i

While this is useful when learning a new programming language, such comments have no place in production code. The assumption is that a code maintainer or implementer is fully conversant with the programming language, so there is no need to explain what a piece of code does; the code itself tells you what it does. Well-written code is also (largely) self-documenting, but when it is not possible to express a concept directly in code, a comment can help draw the reader's attention to that concept.

Low-level programming languages such as assembly language require verbose commentary because it is not possible to express concepts directly in low-level code. The same can be said of C to some degree, because although it is a high-level language, the level of abstraction within the language itself is extremely low. The bulk of our C code tends to consist of low-level functions that provide the building blocks for the higher level functions, but the low-level functions will require more commentary then the higher level ones.

C++, on the other hand, is extremely high-level and requires very little commentary. Although C++ does not support the notion of concepts per se (although it may do at some point in the future) we can avoid using comments through the use of constraints checks and compile time computation. Thus the compiler can provide a more meaningful error message which is much harder to ignore than a comment would be.

That's not to say we shouldn't use comments of course. Often we use them as little reminders to ourselves because we often write code that makes perfect sense at the time but when we revisit the code at a later date, our train of thought has long been forgotten. the trick is to write comments that assist the reader rather than distract the reader, and that is an art in and of itself.

User Avatar

Angelica Hirthe

Lvl 10
3y ago

What else can I help you with?

Related Questions

Comment on this statement?

"Comment on this statement." is an imperative sentence.The subject of the sentence is implied, "You comment on..."


What is the synonyms of remark?

Some synonyms for "remark" include comment, observation, and statement.


Comment on save oil save money?

This is a statement not a question.


Difference between a statement and a comment?

We can state our opinion as well as state the facts. Generally however, a comment is more of a reaction, an opinion or off-the-cuff remark; a statement is deliberate and often even prepared in advance.


What is another name for comment?

Another name or names for comment is observation, statement, utterance; pronouncement, judgment, reflection, opinion, view; criticism.


Is saying you love being white a racist statement?

That cannot be a racist statement if you are white. It is just stating a feeling, not a racist comment.


What is another term for comment?

== == two cents remark, or statement. feedback


Present package must be the first non comment statement in the file?

false


Statistics are like clay of which you can make a good or devil as you please comment on the statement?

bclhxbouL


What are synonyms of the word comment?

remark, say, note, mention, point out, observe, utter


How do you use the word comment?

comment can be a noun -- The teacher made some comments about our essays. comment can be a verb -- the teacher commented on our excellent essays.


How to remove a statement on facebook written by someone else?

If the comment is on one of your posts, pictures, or your wall, then you simply click the "x" in the upper right-hand corner of their comment. If the statement is written somewhere else other than on something of yours, you cannot delete it.