TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

When you write code, which approach do you take?

5 pointsby sneha1995about 2 years ago
When you write code, which approach do you take?<p>Focus on writing clean code, refactoring as you go Focus on writing code quickly, and clean it up afterwards

3 comments

kstenerudabout 2 years ago
It depends on what you&#x27;re building.<p>If you know the domain you&#x27;re writing for and feel confident that you can build at least an 80% accurate model first time, focus on clean code.<p>If you&#x27;re not that confident and expect to make design mistakes that you&#x27;ll correct along the way, focus on making it work first, then clean up the code.<p>It&#x27;s the same for testing: Well known territory and confidence in your model? Write unit tests first. Otherwise write unit tests second.<p>If it&#x27;s completely unknown territory, write a prototype first with no tests, validate your assumptions, then throw out the prototype and write as if you&#x27;re not going to get an 80% accurate model.
eesmithabout 2 years ago
Evolutionary prototyping with a spike and stabilize style.<p>Write a first version&#x2F;prototype, to flesh out the details. See if it&#x27;s even useful. Figure out where the tricky parts are.<p>Perhaps tear it down and write again. More likely do some wholesale reorganization.<p>Let it sit for a while. Use it myself figure out what&#x27;s missing.<p>Go through again (this is now #3) and fix the problems, further organize the code, get friendly users to test it out and report what real users need. (I&#x27;m a sole developer with no QA.)<p>Start writing functional tests. I don&#x27;t like unit tests as I think they are too low-grained and inhibit larger-scale rewrites. This usually resolves the final architectural issues.<p>Then use coverage testing to find out I&#x27;ve only got 80% coverage, so add those. These usually involve error handling, like input files in the wrong format.<p>(I make sure to write that code as part of development, because that&#x27;s when it&#x27;s easiest to think of possible input errors. But I don&#x27;t write tests for them because the parser and even the supported format might easily change over the iterations, making tests a waste of time, when I know even simple line-based coverage testing can identify what needs to be tested.)<p>Then write the end-user documentation, which usually teases out a few more issues.<p>If I can, put it aside and come back to in a few months later. Seeing it later with fresh eyes helps as a code reviewer.<p>I&#x27;ve got 14,000 tests. Takes about 45 seconds to run the main tests. The full tests include some very lengthy tests that I rarely run.
mrv_asuraabout 2 years ago
Well, for me in the beginning getting results matter more than clean code. There are certain things you learn along the way, like what &#x27;not&#x27; to do, which help you in the long run, so you don&#x27;t run into hiccups along the way while doing things quickly. It&#x27;s also important to write simple code because simple code is more scalable and refactor-able in general.