Ask HN: How do you write production level code? - hackmyfaceoff
======
smt88
Work on an open-source project or at a company with someone who knows the
answer to this question and has been doing it for many years.

A frustrating fact about coding is that you don't know what you don't know.
You feel like an expert, and then someone else shoots you down by introducing
you to a new security risk you've never heard of or a technique that's better
than the one you've been using.

This risk is a lot lower when you have an experienced team around you.
Whatever you _might_ be missing, someone else has a chance of catching it.

It's also much easier to write production-level code when you use a language
with robust typing and mature, widely-used, well-tested libraries.

------
davismwfl
Write the smallest usable chunks of code and turn them into functions/methods.
Add input parameter testing, exception handling and have outputs clearly
defined. Write tests for each of these small chunk of code. Group these small
chunks into groups and build up modules. At each module level write test code
that executes all the integrated paths and keep working your way up.

Of course what I wrote is a bit of an oversimplification but overall it is how
I write real production code that must be reliable.

In general I usually wind up with far more test code then executing production
code if I do this all. But like everyone I will get lazy on some of it, which
is usually where I find some error later.

Also, this basic design lends itself to either a functional or OO style of
coding. Modules need not be classes but classes can certainly help you build
modules.

Find people that will give you feedback, even if they aren't in you immediate
network or peer group. It is amazing how helpful people can and will be if you
just ask, respect their time and be honest about your level of experience and
understanding.

------
nareshv
When you cannot work with other experience people or participate in open-
source projects. Try these things.

1\. Take a task and implement it in the most laziest way (like implementing
everything in a single code file)

2\. Try to make the implementation "look beautiful" (with proper indentation,
etc)

3\. Try to make the instructions in your code analyze the return codes, check
the input parameters to functions, catch exceptions, split them into various
files, functions, classes etc by adding more code.

Third step is where you will try to learn more from the programming language
that you have chosen. See
[https://gist.github.com/nareshv/50fa0884d09622792e34](https://gist.github.com/nareshv/50fa0884d09622792e34)
for example

Once you master the step-3, you will always do begin with these things when
you start implementing your project.

Source: Personal experience.

------
cdnsteve
Work in a team with other experienced people. Trying to figure this out on
your own is something that is tough to learn.

------
thorin
If you have to ask this question maybe you haven't seen much "production"
code. It's pretty variable. Open source projects can be a great help to see
what's possible. If it's easy to understand and well used it might be pretty
good.

