Recently I’ve made yet another attempt to optimize several quite inefficient report, which had been out there for so long, that nobody remembers, who have written them, and who have speced them out. I did not finish this task, even with the help of my team we just didn’t have enough time to spare on improving something, which “works”. And when I was thinking about it over the weekend, I thought that different people may have different definition of “works”, when it comes to SQL writing.
I always say – it’s easier to write the code correctly on the first place, that to optimize reports which are written inefficiently, but way too often I am getting a response from the stakeholders – we need it now, you can optimize it later. And then later never comes.
This is so obvious, that I would not spend time writing about this yet another 101th time. However this time my thoughts have taken a different path. I thought about why I was unable to finish this optimization, why I didn’t have enough time. The reason was, that something else which I was writing have taken way more time than I originally planned. And the reason why it took so long is that I find myself unable to write, even as a first draft, the code which I know for sure is suboptimal. No matter how many people will tell me that “it does not have to be perfect”. And then – yes, it takes longer.
Now I think that when I teach an optimization class, and when I am showing to my audience some cool technique, my thought process is that everybody should realize how much better this technique is, and than use “that and only that” approach, because how-else-this-is-so-obviously-better. And as for my audience, people think – ok. It’s cool. Good to know. And do not change there code -writing habits…
Once again, I might have been just ignorant, and may be everybody knew it all along, but it was a revelation for me: if I want to teach people good coding habits, if I really want to avoid this situation “first write, then optimize”, not only that I need to show people how to write a coode code. And not only I need to show how not to write. But I also need to teach zero-tolerance to the bad coding. So that people’s minds won’t even wander in this direction:). If it is not written the right way, it is not done.
I am pretty sure nobody would like this idea, but can I at least have a dream :)?