Category: Clean Code

Posts about clean code in the sense of readability, robustness, maintenance and scale

Masks VS. Bitfields

Achieving Clean Code can get harder when you go down to the nuts and bolts. Bit-manipulating code is very common when you go “low level” with your coding, usually with C. It may be needed when you manipulate HW registers with a certain bit structure, when you want to compress data elements to occupy bits […]

The Dreadful ‘Goto’

The ‘goto’ operation has a very bad reputation when it comes to high-level programming languages. I have heard many times the sentence “never ever use goto”. I think that the fear of ‘goto’ is generally justified since it can lead to horrible spaghetti code. If really abused, it can completely corrupt the structure of a […]

C Polymorphism – Part 2

In the first part of this post, a “classic” example of Polymorphism-like code in C was discussed. Let’s look at some production code I had a chance to refactor. After the refctoring, the code looks like another step forward towards the Polymorphic behavior of real OOP languages. For obvious reasons, I have modified the example […]

C Polymorphism – Part 1

Polymorphism is something usually associated with Object Oriented Programming, not with classic C. However, the notion of Polymorphic behavior definitely exists in C in a “lighter” form. You will not automatically get all the back-stage mechanisms OOP languages give you, but there are still time in which you can get a lot of code cleanness […]