Skip to main content

Random Thoughts ...on... Pre-mature Optimization

OK, not really random thoughts as I've been thinking about this for quite some time.  Sometimes it take a lot of reflection to understand what reality is (at least as I've perceived it).

There are a number of sayings that are too simplistic on review.  Hey, there are a lot of sayings that sound good in the moment but other than a quick emotional appeal, do not help with the needs at hand.  They are the quick 2 min fix that does not fix anything and still leave you as directionless as before.

So there is my software saying : "Don't pre-optimize your code".

At first glance this sounds correct and certainly applies for architectural issues and design, that may change to reflect implementation issues.

But at a personal level, does this really apply?

I mostly view the world through my own eyes and from my perspective, my toolkit, knowledge and experience is rather deep so that any code that I write is already efficient to a large extent.  So much so that I rarely need to go back and re-write my code for optimization.  For any given feature, I've already analyzed the implementation options in my mind and already pruned out the inefficient paths and settles on a clean design and patterns well before I start coding.

Looking back in time, I remember when junior coders have tried and failed to implement efficient implements that required re-work and sometimes a complete re-implementation.  It's not that their code did not work, it did, but there where bugs that could not be rectified with the current implementation.  Digging deeper I wanted to understand why this was the case.

Most features and coding is rather simplistic (web pages and forms come to mind) so that almost anybody that has a good understanding of the language (aka, JavaScript), will result in an acceptable implementation.  The problem arise when the solution set lays outside of the coders experience set.

In these cases the coder should not pre-optimize because they don't have that knowledge yet.  Veteran coders will write optimized code as they code, but the more junior coder will not know how for a more complex solution.

A solution set that represent this are "state" systems and "mutli-threading" (aka, WebSockets for web pages), where there are added dimensions to account for.   Coders that have NOT been exposed to the designs and patterns for handling these cases will try to overcome them by adding flags, extra timeouts and other simple tricks to get the operational behavior that is required.  All the while they are just hiding the issues without ever solving it.  The resulting implementation could be so flawed that a re-write is required.

At this point, the coder would need to take a large leap on the learning curve to reach this higher level of knowledge.  The real issue is they may not know this unless someone is around to guild them through this and there maybe additional pressure from management to "get it working".

There is kind of an unwritten myth that one you learn how to code, you can code anything.   It's true if you know where your knowledge ends and when you need to stop and gain deeper understanding.

This is the opposite of the Imposter Syndrome where you feel not up to a task.  This problem is where you are too optimistic about your skills and end up digging a deep hole that you can't escape from.

This leads in the Full-Stack vs Specialist programmer issue.  But this is for a later article.  For now just keep learning.

Comments

Popular posts from this blog

My Current Desktop and Happy Vining.

It's been a big switch when I quit my old procession (Software Engineer) and ventured into the unknown.  So this is my current desktop.   First it's a REAL desktop and not a computer screen. Second, I've had to learn a whole new set of tools.  You would think a pencil is just a pencil and a paint brush is just a paint brush, but noooooo, they are tools into you mind and that's what needs re-tooling. The tactual nature of these tools and operation as much more rewarding (and frustrating too) than typing code in an IDE.   That had it's incentive but that well went dry and life changes,  so I changed. The pleasure of creating colors (no RGB involved) ad hoc wise is interesting.  Getting the technique to merge them on paper is very tough.  You do not know what you're going to get, so you just have to go with it. I'm glad that I can do a lot of other things instead of Software, but I hope that others in my past procession work on other pa...

3rd Try is a Charm

I've been trying to draw / paint these barns for a couple of years but never felt or got them right.  This time I think they turned out right. So What went wrong before and what's right now with this drawing?  This time, the light was right.  It's coming from the upper right and the shadows just looked right.  The other thing is the corn field on the left had to "be in season", otherwise it's just a plowed field.  I had taken other photos from different angles but they never felt right.  This angle has the road, power lines, corn field, etc. all leading to the right.  The shadows on the lower right helps fill in that corner (don't forget about the corners!).  The last part is trying to draw (ink paint maybe) the trees in the background.  Not so easy when they are kind of a blob is green shades. So yeah, it's composition that is king.  Many times I just don't see it until the drawing / painting is finished and when it's right it feels goo...

Thought Patterns

I know how I work.  How a think about, visualize a problem and go about mentally design a solution and implement it in code.  My thought pattern works pretty well for me on most occasions, but not always. There are times when I have a force myself to change my thought pattern because of the problem I'm solving requires a different mindset.  Anyway, this posting is about how I work most of the time.  Here is goes. I quickly break down a feature into operations that are required to exists and tackle that code first.  My thinking is that, if I can solve the primary issues first, then secondary features will fall into "known knowns" and I can address those at anytime (and sometimes at my leisure) and this allows me to meet my internal timeline. If I addressed features and operations that are not primary first, then I feel I risk my (and the projects) timeline without addressing issues that allow the feature to operate.  You may have seen this occur where...