
Ask HN: I struggle to write code from scratch - batt4good
Generally most of my learning has come from my CS degree and reading other people&#x27;s code.  Yet, when I have to start something completely from scratch I still feel like I make beginner mistakes or write sloppy code.<p>This hasn&#x27;t really been an issue at my work, however I&#x27;m still at a loss as to how I should learn to start from scratch and &quot;architect&quot; code in a way that makes sense and is complex.  By this, I mean sometimes I&#x27;ll look at a repo that&#x27;s just a complex rest API and I&#x27;ll be thinking &quot;there&#x27;s no way I&#x27;d be able to come up with this elegant structure or nested code in one sitting&quot;.<p>Is this a sign I just learn slowly or should I just resign myself to doing product management and non-coding stuff?
======
davismwfl
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.

~~~
greenyoda
Also, the author could have gotten feedback from other people (users of the
API or other developers) on earlier versions of the API that improved the
current version. Being able to write complex code is a useful skill, but so is
the ability to collaborate with others on larger projects.

~~~
batt4good
It's mostly been awkward at work when co-workers or my manager make comments
like "you've shipped code like this before" that's followed with negative
feedback and a implication that I should've "known that wasn't good enough" or
"wasted the time of a reviewer" even though the code seemed simple enough for
me and passed tests.

I really can't tell if I suck or just work in an incredibly toxic workplace?

