Have you ever baked cookies and wondered why the recipe is exactly that way and no other?

If you changed this ingredient up or that temperature, would it make the cookies even better?

I certainly have had these thoughts.

Oi, developers! ‘Best practices’ can turn you into complacent a-holes

Its the reason why most of the things I bake arent very edible…

When it comes toprogramming, these thoughts arise too.

What if I wrote this part as a separate function?

Article image

If I hard-coded this bit over there, would it make the code easier?

Can I rewrite those ten ugly lines into two elegant ones?

There are no recipes in programming, but there are best practices.

Theyre not precise like a recipe, but clear enough that its evident if you havent implemented them.

Like with recipes, some best practices get repeated over generations of programmers.

It’s free, every week, in your inbox.

But eventually, even the coolest tradition dies out or evolves into something more useful.

The same will happen with some, but not all, best practices in programming.

Dont Repeat Yourself has become a mantra of sorts.

Im not a computer science major, but I do read a bit, and Id internalized that mantra.

So I took those four lines and put them in a function.

Then I noticed that I couldnt do that so easily because those four lines werent completely identical.

Id also need an if-clause and perhaps a new boolean parameter to invoke that option.

That wouldve made the code as complicated as it was before.

This did simplify my code slightly.

I did end up repeating myself, but only twice instead of three times.

And I violated theSingle Responsibility Principlebecause my two functions were doing more than they were advertised for.

And these workarounds might have even satisfied both principles.

Its hard to disprove a claim like that.

But programmers arent paid to write the most elegant and beautiful code of the decade.

Theyre paid to make something work.

And more code-cosmetics would cost me valuable time that Id rather spend on other projects that arent working yet.

Maybe Im just so dumb I cant even get two programming principles two work.

But I guarantee you that there are whole swathes of programmers that are on a similar level as me.

Swathes of people who cant get DRY and SRP to work together either.

Its unlikely that this would cause DRY to dry out (sorry, the pun had to be).

Its an extremely useful principle for example in functional programming,which is taking up steam these days.

The Single Responsibility Principle, on the other hand, might become rarer.

Think about neural networks, for example.

They dont figure out one single thing.

Thats the opposite of SRP.

In other words… SRP is DRYing out.

But that doesnt change the fact that it isnt always sensible to implement.

The idea is that if a solution to your problem already exists, you should use it.

Its probably less buggy and more efficient than your home-cooked solution.

There are a few problems with this thought.

First of all, existing solutions rarely match your specific problem 100 percent.

Second, existing solutions often have more than one feature.

And youll probably not use all the features.

You could have avoided that by custom-building your own.

Third, beware ofincorporating open-source solutionsin proprietary projects.

This is a violation of copyright and can, in the worst case, get you into legal trouble.

If you use open-source code in your project, your project should be open-source too.

Finally, reinventing the wheel wont guarantee freedom of bugs anyway.

Not great, because you havent used your writing muscles very much with only one article.

But not bad-bad because youve polished it up quite a bit.

Some of them will be great, and one or two of them might even be excellent.

Now, you might object that programming is rather different to free writing.

But programming is, in its essence, quite a creative discipline.

Programming is basically about finding interesting, elegant, and efficient ways to solve problems with a computer.

But seriously, if you have 100 shots surely youll shoot one in the right direction!

So code more, make more mistakes, and learn more.

But they might limit your thinking and blind you to more innovative solutions.

If you really want to stand out in a positive way, use best practices as guidelines.

Break those guidelines when that seems appropriate to you.

People who always follow the rules become complacent.

And complacency, over time, kills success.

Start breaking the rules and you have a shot at joining the great heads.

Repeat yourself if thats better for you.

Leave your responsibilities tangled if thats easier to maintain.

Code your own solutions instead of importing existing ones that dont fit perfectly.

Even if its bad or buggy.

Therell be a few gemstones in the mess you create.

This article was originally published on Medium.

you might read ithere.

Also tagged with