I learned programming in high school, where we studied Pascal to solve simple, dumbed-down high school problems. It wasn't very exciting, and I came to think of programming as a "tool to automate stuff"; a useful but uninspiring skill worth knowing, like sewing or something. ![pause](/media/images/pause.png) Then I went to the university, where we studied Scheme. This was something else *entirely*: I mean, this language was *beautiful*. Sometimes you saw something so clever or bizarre it actually made you *laugh*; and so I came to think of programming as poetry. I realize this sounds pompous, but I mean it: we were trying to express some complex idea under the constraints of some language, and we were trying to do so in the most elegant way possible. Maybe the definition of elegance was somewhat different, but the process was similar - and I loved it. ![pause](/media/images/pause.png) Then I went to the military, and again, this was something completely different: we were using C, and this time I came to think of programming as studies in law. Here's how it went down: "Can you write a program that prints 'Hello, world!' in C?" They asked. By this time, I had a B. Sc. degree in mathematics and computer science, so naturally I thought I could. This is what I came up with: ```c #include <stdio.h> int main() { printf("Hello, world!\n"); return 0; } ``` "What is this lousy code?" They asked, "What if ``printf`` fails? Why don't you check its return value?" What. I didn't even know ``printf`` had a return value. OK, let's fix it: ```c #include <stdio.h> int main() { if (printf("Hello, world!\n") == -1) return -1; return 0; } ``` "Why is ``-1`` hardcoded? Where are the curly braces, in case your clauses grow in the future? And use [Yoda notation](https://en.wikipedia.org/wiki/Yoda_conditions)!" They bellowed. OK, Jeez: ```c #include <stdio.h> #define MESSAGE ("Hello, world!\n") #define SUCCESS (0) #define FAILURE (-1) int main() { if (-1 == printf(MESSAGE)) { return FAILURE; } return SUCCESS; } ``` "What is this loser program? One hiccup and it exits with a failure? What are you, some kind of pacifist? Stop being such a god damn wimp and MAKE IT WORK ALREADY!" They kinda went Full Metal Jacket on me. So then: ```c #include <stdio.h> int main() { const char *message = "Hello, world!\n"; const size_t length = strlen(message); size_t printed = 0; int retval; while (printed < length) { retval = printf(message + printed); if (-1 == retval) { continue; } printed += retval; } return 0; } ``` "Your program can get stuck in an infinite loop, you know." They said with a smug smile. ```c #include <stdio.h> #define SUCCESS (0) #define FAILURE (-1) #define MAX_ATTEMPTS (100) int main() { const char *message = "Hello, world!\n"; const size_t length = strlen(message); size_t printed = 0; int attempt = 0; int retval; while ((printed < length) && (attempt < MAX_ATTEMPTS)) { attempt++; retval = printf(message + printed); if (-1 == retval) { continue; } printed += retval; } if (printed < length) { return FAILURE; } return SUCCESS; } ``` Motherfuck. But, the lesson was learned: read the entire ``man`` page. Consider all the edge cases. Pay attention to magic numbers, return values, conventions - everything. Be *meticulous*. ![pause](/media/images/pause.png) If you ask me to write a program that prints "Hello, world!" in C today, this is what I'd write: ```c #include <stdio.h> int main() { printf("Hello, world!\n"); return 0; } ``` But I'd do so for entirely different reasons. Charlie Parker, one of the best Jazz musicians of all times, once said: "You've got to learn your instrument. Then, you practice, practice, practice. And then, when you finally get up there on the bandstand, forget all that and just wail." It's funny to apply this to programming; but I like it. Yeah, programming is a useful tool; and it's also poetry; and it's also law studies; and it's also Jazz. Once you understand something thoroughly, you can't keep thinking about it in just one dimension; and that multidimensionality - that mental prism you develop - is what makes a good programmer; or any expert for that matter. At least, in my opinion. But what do I know, I couldn't even write a hello world program. ]: