This Is How to Write Great Code as a Developer

June 30, 2016

10:15 am

Writing great code involves more than just having the knowledge and skill to get it done. In fact, good coding involves other skills – problem solving, cognitive understanding, and much more – which all comes together to create code that works well for both the developer and the user.

But even with all of these skills coming together, it can be tricky to understand how to properly apply them to write good, responsive code. Developers have taken to Hacker News to share some of their best advice on what it takes to write good code. Here are some of the best responses to use on your next coding endeavor:

Be Meticulous

“Think really hard about the problem you are solving.

First question to ask is always: Do I need to write some code or I can solve this problem using tools already here?

If you decide to write code, then start to think really hard.

What interface should I provide? The smallest the interface the better; and be aware that any kind of configuration your interface use increase exponentially the size of the interface itself.

Now you should experiment, take your time and be sure that the interface you are providing is the smallest possible, try to see the problem from another point of view, don’t be afraid to throw away code (don’t write test yet if not for experimental purpose, you don’t even have the interface to test) and try to keep everything stateless and pure.

During this process is important to gather feedback from your peers, they may see problem that you don’t.

Once you have decided what you are going to code, write it down.

Try to keep everything so simple that test will seems pointless, write those anyway.
Be slow, take your time for thinking, don’t be afraid to throw code away.”

Work Smarter, Not Harder

“When ‘better’ means ‘fewest bugs’:

1. Use the best language you can get away with. This means using a language that eliminates entire classes of run-time errors via some or all of: a) strong typing; b) static typing; c) managed memory; and d) immutable data.

2. Assume that your code will be maintained by somebody who doesn’t know your programming language as well as you do.

3.Use static and dynamic assertions liberally.

4. Ease debugging. Have great formatted dumps of your internal data structures, great internal consistency checking, and great logging. Automate problem isolation, too: for example, in an optimizing compiler, at each point where a discretionary change is about to be made, call a function that logs the change, increments a counter, and returns false if the counter is past a limit that you can set in the environment; this allows an automated bisection analysis to immediately find the change that broke a test program.

5. Regression tests. Once you fix a bug, make sure that your test suite will notice recrudescence.

Always Write Code for Someone Else

“Always write code for someone else. And you don’t know who it is. Write tests not only to prove correctness, but also to test whether code as an interface makes sense. Be defensive as much as possible. Each additional check / assertion helps to avoid accidental bugs or can help to find them early. Speak about code as much as possible. If you can explain code in your own words and discuss it with someone else, code gets raised on a philosophical level and may end up to be elegant and logical for others. RTFM & RTFS(pecs)!”

Read, Test, and Try Again

“Read lots of code. The more of other people’s code that you read the faster you’ll learn good practices.

Work with other people that are better/more experienced than you.

Code reviews are your friend. When I was at Google, the best way to learn and teach good coding practices and libraries were through the code reviews that we had. Get in the practice of reviewing other people’s code and having others review your code.
Test, test, test! It may sound counter intuitive, but if you want to increase coding velocity, write tests. Tests upfront will save so much time in debugging later on.”

The 4-Word Tip to Coding Success

“Think more, type less”


Did you like this article?

Get more delivered to your inbox just like it!

Sorry about that. Try these articles instead!

Cameron is a tech and culture journalist, comic book enthusiast, and lives near New York City. A graduate of Stockton University, she's using her words to shift the world of online journalism, one byline at a time. When she's not writing, she can be found reading sci-fi novels, collecting succulents, and planning her next obnoxious hair color. Cameron is an editorial fellow at Tech.Co. Send your tips to or tweet @BlkGirlManifest.

  • Shares

Leave a Reply

  • (will not be published)