Is it only looks and personal, or some of it can be considered a bad practice?

We all have different styles and preferences in everything in life, including on how we write code.

Imprinting your personality in the code brings originality and a sense of ownership and responsibility for it. This is important to keep us motivated; it makes us feel good (at least I do).

However, is the coding style always just a harmless style? Or does it impact readability and hence maintenance?

During a code review, for example, I often find myself questioning whether I should bring certain ways of coding to discussion or not — is it readable, is it easy to maintain? Or perhaps I should leave it alone, thinking to myself — Don’t be picky, it’s just how he or she codes, it’s not a matter of right or wrong.

The differences usually lie in the structure, organization, space here, curly braces or lack thereof there, and so on. There are not many variations in how someone might write an if condition, for example, and there are often some rules to follow. But still, if coding standards are not enforced strictly, there will be at least nuances between one programmer or the other. Based on my experience, it becomes more common to notice within a team when, but not limited to, there are members from different eras or coming from other programming languages.

Stretching it a little bit further — we could say a developer has a coding identity, or ‘fingerprint’. Similar to what happens with regular writing. For regular writing, there is often a pattern with which someone writes — the terms, vocabulary, structure — a linguistic expert, for instance, can analyse and identify the author of some anonymous material. It might even tell things such as age and place of birth of the author. This technique is called: Stylometry. It’s commonly used in criminal investigations, for example. Machine learning algorithms are used for Stylometry as well — it can process many texts/books and identify patterns.

We probably can’t tell who committed a crime based on the coding style (or can we? hm., that’s a good novel). But let’s say in a team of ten developers, if there are no strict standards to follow, I believe it’s quite possible to identify who wrote a block of code without looking at the author information.

In this post, I’ll list down different ways of writing code I’ve encountered and remember throughout my career as a Software Engineer. I’ll focus on Java, but some are applicable in general. I’ll also take a stab and give my perspective on whether it is just a coding preference that we shouldn’t care about, or perhaps there is a right (and wrong) way of doing it — IMHO.

I know people (myself included) may have strong opinions about some of it below. I apologise in advance :)

#java #programming #developer

Java Coding Style or Bad Practice
3.10 GEEK