HACKER Q&A
📣 batt4good

I struggle to write code from scratch


Generally most of my learning has come from my CS degree and reading other people's code. Yet, when I have to start something completely from scratch I still feel like I make beginner mistakes or write sloppy code.

This hasn't really been an issue at my work, however I'm still at a loss as to how I should learn to start from scratch and "architect" code in a way that makes sense and is complex. By this, I mean sometimes I'll look at a repo that's just a complex rest API and I'll be thinking "there's no way I'd be able to come up with this elegant structure or nested code in one sitting".

Is this a sign I just learn slowly or should I just resign myself to doing product management and non-coding stuff?


  👤 davismwfl Accepted Answer ✓
You shouldn't expect to graduate with a CS degree and immediately architect complex systems in the first few years. Experience is what makes people proficient, and mistakes help make you better. Every time you code something up and have to redo it cause you messed up or didn't understand the problem well enough, you learn more and get better.

I also agree with db48x, the complex elegant solution you saw wasn't designed and done in one sitting. It was likely done over time and with a few prototypes and concepts that then got refined into a more elegant solution. Once you get enough experience, you will go through fewer iterations because you'll recognize patterns and when to apply them. Even then though you might prototype a couple of different ideas to test some theory.

Now if you say you've been coding professionally for 5-7 years and you are struggling still with basic architectures, then maybe there is something else going on.


👤 jbn
I think this happens to everyone. No one instinctively knows how to do this. In addition, you learn by seeing existing designs and critiquing them (positively or negatively... knowing what to avoid is almost more important IMHO).

I would even say that most people working in software can only fill in the blanks, they absolutely cannot start from scratch (which is in truth very hard).


👤 db48x
It's just a skill; practice it. The author of that complex API probably didn't write it all in one sitting, or even come up with the skeleton all at once. Likely they cribbed from some other project they worked on, perhaps making improvements or mistakes.