Chapter 4. Thinking in Objects
A funny thing happened on the way to the future. Computers became much more powerful, and developers decided to take advantage of this potential by making software that did a lot more than just process one instruction at a time on the command line.
They built more sophisticated interfaces that could do a lot of things at once. This allowed software to tackle complex tasks like nonlinear video editing and 3D modeling. But creating programs with such sophisticated user interfaces required a lot of code.
Expert engineers love simplifying code. They’re obsessed with it. Good programmers think of ways to write code more quickly, but great engineers think of ways to write less code to do the same job. There’s a good reason for this. The less code you have, the easier it is to understand and improve.
The functions in earlier chapters do a calculation and return a result. You store the result in a variable, and then pass it into another function, like this:
#include <stdio.h>
#include "types.h"
main () {
char* itemType = "Document";
int itemCount = countForItemType ( itemType );
int itemTotal = totalForCountOfType ( itemCount, itemType );
char* totalString = formattedTotalForType ( itemTotal, itemType );
printf ("The total for %s is %s", itemType, totalString);
free ( totalString );
}
C is a procedural language, which means that functions and the data are separate, and the code is fairly linear. You can also say that C is a static language. This means that all ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access