The Reason: Getting in the habit of minimising the number of lines inevitably leads to hard-to-understand and hard-to-maintain code.
To demonstrate this, let’s do a contrived but a simple exercise.
Shown below are different versions of the same code written in different styles - concisely and verbosely.
Verbose Style
1-1.c (Version 1)
void Foo (int, int);
void Bar (int, int);
void FooBar (int, int, int);
const int fooVal = Foo (2, 3);
const int barVal = Bar (2, 3);
FooBar (1, fooVal, barVal, 6);
1-1.c (Version 2)
void Foo (int, int);
void Bar (int, int);
void FooBar (int, int, int);
const int fooVal = Foo (2, 3);
const int barVal = Bar (4, 3);
FooBar (1, fooVal, barVal, 6);
Concise Style
1-2.c (Version 1)
void Foo (int, int);
void Bar (int, int);
void FooBar (int, int, int);
FooBar (1, Foo (2, 3), Bar (2, 3), 6);
1-2.c (Version 2)
void Foo (int, int);
void Bar (int, int);
void FooBar (int, int, int);
FooBar (1, Foo (2, 3), Bar (4, 3), 6);
Now do the following.
Create 4 files from above - 1-1.c, 1-1.c.1, 1-2.c, and 1-2.c.1:
- Copy and paste version 1 of 1-1.c to a text file named 1-1.c;
- Copy and paste version 2 of 1-1.c to a text file named 1-1.c.1;
- Copy and paste version 1 of 1-2.c to a text file named 1-2.c;
- Copy and paste version 2 of 1-2.c to a text file named 1-2.c.1;
Using your favourite tool (for example, command-line diff tool or FileMerge App), compare:
- 1-1.c to 1-1.c.1; and
- 1-2.c to 1-2.c.1
In which style of code did you find it easier to be able to tell precisely what has changed?