Sunday, January 25, 2015

Week 3: Geek Week

    Let's face it: we can only hide behind our screens with Atom and Emacs shielding us from the terrors of writing coherent sentences for so long - but trust me, it's not all bad (and as it turns out, it's actually really important).

    As Computer Science students (or 'geeks' as some playground-bullies would be so inclined to call us), it's important to be well-versed in a number of languages, including the English language. This is important for a number of reasons, but it can be very accurately summarized by a quote by Martin Fowler:
"Any fool can write code that a computer can understand. Good programmers write code that a human can understand"
    Computer Science is an extremely collaborative faculty that requires a lot of team work. It's rare to find a widely successful software that was created by a single entity without any discussion or help from other entities. Therefore, a single project's code base will likely be viewed by several different programmers that all add and contribute to it. For this reason, it's extremely important to not only create intelligent code, but well-written code. This means following appropriate style guidelines, including comments, and writing full and coherent docstrings. The ability to communicate your idea is almost - if not more - important than the idea itself, for if you cannot explain your genius then it's hard to believe your genius exists at all.

Let's create somewhat of a 'case-study' regarding a sample of well-written code that demonstrates how to identify all natural even numbers less than a given top_number:


Although this is a very simple example, it still demonstrates the essence of good programming.

    Variables are named with clarity and are appropriate to the situation, as opposed to vague and indiscernible names such as 'x', 'num', and 'var'. It is easy to identify what role each of the variables are playing in the scenario.
    In-line comments can be the key to unlocking all the answers of the universe - if done correctly. There are many ways to approach a given problem, so indicating what the purpose of certain data structures that may be difficult to understand otherwise, is essential. We can see in the given example that the purpose of the while loop is clear, and as a result our approach to the problem has been communicated more efficiently.
    Writing clear code can help immensely in the process of debugging, and makes the lives of the writer and the reader of the code much easier. If one were to try to trace a program without understanding how the different parts are interacting, it's safe to assume they would struggle greatly before reaching a conclusion.

    Additionally, keeping a clear and coherent log of your common mistakes can turn out to be the most useful tool you'll ever possess. Writing about a problem and tracking your progress through the issue can help you identify where your concepts are weak/strong, what improvements you can make in terms of approaching a problem, what kinds of problems you face most commonly, and ultimately how to become a better programmer.