The Link Between Critical Thinking & Programming
For as long as I remember, it has always occurred to me that in order to program, one must execute specific memorized lines of code whenever appropriate or applicable. Little did I know that programming is more than just placing the fitting line of code in the right place.
After reading the works of David Thomas & Andrew Hunt, and Robert C. Martin, I was immediately able to see the connection between programming and critical thinking in Carl Sagan's "The Fine Art of Baloney Detection". I came to the conclusion that programming languages, like common oral languages, are practically the same. Conjunctions and disjunctions exist in both. Additionally, in order to get from point A to point B, one would have to logically link all the points in between.
The one thing that differentiates programming languages from oral languages is, instead of using them to converse with humans, they are used to communicate with machines. Code differs from one developer to another, just as handwriting does between individuals. Moreover, different logical approaches are usually taken by different developers to get to a point, similar to how different modes of discourse are utilized by different authors to prove an argument.
Carl Sagan's Baloney Detection
In his article, Carl Sagan expresses the importance of critical thinking using those who accept a situation without analyzing it, or explaining it logically and scientifically as an example. Furthermore, Sagan introduces the tools of Baloney Detection, such as:
- Thinking of multiple hypotheses and eliminating them one by one until only the correct one remains
- Questioning all hypotheses even if it is yours
- Making sure all arguments link to one another (a chain is no stronger than its weakest link)
These tools can be referred to in order to approach a situation rationally, to analyze and to explain seemingly impossible things rather than accept things the way they seem to be. In addition, Sagan promotes critical thinking in order to differentiate facts from fiction, scientific explanations from hypotheses and the truth from baloney.
The Pragmatic Programmer's Approach
Similarly to Sagan, Andrew Hunt & David Thomas stress the importance of critical thinking in their book "The Pragmatic Programmer". Hunt & Thomas imply that the philosophy used while approaching problems and their solutions, the style and the attitude, distinguishes Pragmatic Programmers from impractical and irrational Programmers.
Additionally, a Pragmatic Programmer places the immediate problem in larger context, thinks further and seeks out the bigger picture. Hunt & Thomas present a prime example of irrationality in code, which is writing contradictory lines of code, that is referred to as duplication. Hunt & Thomas provide an example of duplication from Star Trek: James T. Kirk's favorite way of disabling marauding artificial intelligence is giving a computer two contradictory pieces of knowledge, where the same principle applies for a developer's code.
Hunt & Thomas also point out that as Pragmatic Programmers, our main source of material is not fuel or iron, but rather knowledge and solid logic. Additionally, Hunt & Thomas imply that machines are meant to receive the developer's logic as precise pieces of code, therefore, the machine's logic is equal to the developer's logic, and it cannot be flawed.
Clean Code and Simple Design
In his book, "Clean Code: A Handbook of Agile Software Craftsmanship", Robert C. Martin emphasizes the importance of a design producing a system that acts as intended. Similar to Sagan, Robert C. Martin presents a programmer's version of the tools of baloney detection called the "Kent Beck's four rules of Simple Design".
These tools exist in order to help programmers create good designs and gain insight into the structure of their code. Additionally, these tools facilitate the emergency of good design and provide great assistance in creating well-designed software. These tools are:
- Running all the tests
- Making sure that duplication doesn't exist
- Expressing the intent of the programmer
- Minimizing the number of methods in addition to simplifying the logic used
"Systems that aren't testable aren't verifiable. Arguably, a system that cannot be verified should never be deployed."
Thus, a programmer's logic should be solid, fluid and understandable, but simple in order for the machine to process its objective. However, Martin also shows the similarities between programming and art, implying that one cannot write clean and elegant programs in one pass, just as one cannot write a best-selling novel or book in one pass.
To write clean code, you must first write dirty code and then clean it.
Final Thoughts
Although software developers and programmers have different philosophical approaches to problems, methods, styles and designs, they all rely on critical thinking and impenetrable logic to achieve their goals. The works of Andrew Hunt & David Thomas, and Robert C. Martin, have provided key examples of critical thinking which directly correlate to Carl Sagan's article.
Finally, my understanding of approaching problems philosophically and seeing the bigger picture has been immensely broadened, and the tools in my arsenal to combat baloney have grown exponentially. I would personally recommend these two books to anyone that is passionate about programming and software developing like I am.
References
Hunt, A., & Thomas, D. (2019). The Pragmatic Programmer: your journey to mastery (2nd ed.). Addison-Wesley Professional.
Martin, R. C. (2009). Clean Code: A Handbook of Agile Software Craftsmanship. Upper Saddle River, NJ: Prentice Hall.