Practical C++ Programming by manish baranwal

Start from the beginning
                                        

The purpose of this chapter is to convince your students to put copious comments in the code.

Comments should be written as an integral part of the programming process. Time and time again I’ve

heard, “Here’s my homework, but I didn’t have time to put in the comments.”

My answer, “You should put in the comments first. I don’t mind too much if you put in the comments

and don’t have enough time to do the code, but don’t leave out the comments — ever!”

When I was grading homework I had a rubber stamp made up:

If you teach your students one thing it should be to make their programs clear and easy to understand.

Comments are an essential part of that process.

Classroom Presentation Suggestions

There should be a style sheet for the class. This can be created by the class or supplied by the instructor.

It should include a list of what you as a teacher want for the heading comments of each assignment.

Suggestions include:

• The student’s name

• The assignment number

• Student ID number

• All the other stuff detailed in this chapter

Review Questions

Page 7

1. Why are comments required in a program?

Comments provide the programmer with a clear, easy-to-read description of what the

program does. They are required because uncommented programs are hard to understand

(sometimes even the person who wrote them can’t understand them). Uncommented

programs are also extremely difficult to maintain.

As the age and complexity of software programs skyrockets, maintenance (and

comments) becomes much more important. (

2. Why must you write comments before or while you write the program, never after?

Because at the time you write the code you know what you are doing. If you leave the

commenting until later, you may forget and have to guess.

3. Which is better: 1) The underscore method of writing names, such as: this_is_a_var, or 2)

The upper/lower case method: ThisIsATest?

I like this_is_a_var myself because you can run your program through a spelling

checker. I think it is more readable. Also it allows you to use lower case only for

variables and upper case only for constants.

Some people think that ThisIsATest is more readable .

This is a religious issue and has no right answer.

Page 8

Chapter 4: Basic

Declarations and

Expressions

A journey of a thousand miles must begin with a single step.

— Lao-zi

If carpenters made buildings the way programmers make programs, the first woodpecker to come along

You've reached the end of published parts.

⏰ Last updated: Nov 04, 2012 ⏰

Add this story to your Library to get notified about new parts!

Practical C++ Programming by manish baranwalWhere stories live. Discover now