GOOD PROGRAMMING GUIDE

“Any fool can write code that a computer can understand. Good programmers write code that humans can understand.”-Martin Fowler

When you first start programming there are a few things that may seem small, but are very necessary in order to have the most efficient lines of code. Your program needs to be not only functional, but also understandable; and it can be so following the below rules: 

Be careful with NAMING

Analyzability = Readability + Understandability. As a programmer you should keep your work organized, so that it is easier for you to find a specific task when needed. This simplicity starts with naming that you give to projects, classes, methods, variables etc. The naming of these elements should be meaningful and should relate to the function that they are going to have. For example, if you are going to make a method to calculate the average grade of student, then the method’s name should be something like calculateGPA() or studentGPA(). The name that you give to classes, variables, functions should tell why it exists, what function it has and how it is being used. 

The code below calculates the arithmetic mean of inputted numbers. It is calculated by adding the numbers and diving the sum by the total number of values. The name of the class is Calculate Mean, which is makes sense for the function that this class has, and the variables are named as necessary: numbers, mean, sum, which are the elements needed to calculate the mean. 








SPACING, TABS, NEW LINES

As we know the compiler doesn’t have any problem to run a code that has even 5 lines of code and 100 spaces between them. The same thing happens if we do not use spacing, tabs or new lines at all. As long as the syntax of the program in correct, it will compile. Still, this way the code cannot be readable, thus we need them. 

For example the code above performs the decryption process on Vigenere cipher. You can easily find this method by its name "vigeneDecrypter", but the organization of the code is confusing to focus on. The easiest way is to use "Format" from the IDE that you are using, and it will automatically fix this issue. 

Now we can see that the code is much clearer and easier to understand. 

Keep it SIMPLE

You may have heard this thing a lot of times, but is very important not to add complexity to the code and to respect the code smells, thus indicate the bad design, code that is hard to maintain, read or change, code that is placed in the inappropriate place. The most common code smell is duplicate code, which can really make a mess in our code.  

In the example below the arrayMax method returns the array with the largest sum. Here we can see that the for loops are repeated for both arrays, thus producing a duplicating code. 



This can be eliminated by creating an extract method called calculateArraySum() and simply pass it to each of the arrays. 

Now, both ways are going to be compiled, but is important to not ignore duplicating, as it effects on the quality of the code and makes if lengthy and bulky. You should also consider that producing repetitive code on large projects increases security risks. It leaves holes in the program and opportunities for attackers, therefore making it vulnerable. 

Check tutorials & PRACTICE

Firstly, you should focus on recommended books that are given to you at school (if you are studying programming). You do not want to overload yourself, but neither to stay dependable on only that material. There can be certain things that you may have difficulty, and you can easily find them online by searching your issue correctly. You will progress, and become more vigilant on later challenges you may have. 

You can learn a lot of tactics by following YouTube tutorials; there are a lot of channels that offer solutions to most of the problems that you can search online. Not to forget, you will not be the only one whose life has been saved by an Indian guy on the internet. Be practical and search. Check on methods on how to make your code efficient and more functional. Do not necessary focus on shortening the code, as it is not always the case, expect the situations that were mentioned before. 

Below are some of the books I have used to learn programming; very good books for beginners:

JAVA How to program by Paul Deitel & Harvey Deitel 9th edition 

Internet and WWW How to Program by Deitel P, Deitel H, Deitel A 5th edition 

Visual C# 2012 How to Program by Deitel P., Deitel. H - 5th edition 

Data Structures Problem Solving Using Java by Mark Allen Weiss 4th edition