Why Is It Important?

Let us take the example of grammar. In the English language there are many situations in which a subtle use of grammar or punctuation can entirely change the meaning of a sentence. Look at the adjacent black board; you would be a little worried if someone said the latter to you! This is because it expresses an entirely different intent.

Intent is an important concept in programming. As we write code we want the reader (a colleague, someone in the future or even you!) to know what it is that you are trying to do. This becomes especially important when you work on larger projects with multiple people or more complex code that you might spend your whole Ph.D. working on. So with this, I present a few rules of grammar to follow whilst we code, all for the purpose of making our intention clear and, as a result, our code will be easier to follow...

Recommended Grammar

Here, I will outline very quickly, with examples, of what our common rules should be. These rules vary from organisation to organisation as they are not fixed in stone. I have presented what I believe to be the most commonly used rules from my experience as a developer. Let me introduce you to something called camal case. It is shown in the adjacent blackboard. so here are our rules:

For variables and functions

int lowerCamalCase = 0;

function lowerCaseFunc(){};

For classes

						class UpperCamalCase{
bool isUpper;

Here we use what is known as lowerCamalCase and UpperCamalCase. We use the lower case for variables and functions and the upper case for classes (specific to Object Orientated languages). This is so we can distinguish between the two. You might think "how will I distinguish between a variable and a function?" Well, a function will usually have a parameter list (known as a function signature) denoted by parentheses, whereas a variable will not. For example this is a variable myVariable; and this is a function myFunction(input1, input2); See the difference?

We Are Authors!

Now that we have our simple framework of coding grammar established, let us talk more about your reader. You might think that no one will read your code so why bother with all this effort into making it readable? Well you would be wrong! Even if no one else reads your code, you atleast will do! What I mean by this is that you will likely spend a relatively long time making some code and as you come back to it on different occasions you will undoubtedly think "What on Earth was I trying to do here?!" We've all been there.

To tackle this problem, I always try to emphasise the point that we, as programmers, are authors! We write code to convey some intention or functionality. In the same way a story needs to set the scene and characters to make the context of the plot clear, we should write our code in such a way that it is easy to follow, we know where our variable, functions and classes are at a glance and we can easily build upon our code once we know that.