Programming Style ----------------- Most chapters of the textbook have a section called "Style". Many useful suggestions are made in those sections. You are strongly encouraged to pay special attention to those as you will develop your programming habits in this course and those habits will stay with you (most likely, forever). Programming style has a major effect on "program readability", which has a major effect on "software maintenance", which is a major portion of "software cost". Issues discussed in the textbook include: 1. comments 2. variable names 3. spacing within a statement and between statements 4. indentation Indentation ----------- There are several indentation styles. It doesn't matter which one you choose to follow; what's important is to be consistent in your program, i.e., follow the same style throughout the program, i.e., don't change the style from one section of the program to another section of the program. Below are some sample styles (using if-then-else): if ( condition ) { statements } else { statements } if ( condition ) { statements } else { statements } if ( condition ) { statements } else { statements } Examples: if ( grade > avg ) { statements } else { statements } if ( age > 50 && salary < 50000 ) { statements } else { statements } if ( (age > 50 && sal < 50000) || (age < 20 && sal > 20000) ) { statements } else { statements } The while loop will have three similar options: while ( condition ) { statements } while ( condition ) { statements } while ( condition ) { statements } The for loop (and other constructs) will be similar. Examples: for ( k = 1; k <= 100; ++k ) { statements } for ( k = 1; (k <= 100 && sum < 1000); ++k ) { statements } for ( k = 1; k <= 100; ++k ) { statements }