Professional Documents
Culture Documents
L05 - Program Formatting
L05 - Program Formatting
29 February 2024
COS132 Program Structure and Output
Types of comments
Commenting and Indenting Code Commenting practices
Layout Rules
Layout Rules
Good and consistent code layout
enhances code readability.
If code is readable, it is inherently more
understandable and consequently
reliable and maintainable.
We will look at some pointers on layout
that need to be taken into account a
promote code readability.
COS132 Program Structure and Output
Types of comments
Commenting and Indenting Code Commenting practices
Layout Rules
Example Style 1
1 #i n c l u d e <i o s t r e a m >
2
3 using namespace s t d ;
4
5 i n t main ( )
6 {
7 c o u t << ” Programming i s g r e a t ! ”<<e n d l ;
8 return 0 ;
9 }
Example Style 2
1 #i n c l u d e <i o s t r e a m >
2
3 using namespace s t d ;
4
5 i n t main ( ) {
6 c o u t << ” Programming i s g r e a t ! ”<< e n d l ;
7 return 0 ;
8 }
Example Style 3
1 #i n c l u d e <i o s t r e a m >
2
3 using namespace s t d ;
4
5 i n t main ( )
6 {
7 cout <<” Programming i s g r e a t ! ”<< e n d l ;
8 return 0 ;
9 }
Use of indentations
COS132 Program Structure and Output