General Concepts of Programming Methodology

Comments

Concepts of Programming Methodology

Programming is basically solving a particular problem by giving coded instructions to the computer. Furthermore, the whole scenario of the programming cycle involves writing, testing, troubleshooting, debugging, and maintaining a computer program. Moreover, a good program should have clarity and simplicity of expressions, should make use of proper names for identifiers, contain comments, and have a proper indentation.

Programming Process Cycle

The steps of programming are as follows:

Writing

This step involves writing the desired output of the code. besides, drawing a flowchart depicting all the steps from beginning to end. Then the programmer writes the first copy of the code on the programming software.

Testing

This step is about testing the code against the test cases. If the output is according to desired test cases, the code is correct.

Troubleshooting

After testing the program we perform the error correction in this step.

Debugging

It is the process of finding the exact location of the error in the code.

Running

After all these steps the program is run to get the desired output.

What is an efficient program?

A program that gives the correct desired output for every input, including the wrong input is an efficient program. Moreover, it should produce correct results in less time and use less memory space. Besides, an efficient program should have clarity and simplicity of expressions, should make use of proper names for identifiers, contain comments, and have a proper indentation. Here, we will study the comments in detail.

Comments

A comment is basically a text note that gives an explanation about the source code. Furthermore, they act as documentation in the source code. We include comments to increase the readability of the program. Besides, comments make it easy for the programmer to remember the complex things added to the code. They describe what a function does, or explain the working of a particular block of code, etc.

Moreover, the compilers and interpreters ignore these comments and do not execute them. There are different ways to write the comment in each programming language. Besides, we write them in simple English language in every programming language.

Types of comments

There are mainly two types of comments as follows:

Line Comments

These are basically the single-line comment.

Block Comments

These are the multi-line comment. There are different ways of writing comments in each programming language. Moreover, the multi-line comment symbols can be used for single-line comments as well.

Browse more Topics Under General Concepts of Programming Methodology

Uses of Comments

There are several uses of them as follows:

Reviewing and maintaining the code

We can easily write the pseudocode in the comment section. This helps while reviewing the code since understanding the pseudocode is easier.

Describing the code

The programmer can add a comment before each block of code so that the readers can understand the use of that particular block or statement. This increases the readability of the program. Besides, this portrays the intention of the programmer for writing that code.

For example:

{

/* multiline comment

integer variable to store the value of sum */

int sum;

}

Describing the logic and algorithm

The programmer can use comments for explaining the logic, equation, formula, or mathematical proofs included in a program.

Adding resources

We can use a comment to include resources like logos, diagrams, flowcharts, etc. Moreover, we can also embed the copyright-terms and conditions of the program.

Adding metadata

We can further use a comment to include metadata in order to increase the maintainability of the code. The metadata can be the name of the original creator, current people editing the code, data of the first version of code, etc.

Debugging

It is a common approach to use print statements for finding errors in the code. Furthermore, using a print statement we can check the expected output at various points in a code. Later, we simply make these statements as a comment because we don’t have to execute them in actual output. For example,

int m=1;

while (m>10)

{

a=a+b;

// cout<<a; here we are using this statement to check the value of a in every iteration and try to find the error

++m;

}

Documentation

writing the metadata and documentation in comments makes the documentation process easy. Moreover, the comments update as we change the code hence the documentation also remains up to date. They may include header files, file’s revision number, etc. They are called annotations.

Comments in different programming languages

There are different syntaxes for writing comments in every programming language. Some common languages and their syntax for writing a comment are as follows:

C/C++

Both C and C++ use:

// symbol for writing a single line comment. For example:

//Hello world

/*     */ symbol for writing multi line comment. For example:

/* hello

world

world

hello */

Java

Java programming language uses the same syntax for the single line and multiline comments. Moreover, it also has java documentation comments.

// symbol for writing a single line comment. For example:

//Hello world

/*     */ symbol for writing multi line comment. For example:

/* hello

world

world

hello */

Java documentation comments: Java uses this type of comment for creating the documentation API. Besides, you can use the Javadoc tool for creating this API. It uses /**       */ symbol for this comment. For example:

/** this

is

a

documentation comment */

Javascript

Again, the syntax is the same as C, C++, and Java.

// symbol for writing a single line comment. For example:

//Hello world

/*     */ symbol for writing multi line comment. For example:

/* hello

world

world

hello */

Python

In python, we use the # symbol for writing the comments

The single-line comments use a single # symbol. For example:

#hello python

The multi-line comments either use a single # symbol or string literal ”’. For example:

# a

# multiline

# comment

”’ second method

of writing

a multiline comment. ”’

Frequently Asked Questions (FAQs)

Q1. What is programming?

A1. Programming is basically solving a particular problem by giving coded instructions to the computer.

Q2. What are the steps of writing a successful program?

A2. The whole scenario of the programming cycle involves writing, testing, troubleshooting, debugging, and maintaining a computer program.

Q3. What is a comment?

A3. A comment is basically a text note that gives an explanation about the source code. Furthermore, they act as documentation in the source code.

Q4. What is the main purpose to use a comment?

A4. We use comments mainly to increase the readability of the program.

Q5. What are the two basic types of comments?

A5. There are mainly two types of comments as follows:

  • Line comment
  • Block comment

Q6. Which language use // for single line comment?

a) Java

b) C

c) C++

d) all of them

A6. d) all of them

Q7. Which language use /*   */ for multi-line comment?

a) Java

b) C

c) C++

d) all of them

A7. d) all of them

Q8. State true or false with reason:

Python uses // for single-line comments.

A8. False, because python uses # for a single line comment.

Share with friends

Customize your course in 30 seconds

Which class are you in?
5th
6th
7th
8th
9th
10th
11th
12th
Get ready for all-new Live Classes!
Now learn Live with India's best teachers. Join courses with the best schedule and enjoy fun and interactive classes.
tutor
tutor
Ashhar Firdausi
IIT Roorkee
Biology
tutor
tutor
Dr. Nazma Shaik
VTU
Chemistry
tutor
tutor
Gaurav Tiwari
APJAKTU
Physics
Get Started

Leave a Reply

Your email address will not be published. Required fields are marked *

Download the App

Watch lectures, practise questions and take tests on the go.

Customize your course in 30 seconds

No thanks.