Skip to main content

5 Principles of Programming that Every Coder Must Know

Thanks to a proliferation of free online tutorials, virtually anyone can learn how to code. Once you’ve been a developer for a while though, you quickly start to realize that all code is not created equal. Programming forums are awash with horror stories detailing ginormous if-else blocks, massive spaghetti-like algorithms and redundant code that serve no purpose.

While these may seem like rookie errors that only bedevil persons just starting out, many programmers carry on these bad habits well into their career with disastrous results.

5 Principles of Programming that Every Coder Must Know

Image Source

Below are some of the useful principles of programming that you must keep in mind while writing code.

1. Simplicity

Simplicity is the ultimate sophistication and perhaps nowhere more than in programming. It all begins with how you document and dissect program requirements. Each requirement should be well articulated to the extent that once you start to code, you can satisfy these requirements using the simplest of techniques.

Complex code not only takes more time to design and write but is also more vulnerable to errors and bugs. A labyrinth of code can make web app monitoring tedious. Beware of feature creep where you start to add new features to the program that the customer didn’t ask for as this only needlessly entangles the software.

2. Do Not Repeat Yourself

Minimal repetition is a sign of quality code. Avoid duplicating logic and data. To know whether your program has excessive repetition, think about how much code you’d need to modify if you wanted to alter one aspect of the application’s behavior.

To minimize duplication, identify all sections of code that do the same thing. Abstract this common blocks of code into a single function that you call whenever you need to perform the said task. That way, if you ever need to change how the task is performed, you’ll need only modify the one function as opposed to amending multiple lines of code throughout program.

3. Code for the Now not the Future

One of the smart principles of programming is to make provisions for future changes in the code. It should be easy for a third party who was not involved in the project, to follow the logic and add or remove functionality as needed.

Nevertheless, making provisions for future maintenance isn’t the same as coding in functionality that you might need in future. The latter only increases the volume of code while creating a new avenue for bugs. In any case, such functionality is often not needed at all in future.

Coding for the now prevents scope creep. Unless the end user specifically requests for this functionality to be included from the onset, stay away from it.

4. Don’t Optimize Prematurely

When you enroll for a basic programming course, one of the areas of emphasis is the need to create fast efficient algorithms. The mistake some coders make is to run with this one lesson. They get immersed in trying to speed up and optimize the code from the start while losing sight of the primary objective which is a creating a functioning program.

Work on meeting the system requirements first then move on to optimize the code. Optimizing too early is akin to groping in the dark. Before the program is up and running, you cannot really be certain where the bottlenecks will be. You could waste precious time optimizing a function whose speed doesn’t contribute much to overall program performance.

Ergo, first satisfy the program requirements then work on resolving the bottlenecks.

5. Readable Code Over Clever Code

Clever code is programming that is less about creating easily understandable code and more about showing everyone how smart you are. A typical example of clever code is packing an excessive amount of program logic into a single line of code.

Minimal code was at one time heralded as a sign of good programming but over time, the industry has recognized that brief code is meaningless if it’s hard for someone else to follow the logic. Any line of code that would take another programmer dozens of minutes to understand should probably be done away with.

Good programming is not only about building applications that meet the end user’s expectation but also creating code that is easy to understand. Following these programming principles will ensure you achieve both.

The post 5 Principles of Programming that Every Coder Must Know appeared first on The Crazy Programmer.



from The Crazy Programmer https://www.thecrazyprogrammer.com/2018/07/principles-of-programming.html

Comments

Popular posts from this blog

dotnet sdk list and dotnet sdk latest

Can someone make .NET Core better with a simple global command? Fanie Reynders did and he did it in a simple and elegant way. I'm envious, in fact, because I spec'ed this exact thing out in a meeting a few months ago but I could have just done it like he did and I would have used fewer keystrokes! Last year when .NET Core was just getting started, there was a "DNVM" helper command that you could use to simplify dealing with multiple versions of the .NET SDK on one machine. Later, rather than 'switching global SDK versions,' switching was simplified to be handled on a folder by folder basis. That meant that if you had a project in a folder with no global.json that pinned the SDK version, your project would use the latest installed version. If you liked, you could create a global.json file and pin your project's folder to a specific version. Great, but I would constantly have to google to remember the format for the global.json file, and I'd constan...

15 Web Design Trends to Watch in 2018

The modern world is full of extraordinary things that influence our imagination and mood. Our soul needs a perfect atmosphere and impressive spots. To apply such things in practice, we have submitted the list of the web trends that deserve your attention. Robert frost design analysis will meet all your wishes and expectations. Image Source Web Design Trends to Watch in 2018 1. More Organic Shapes Until this year, web design, as well as mobile design, were based on the right-angled and sharp-edged shapes. However, it seems that this year will bring some significant changes in the field of web design. The recent trends will offer the absolute rounded corners. In addition, the web design of 2018 will make the real things look like the cartoonish ones. 2.   Bold Minimalism Although some of you may think that this web design trend will not attract the Internet users. Indeed, the notion of minimalism is often associated with boredom and dullness. However, in this case, bold ...

Data Encryption Standard (DES) Algorithm

Data Encryption Standard is a symmetric-key algorithm for the encrypting the data. It comes under block cipher algorithm which follows Feistel structure. Here is the block diagram of Data Encryption Standard. Fig1: DES Algorithm Block Diagram [Image Source: Cryptography and Network Security Principles and Practices 4 th Ed by William Stallings] Explanation for above diagram: Each character of plain text converted into binary format. Every time we take 64 bits from that and give as input to DES algorithm, then it processed through 16 rounds and then converted to cipher text. Initial Permutation: 64 bit plain text goes under initial permutation and then given to round 1. Since initial permutation step receiving 64 bits, it contains an 1×64 matrix which contains numbers from 1 to 64 but in shuffled order. After that, we arrange our original 64 bit text in the order mentioned in that matrix. [You can see the matrix in below code] After initial permutation, 64 bit text passed throug...