Posts

Showing posts with the label code quality

Reflecting on reflection in Scala and Java

Reflection has always been a bit of a trickery, and while there may be some true to it, it does not mean one cannot master mind some cool stuff using it, and by cool I mean useful,  re-usable, elegant and the likes. In this post we put on the wizard hat and pull out some rabbits. Problem Statement In this post we'll discuss 3 use-cases in which we want to retrieve runtime information for some generic parameters. In all three of the following use-cases, our goal is to retrieve the runtime information for the generic type parameter T. The first use case is when you have a class deriving from a generic class, without having generic parameters of its own: class GenericInt extends Generic<T> {} // one wants to know the type of T of its parent new GenericInt () The second use case is when you create a new instance of a generic class by providing a generic parameter: // one wants to know the type of T inside the class new GenericClass<Integer> () The third...

Keeping it together in face of a terrible codebase

Image
This is, as a matter of fact, an industry proven method.

Dependency Injection - The good, the bad and the ugly

Image
The Good Dependency injection (DI, a.k.a IoC - inversion of control) is a well known technique to increase software modularity by reducing coupling between modules. To provide the benefits of DI , numerous DI frameworks have arisen ( Spring , Guice , Castle Windsor , etc.) all of which essentially give you "DI capabilities" right out of the box (these frameworks tend to provide a whole lot more than just "DI capabilities", but that's not really relevant to the point I'm about to make). Now, to remove the quotes around "DI capabilities", let's define it as a DI container - a sack of objects you can manipulate using a provided API in order to wire these objects together into an object graph that makes up your application. I've worked on quite a few projects employing Spring, so it will be my framework of reference throughout the rest of the post, but the principles and morals apply just the same. 

Continuous Deployment - Not Without Modularity

When asked about what's a module, no two people give the same answer. The interesting thing is, it doesn't keep modularity from being one of most pronounced words when it comes to the desirable set of attributes a software system should ideally have. It's somewhere just next to scalable and robust, in no particular order.

Feature flags revisited

Feature flags have always made me feel ambivalent. On one hand, I can relate to the need for having a mechanism to easily enable or disable particular features, while on the other hand, being a software engineer I pretty much loathe this concept, since feature flags make your code ugly more often than not. Especially if such a flag is left in place even after its corresponding feature has become fully operational, eliminating any practical need to be turned off on demand. Cliché ahead in 3,2,1: not everything in life is black and white, and sometimes, even in the face of feature flags, we can still, well, save face.

4 excuses to write poor quality code

Image
1. This module can't be unit tested, it's too [ insert-adjective-here ]. If it's too [ insert-adjective-here ], how do you even know it's working in the first place? And what about after we extend it with a new feature? 2. Breaking logic into methods incurs a performance hit. So does inheritance, and separation into classes. Does this mean your design should consist of a single class with a single method where all business logic is placed? 3. Commenting code is time consuming and hinders development. Same goes for going to the bathroom, but you don't see people skip that, do you? 4. Coding conventions are too rigid, I'll call my fields whatever I want. Now that's just an excuse to write ugly code.

Enhancing code readability

I'm a big fan of easily readable code, in fact, my appreciation for code that reads almost English has only grown over the years. Extension methods in C# allow for some nice tricks to take place in this regard.

They let anyone commit to production these days

Today, more than ever so it seems, people outside the software engineering field partake in writing code that eventually makes it to production environments. An increasingly great number of companies have data analysts or researcher personnel write code as part of their job. I find this phenomenon rather interesting as I do not believe this was the case as far as only a decade ago. Back in the day, doctors practiced medicine, chefs practiced cooking and researchers practiced, well, research. It was the software engineers who were concerned with how to get computers do what was needed to be done using code. Today on the other hand, while it’s still quite difficult to find a brain surgeon who writes code, it is quite easy to find a computer vision researcher coding for a software company, or a statistician slamming hadoop jobs (the reason for this shift is interesting in its own right, but as design documents often state – this is out of scope).