5 points · by hoodoof · 10y ago · 11 comments
I have to write so much complex code to make whatever I am building work, then I have to go through a challenging phase of simplifying it down to the minimum working code.
When I look at the minimum working code that is the result of this process I think "why the heck couldn't I have written that simple code in the first place - it would have taken me 25 minutes instead of 8 hours".
Blah. I'm sure some genius programmers out there only ever write the minimum code in the first place.
Once you have the correct code, you'll also have a more complete understanding of the problem and it's parts.
At this point you can start simplifying, optimizing and so on.
Also, having a correct code makes that job easier, since now you can have both a proven set of tests and a reference - errors are trivial to catch.
> I think "why the heck couldn't I have written that simple code in the first place - it would have taken me 25 minutes instead of 8 hours"
You didn't know it back then, now you do. The path from there to here resulted in that understanding, and the hindsight through the understanding makes the past looks absurd.
I find getting the data and data structures correct leads to the simplest implementation -- and chipping away at the code as you go along trying to make it simpler and faster is usually how a solution evolves.
I don't know if anyone writes the perfect implementation of anything complex the first time -- you have to work at it.
Eventually I get the code to behave in a predictable manner and get my functionality implemented then I start removing all the dead ends and mistakes and misunderstandings.
Rinse and repeat several times until the code is as simple as I want it to be.
It might be hard to learn to drive an 18 wheeler but better than building it yourself.
Speed and/or size improvement in next iteration is much better than completely reworking because of: missed or bad requirements understanding, compatibility issues etc.
As was already mentioned, you have to have something working. Only this can be improved. Without working code any speed or size optimization is useless.
Remember 90% of code is crappy. Your job is to make something work, and then you can go back and make it work better.
With coding, it can take a while of working with rough code to identify the abstractions that simplify problem.
This design could then be reviewed by your colleagues.
This is the same mental process but may save a lot of tedious typing and then undoing again when you consider a better design