Code stabbing - happy accidents and headaches.

If you’re a fan of FreeCodeCamp, CodeWars or other code training websites you will no doubt be familiar with completing challenges, bonfires or kata. The idea behind them is that you usually get a short scenario and then have to solve a problem with a small bit of code. I find them a good way to put into practice some things which otherwise might be a bit abstract. For example, understanding how to chop up strings might be a trivial concept but when the purpose of doing it is to check for palindromes well, it has a whole new meaning.

Because the scenarios and hence the ideal solutions are usually quite short I personally never spend a lot of time planning how to solve them. If it was a more complex task I would probably break it down in to areas and work on them individually. However I tend to go code stabbing and just wander around aimlessly in the dark, firing off bits of Javascript and seeing if I hit anything. Sometimes I find this to be a good approach and the odd happy accident means I discover something new. I remember a FreeCodeCamp challenge where the idea was to filter false-type values and I was about to write a complex if statement to do this. By accident I discovered that if you just return the value in question, it will give a true / false result. Excellent! The point being is that if I had planned out the complex if statement and other parts of the challenge I would probably have not discovered that shortcut which has proved helpful in so many other areas of my coding.

It’s not all good news though. Whilst on my code stabbing evenings I have had successes I have also been met with numerous dead-ends, problems and headaches which even the recommended dose of paracetamol could not resolve. This does mean it can take longer to solve what would perhaps be a simple problem and does have the side benefit of spending hours on the Mozilla Developer site trying to comprehend how call, bind and apply are different.

The end result I feel is that a little bit of code stabbing now and then is not a bad thing. It pays to tinker. It can be beneficial to experiment. It can be quite fun. I guess that we just need to be conscious not to let what could be a bad habit, creep in to professional work.

Do you think stabbing around for solutions to code can be useful?