DEV Community

Cover image for Programme Structure
Sachin Pant
Sachin Pant

Posted on

Programme Structure

What is Programme Structure

Just like any spoken language where we have distinct parts in a sentence which have a meaning of their own and when they combine they form a bigger sentence, and when we combine these sentences we can have different styles of writing such as a paragraph, poem, article etc similarly in programming we have different fragments which are called expressions which have their own value. When we stitch together these fragments we get what we call a programme.

Bindings - (Variable Storage)

Bindings could be compared to an Octopus' tentacles as they are there to grasp different things as per the requirement, likewise in programming a value is grasped as per the requirement by a variable. This helps to maintain the internal state of the programme.

Binding Names

Binding names or variable names have certain rules that everyone has to follow. It can't start with a numerical. It cannot have a special character except '$' or '_ '. We can't keep keywords as variable names, for e.g. 'Let', 'Var' etc.

Functions

Our main aim of programming is to reduce work and functions help us do that. It is a value which keeps changing on giving different arguments. We execute a function by writing its name followed by parenthesis. This process is known as calling a function. There are a lot of pre defined functions in any language, for e.g. in Javascript one of those is 'Console.log()'. It is used to output a value to the console of a browser.

Control Flow

When we execute a programme it is executed from top to bottom. The control flow depends on the type of executions we have given in the programme. All programmes don't execute linearly. Some of them divide like a highway or branch out like a tree. This type of execution takes place in conditional execution.

Conditional executions can be created with the use of different keywords in Javascript. For example if, while, for etc.

Indenting Code

The compiler doesn't execute the code according to lines it can execute a long straight-line code. But for practical purposes and for our understanding we use proper indentation i.e. proper spacing between new open block. Most code editors these days come with tools to help look the code beautiful.

Breaking out of a Loop

It is very important that our code should not be an open ended code that means a code which will not or cannot stop itself and it will keep iterating over itself. It could make our coding environment irresponsive which could lead to loss of work. There are different methods to break out of a loop apart from defining the conditional breaking out of the loop.
the expression 'break;' is one method to come out of the enclosing loop it is in. The other expression is 'continue', It doesn't stop and comes out of the loop, it jumps out of the body and continues with the next iteration.

Updating Bindings Succinctly

There are many ways to increase the value of a variable in a loop. In conventional way we write the whole equation like this:

counter = counter + 1;

But to type quickly, Javascript offers shortcuts such as

counter += counter

even more shorter equivalent is

counter++

Capitalisations and Comments - Accepted Practices

How to use capitalisation when declaring variables.

  1. smalllittlekitten - As we can see this could be confusing at times to understand what is written, so we avoid declaring variables like this.

  2. smallLittleKitten - This is an accepted format and it is easy for the reader to interpret what is written.

  3. SmallLittleKitten - The first letter cannot be a capital and this is not an accepted format.

  4. small_little_kitten - This is also allowed but it could really look too big when we name a complex and an important variable.

What if someone else has to read a code written by you. If you want explained what exactly a function is doing or haven't written a code following the best practices the reader might get confused. To tackle those situations we should try and inculcate the habit of writing comments wherever you feel the reader might get confused. As it is often said a good code is not a code that is easily executed by a machine but that one which is easily understood by a human.

Conclusion:

Programme Structure is the process flow of a programme from execution, to control flow to how a programme ends. So, how we write a programme to the logics we use everything matters in a programme and comes under the umbrella of programme structure.

#teamtanayejschallenge

Top comments (0)