News for hackers. Stuff that matters.
Re:Ask HN: Where do I find good code to read? by gwbas1c on Thursday August 24, 2023 @09:20AM (#37248421)
I disagree.

The problem with believing that "good code" is good enough to deliver business value is short-sighted.

Good code is highly maintainable so that you can continue to meet business objectives in a timely manner without regressions. Often this means (ironically) taking a little bit of extra time early on to think about how to make your code readable and "simple enough" for someone else to be able to jump in and maintain it.

Re:Ask HN: Where do I find good code to read? by Zetice on Thursday August 24, 2023 @09:26AM (#37248483)
The problem with this “maintainability” argument is the presumption a) that it will be maintained (note I recommended rewriting frequently) or that b) it’s in conflict with meeting business objectives.
Re:Ask HN: Where do I find good code to read? by alpha_squared on Thursday August 24, 2023 @01:18PM (#37251729)
Rewriting frequently (reference a) is often out of the hands of the developer because of (reference b) business objectives. Writing code is entirely in the hands of the developer only at the time of writing, not a "henceforth and forever" sort of situation.
Re:Ask HN: Where do I find good code to read? by johnnyanmac on Friday August 25, 2023 @12:52AM (#37258221)
And I suppose a dev who only cares about paying the bills would still resonate with this advice. It's not their problem once the suits take charge of the product and give a thumbs up. Why bother with future dev maintenance? the suits will pay for that bride when it burns down, and having that happen is 100x more easy than trying to explain good code upkeep that delays business for a few weeks.
Re:Ask HN: Where do I find good code to read? by eternityforest on Thursday August 24, 2023 @02:10PM (#37252514)
Rewriting throws away years of accumulated edge cases handling. Suddenly the thing doesn't work because one particular model of printer needs an undocumented command to enable some feature, or users are inputting bad data because you forgot the checks you accumulated...

Seems not ideal for end users, unless you're working with microservices or something with well defined specifications that people are actually paying attention to.

Re:Ask HN: Where do I find good code to read? by Zetice on Thursday August 24, 2023 @05:30PM (#37254792)
Depends on the field, but what I work on generally evolves so much over time that by the time I'm ready for a rewrite, the "edge cases" I had to account for when I started are either solved, partially solved, or can be isolated into some tiny part of the codebase that could be ported over from the previous code.

Beside, "rewrite" here doesn't mean "new repo, new project, new everything" it means reimplementation, usually based on the lessons learned from the previous implementation, and that does include edge case handling, as well as expanded functionality to "underwrite" or justify the effort spent on the rewrite.

Re:Ask HN: Where do I find good code to read? by vendiddy on Friday August 25, 2023 @08:33AM (#37260977)
Rewriting does not need to be an all-or-nothing endeavor.

If you design your app as a collection of subsystems, it's sometimes faster to destroy and rebuild one of them than it is to refactor.

Re:Ask HN: Where do I find good code to read? by nailer on Thursday August 24, 2023 @09:24AM (#37248470)
> Focus instead on writing code you can throw away easily, code that you are wholly unattached to and is isolated enough that rewriting it won’t cost absurd hours.

> Good code is highly maintainable so that you can continue to meet business objectives in a timely manner without regressions.

I think you essentially agree on what people should do, regardless of whether you call this 'good code' or just maintainable code.

Write tests. Give things good names. Use comments to explain why you're doing something, not how to program. Don't copy and paste the same implementation x times because that way there's only one place to fix it.

Re:Ask HN: Where do I find good code to read? by nkjnlknlk on Thursday August 24, 2023 @12:44PM (#37251161)
> Don't copy and paste the same implementation x times because that way there's only one place to fix it.

But also sometimes it makes more sense to copy and paste over trying to fit an abstraction where it shouldn't be. :)

I think the purpose of questions like the ones by OP is not to figure out "rules" (which are useful only for beginners) but to figure out where and why rules were broken. Sometimes (often) the answer is time, but that in and of itself is a useful example.

Good intermediate (I suppose Sr. in our industry) level code is notoriously difficult to find examples of and mentor toward.

Re:Ask HN: Where do I find good code to read? by johnnyanmac on Friday August 25, 2023 @12:58AM (#37258246)
>But also sometimes it makes more sense to copy and paste over trying to fit an abstraction where it shouldn't be. :)

depends on goals. diverging modules should be copy-pasted, two modules that rely on the same functionality should be consolidated (not necessarily abstracted, but synchronized somehow). Those are both two common cases, so there's no general advice on which is better.

>Good intermediate (I suppose Sr. in our industry) level code is notoriously difficult to find examples of and mentor toward.

so much industry code and knowledge is proprietary, so I imagine that is by design. even intermediate code has a bunch of value to a company, even if the company lets go of that engineer to make their earnings report 0.1% higher.

Re:Ask HN: Where do I find good code to read? by gwbas1c on Friday August 25, 2023 @09:27AM (#37261468)
> But also sometimes it makes more sense to copy and paste over trying to fit an abstraction where it shouldn't be. :)

I find that's a smell of limited languages: Maybe a language has poor error handling semantics, maybe it's not expressive enough to make a parameter generic.

It can also be a smell of not understanding the language well enough, too. Maybe there is no need to copy and paste, but the programmer didn't understand the language well enough to make a generic abstraction.

Re:Ask HN: Where do I find good code to read? by nkjnlknlk on Friday August 25, 2023 @12:53PM (#37264016)
I agree. I've had the unfortunate experience of moving from more expressive languages and interesting problems to less expressive languages and boring problems as the size of my TC and company go up. :')

But you can only do what your tools allow you to do.

Re:Ask HN: Where do I find good code to read? by shortrounddev2 on Thursday August 24, 2023 @12:39PM (#37251059)
"maintainable" code is disposable. Modern web stacks are built on the idea that you can delete a file and re-implement its interface with a different service behind it later on. Instead of writing code which will be easy to modify, write a good interface which solves your problems in a way that's easy to reason about, and feel free to write garbage implementations that will get "refactored" (thrown away) every year or so
Re:Ask HN: Where do I find good code to read? by boredtofears on Thursday August 24, 2023 @04:11PM (#37253938)
You can write good code behind well defined interfaces, too. There's no reason you have to pick one or the other. Bad implementations are still bad.
Re:Ask HN: Where do I find good code to read? by vendiddy on Friday August 25, 2023 @08:41AM (#37261053)
I usually find it faster to define a good interface, hack together and implementation, then rewrite it.

A good interface limits the blast radius of my refactor.

Re:Ask HN: Where do I find good code to read? by johnnyanmac on Friday August 25, 2023 @12:54AM (#37258232)
>Modern web stacks are built on the idea that you can delete a file and re-implement its interface with a different service behind it later on.

and that paradigm is exactly why my domain is the start opposite of front end web development. Code I write may be used by thousands of other engineers over decades. I can't take into account every edge case, but I do try to write with the assumption that one day some archeologists will uncover that code as some Rosetta Stone. Of course, modern demands never let me reach that ideal, but it teaches care and good documentation.