Christian Beck
Architecture for Raccoons

Architecture for Raccoons

Are we training to write complicated code?

Christian Beck's photo
Christian Beck
·Dec 22, 2021·

4 min read

It is again this time of the year where i find some rest to code just for fun. The last few days i was doing some Codewars katas. When i solve a kata it is not just for the nice feeling of solving a tricky puzzle. It is also a training. So in the beginning i decide for a set of rules that guide me towards my training goal - almost always strict TDD (in several flavors) and currently mostly stick to IOSP and CQS. And as far as i known many developers do it that way and it is the way that it is meant to be done - a kata is so simple, that you do not have to think about the actual solution, but can focus on the execution of this solution.

Now solving a kata just to have some fun and learn something is time well spent, but from time to time i also read solutions from other people as well to see another angle to those katas i solved. And what struck me is that most high rated solutions in code wars are shorter than mine. They are semantically equivalent, but shorter. The reason is clear: They lack the overhead of additional training constraints. They come with less variables and methods and shorter names. And frankly those solutions aren't bad. I still like my solution, but short is beautiful and in most cases there isn't too much logic to understand - the code is still very understandable. When the whole thing could easily be written with less code around and does not suffer in clearness to read, does this mean the additional code of my solution is noise? Probably yes! And it is not a bad thing, because the code of my solution is meant for training purpose and i throw it away afterwards - so no harm done.

But i was wondering, what if our methods of training encourage us to write code in a certain sophisticated way, regardless if the logic we want to express does require that level of sophistication or not. Or in short: Do we train to write sophisticated (or complex) code and forget how to write simple code? Well then we might have a problem - namely overly complex code. And thinking back to some code bases i know (and i have actively worked with), where the developers take pride in there very good coding skills and high level abstractions, i got the feeling that this might actually be a thing.

When one learns the high praised patterns and practices of our trade one does apply them. And this is what we want. But i fear as a unwanted side effect we diminish the lesser praised patterns of our trade, even though at some point these patterns are also valid, because sometimes they are just what is needed. Maybe you do not always need a big dependency inversion container and hundreds of factories and strategies and adapters and mappers ... - e.g. for a simple command line tool that prints some system information. Sometimes code can be as expressive and well maintainable without these advanced techniques.

A new training approach?

So i was thinking is there a way to train for simple solutions occasionally. The usual way of training is good and i love it, but should we at some point just try to code without high level constraints?

What if you have to code the same kata once with constraints and once without them and then compare the solutions - or maybe in two different teams with different level of sophistication constraints. Or use different katas to reduce practice spilling from one kata execution to the other. Something like: team one codes a simple kata with high sophistication and hard kata with low sophistication and team two does it the other way around and at the end all solutions are reviewed by all participants.

I am still pondering about the right method on how to do this (and i love further input on this topic) but i am most likely going to experiment on this one in the next year. So looking forward to stunning new experiences.

 
Share this