HACKER Q&A
📣 actbsh

How to write production-grade code?


Hello HN,

I have been writing python code (for Deep Learning/ Computer Vision) for almost 4 years professionally. However, I haven't worked close to a production system so far but would need to in my new position. I want to understand what it means to write production-grade code?

So far, my understanding tells me of

- Language specific or even general code style guidelines - check

- Logging and exception handling - check

- Tests - check but not always and could be more comprehensive

Still, I feel like I don't craft quality code. I have ofcourse received feedback from team members over the time and have incorporated those into my work so that I don't get those review comments anymore. However, the feeling that my code is just simple and dumb doesn't go away. Some say it's a good thing but most code I come across, say libraries I use, are just different in terms of abstractions, language features they use and whatnot while mine looks like something written by a highschooler (imo)

So, if the more experienced among you could suggest some resources / practices / exercises / whatever, that would really be helpful. Thanks in advance.


  👤 Shinmon Accepted Answer ✓
This is experience and learning from each other.

Sure, there are general guidelines that can be applied in many cases (testing, keep it simple, ...). However, many things depend on the company and the team you are working in.

A lot about production grade code is also to make sure it's easy to read and understand (thus maintainable).

A good question to ask is also "What happens when X goes wrong?". What happens to the system in general, how critical is it, and how can you understand what happened. This is about logging and moire general observability.

In the AI/ML field production grade code doesn't necessarily mean that you need to have super abstract things. A lot of this is actually the MLOps part: getting the data to your model, saving the model in some artifactory, running inference, ... . To make this easier it's most important that your code is somewhat modular and not just a plain script that you run when you need it.

Also, don't be to hard on yourself. Your last two lines sound a lot like imposter syndrome. Look back at your code from 4 years ago and see how it has changed and how much you have learned.


👤 rudasn
If you want to write you first need to read.

You can go through the django source code, documentation, pull requests, mailing lists, tickets, and find all you need to produce serious software.

WireGuard too, but that's in C and in Go. It's a lot of fun seeing how the guys from tailscale submit patches to the wireguard-go library, and how brutal (in the best possible way) Jason's comments are.


👤 hayertjez
If you have found a good resource about Logging and Exception handling let me know.