The Purpose of Code

Ask yourself why you write code. If the answer to that question was “to create software”,  you might as well have done it using nothing but zeros and ones, or punchcards for that matter. In fact, creating software by directly modifying bits and bytes will probably result in much faster and optimized software than going through the abstraction of code. Let me illustrate with an example, imagine the following.

class EFRoutingCollectionHasIdCollection : IEFRoutingCollectionHasIdCollection
{
    public bool? GetRoutingCollectionHasIdIfNecessaryClientExists(SomeRidiculouslyLongPocoTypeName entity)
    {
        /* ... I think you get the idea ... */
    }
}

What is wrong with the above code? Let me give you a hint; It’s almost impossible to understand for a human being. Sure, a computer might perfectly understand it, but to a human being, the above code is one notch away from being zeros and ones …

We write code such that other human beings can understand what we are trying to accomplish

That’s it! Arguably the entire explanation of why we’re using code as an abstraction. If you structure your code beautifully, and create reasonable variable names, methods, and class names, 2 years down the road, any seasoned developer can pick up your code, and continue where you left it, without having to spend months simply trying to navigate your class hierarchy, to understand your intentions. In fact, if your compiler also happens to be able to actually create working software out of your code, that’s arguably a *bonus*.

Do me a favour, and look at your code. Is it easily understandable? Can somebody else pick up your code, and start modifying it, without requiring any instructions as to what it does? If the answer to that question is yes, you have achieved something good, and you have created something great. If the answer to that question is no, you should probably refactor your code, and restructure it. Creating great code is hard, very hard, but if you want to create great software, larger than yourself, the benefits of refactoring and restructuring your code “one additional time” always pays off.

Great code is beautiful. You can immediately understand it. In fact, even a person who has never done any software programming himself can also to some extent understand great code. Great code contains as few “clever structures and algorithms as possible”, and can instantly be expanded upon by others. If you are able to somehow write perfect code, comments are arguably superfluous, and the code describes what it does, and spending time teaching somebody else how to maintain your code, is no longer necessary, and your colleagues will hail you, and be happy every time somebody tells them that they are to continue maintaining one of your projects.

Great code is Poetry to the minds of your peers!

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.