Clean Code, part 2

How do we measure a programmers ability? Can we? I believe evaluating a programmers code to see how 'clean' it is would be a decent benchmark.

To write clean code, you have to do as Robert Martin says and "limit the amount of WTF moments you cause for another programmer looking at or working on your code". For me, this makes sense and seems like a good way of describing why clean code would be important.

When someone is viewing your code they are seeing how you think, how you come to a solution, and whether or not your code would cause more problems than it solves when minor condition changes come into play. In CSS, there are certain standards for how you write CSS code to style HTML. Not including the classes used from libraries, you want to limit the amount of classes and ids, only using them when absolutely necessary. Otherwise, you should be targeting the elements on the page using pseudo code like ':last', ':first', or 'nth:child()'. This allows for greater scalability, when your conditions undoubtedly change. For styles that need to be applied across a range of different elements, that is where adding a class would come in. Here's an example that helped me wrap my head around the power of elegant solutions.

Think about how a train operates, the track allows the train to move quickly and stay balanced. A train is simple, it's elegant, and the solution to mass travel at high speeds has been solved by the train for years.

When a train travels into a city environment, questions like, how does the wheel adjust to a flat surface, arise. However here lies the beauty, it doesn't have too. No adjustment is required, except slowing down of course. Instead it's one wheel, one train, and it can run on an above ground track or a track that resides below the ground.

In software development and as software developers this is what we should strive for. Finding solutions that can withstand the test of time. Obviously, technology is changing at an exponential rate, but that doesn't mean we can't push for a high level of code reusability.

Code reusability, is a corner stone of good software. The more modular the code is and the more able the code is to face varying conditions, is another way to measure a programmers ability to write clean code.

When we think about solving problems in this way it does require extra work, more thought out actions, but it allows more room for future adjustments.

Questions like.. is this the best solution? How does the code I'm implementing affect future actions? What problems does this code cause, when changing it slightly? While learning responsive Web design, these issues have been personified.

Here's an example, I adjust the padding of my image to better fit the flow of my website at 1280px+, all though as it scales down, issues arise. Well you may tell me that media queries will save me, and all though it's true to a degree, you have to hard code each break point.

Now imagine if I was having issues with more than one element. It could be done, and it would serve as a temporary working solution, but only open the door to issues later on.

Moral of the story, take extra time to thoroughly plan out how the program will function from the methods to the flow of your website. Don't be afraid to step outside your comfort zone and stack overflow better solutions, that have longer life spans when new conditions are introduced.

Author: Znergy

I got to school full time for Computer Science, work part time on the weekends, and spend 40/hr M-F at Epicodus (code school). I'm a growing developer and I'm learning new skills everyday.