News for hackers. Stuff that matters.
Re:There’s No Such Thing as Clean Code by gefhfffh on Friday January 28, 2022 @06:18AM (#30113240)
When can you rebuild at zero cost?

I have made similar avoidable mistakes of not thinking it through enough, could have saved me a lot of rewriting, which was pretty expensive

Re:There’s No Such Thing as Clean Code by skohan on Friday January 28, 2022 @06:42AM (#30113442)
Rewriting is incredibly cheap! And you learn a lot from the failed attempts.

Again to the house analogy, if you could just build 3 vestibules to see how they fit with just a little typing, that would be far and away preferable to committing to everything on paper before hand.

Re:There’s No Such Thing as Clean Code by gefhfffh on Friday January 28, 2022 @06:56AM (#30113547)
No, it is not cheap, generally.

Example:

Dendrite[0] was going to be a Rewrite of Synapse (which was a prototype which ended up going into production). The rewrite started more than 5 years ago, had lots of development breaks and it still is nowhere complete or close to replace a existing Synapse instance (which even today is ... Well ... suboptimal software).

The current plans are to support and use both servers long term, because Synapse is already too widespread.

I wouldn't call that cheap.

[0]: https://github.com/matrix-org/dendrite

Re:There’s No Such Thing as Clean Code by skohan on Friday January 28, 2022 @08:29AM (#30114293)
Well starting from scratch for a rewrite is generally a bad idea. I'm more a fan of incremental re-wrties. But I have code bases I have been working on for years with tens of thousands of lines where basically the entire thing gets rewritten ever 18 months or so, a bit at a time.

Isn't your example proof of the benefit of pragmatic coding? Synapse is actually serving users right now. Dendrite sounds like a "better design" which is stuck in purgatory.

Re:There’s No Such Thing as Clean Code by gefhfffh on Friday January 28, 2022 @11:54AM (#30117228)
They tried an incremental rewrite before. They failed, and started Dendrite.

https://matrix.org/blog/2020/10/08/dendrite-is-entering-beta

Re:There’s No Such Thing as Clean Code by MrPatan on Sunday January 30, 2022 @05:56AM (#30135785)
Survivor bias.

You don't see all the perfectly designed codebases that never went anywhere.

We only talk about legacy code because it's the one that pays the bills.

Re:There’s No Such Thing as Clean Code by nfw2 on Friday January 28, 2022 @10:49AM (#30116113)
Are you the only working on the codebase? It may be easy to rewrite your own codebase, but it's certainly not easy to rewrite someone else's. Especially if they haven't been caring about code quality and/or test coverage.

My definition of "good-quality" code is pretty much exactly "how difficult would this codebase be for a new engineer to understand and modify safely."

Re:There’s No Such Thing as Clean Code by hinkley on Friday January 28, 2022 @10:58AM (#30116277)
You can go really really fast when you don’t give a shit about consequences.

Often the worst code comes from prolific people. There’s just so much if it. And if you touch it you will break it at least 1% of the time, so you have to pick your battles when you are trying to keep the ratio under control.

Re:There’s No Such Thing as Clean Code by skohan on Friday January 28, 2022 @11:32AM (#30116864)
If you write loosely-coupled code, it shouldn't be that easy to break things unless you're careless.
Re:There’s No Such Thing as Clean Code by hinkley on Friday January 28, 2022 @03:25PM (#30119866)
Nobody in this whole post is talking about loosely coupled code. If you find someone complaining about how hard it is to modify loosely coupled code, you have my permission to fire them.

For everyone else this is tautological. Good code can continue to be good code.

Re:There’s No Such Thing as Clean Code by hinkley on Friday January 28, 2022 @01:06PM (#30118229)
If it were loosely coupled it wouldn’t be an anecdote in this conversation. There is no “I”, there is no “you”. There is only “us”. I can only control Us so much, and I don’t have a time machine.

People who only have green field projects as their context are very frustrating in conversations like this. They make suggestions like, well, don’t fuck up in the first place. I don’t know what your history is but that’s the feeling I’m getting.

Re:There’s No Such Thing as Clean Code by skohan on Friday January 28, 2022 @01:26PM (#30118476)
Not that it matters but I've worked on a mix of green-field projects and mature codebases in various domains with teams of various sizes over more than a decade of professional experience.

I could assume you're throwing shade on "prolific programmers" out of some sense of insecurity, but it wouldn't be fair to generalize about strangers on the internet ;)

Re:There’s No Such Thing as Clean Code by hinkley on Friday January 28, 2022 @03:10PM (#30119689)
No, It’s an overdeveloped sense of justice.

I just punch up at condescending people. Every discipline has a bunch of armchair people who don’t understand the problem who think “get more exercise” is the response to depressed people or people with chronic fatigue, “eat fewer calories” is the answer to weight issues or diabetes, or “write it right the first time” is a useful response to people trying to solve real world problems.

Kindly let the grownups talk and keep your flash card answers to yourself.

Re:There’s No Such Thing as Clean Code by skohan on Friday January 28, 2022 @03:45PM (#30120138)
> Kindly let the grownups talk

Well one of us is certainly being condescending ;)

And did you really answer twice to the same comment? My goodness I must have really struck a nerve.

Re:There’s No Such Thing as Clean Code by nfw2 on Friday January 28, 2022 @09:22PM (#30123155)
Well this escalated quickly
Re:There’s No Such Thing as Clean Code by hinkley on Friday January 28, 2022 @03:24PM (#30119849)
If everyone is discussing a problem that you don’t see, then why offer your simple solution except to appear smart? And who needs to appear smart? That’s your insecurity. Not mine.
Re:There’s No Such Thing as Clean Code by skohan on Friday January 28, 2022 @12:18PM (#30117539)
Idk maybe it's because I did freelancing for quite some time and was often hired to clean up somebody's mess, but I think it's not so bad to rewrite someone else's code. What I normally do is quarantine the old code behind a clean interface, or else start fresh with a better code structure, and then copy and paste the good bits of business logic from the old project into the new one.

Code has a lot of really great properties which make it easy to modify in provably safe ways if you know what you're doing.

Re:There’s No Such Thing as Clean Code by vault_ on Friday January 28, 2022 @08:46AM (#30114484)
That really depends on what you're working on and to what degree it's coupled to the system it's a part of. A form on a web application, or an API endpoint? Sure, rewriting it is probably trivial. A new process scheduler for Linux? The caching system in an HTTP server? Maybe writing the code will be easy (though probably not), but building any confidence that it doesn't break something that's unexpectedly load bearing will be anything but cheap. And if what you're rewriting that started out as "just code and see what happens" it's going to be more expensive still.

Which isn't to say that rewriting can't be cheap, but some intentional design (or at least diligent maintenance and refactoring) must have gone into the system to support that style of development. At which point you're back to targeting "quality," even if it's no longer a focus of on the smaller scale.

Re:There’s No Such Thing as Clean Code by DerArzt on Friday January 28, 2022 @01:48PM (#30118745)
How are defining cheep, and how big is the metaphorical house? Developer time is not free (unless you are working a personal project) and if an hour or two up front of planning things out stops you from making a lynch pin mistake that needs to be re-written it is better to do the planning.

If the amount of time that it takes to rewrite something is trivial (a week or less) then you aren't working on something all that big/complicated.

Re:There’s No Such Thing as Clean Code by runald on Friday January 28, 2022 @06:38AM (#30113402)
Probably not literally without cost, but if the code was written with disposability in mind combined with just a little bit of pre-planning, then rewriting or refactoring should be indeed trivial.
Re:There’s No Such Thing as Clean Code by gefhfffh on Friday January 28, 2022 @06:45AM (#30113459)
When start off with "wrong" higher level design concepts, neither of those is trivial.

If you're writing a function implementation without thinking about design, well you might be right.

Re:There’s No Such Thing as Clean Code by sseagull on Friday January 28, 2022 @08:22AM (#30114218)
I sometimes wonder if there is a miscommunication. I’m scratching my head sometimes like “how can rewriting/refactoring an entire 10-20k project take negligible time?”

Maybe some people have very small projects compared to what I work on? Or maybe they are talking about the design of a single small component?

I inherited a codebase that needed some refactoring because it was written “to just get it shipped”. If completely fell apart with more users and has taken me a year to get it where it needs to be.

Re:There’s No Such Thing as Clean Code by skohan on Friday January 28, 2022 @09:29AM (#30115007)
But how often would you actually have to rewrite an entire 10-20k LOC project at once?

As you need to add functionality, you can opportunistically find ways to improve the codebase toward a better/more maintainable structure.

I have several large codebases I work on which probably get totally rewritten every 18 months or 2 years, however incrementally.

If you have a working project and you think you need to throw it all out and start from scratch probably it's worth a second thought.

Re:There’s No Such Thing as Clean Code by hinkley on Friday January 28, 2022 @10:56AM (#30116235)
We always talk about time when the elephant in the room is energy. People say we don’t have “time” for that and someone else gets out a calendar and tries to disprove them. Followed by a bunch of backpedaling with other excuses and followed up with foot dragging.

The second elephant in the room is job security. People who write baroque code are hard to fire. Nobody wants to invest energy in understanding their private little Bedlam.

Re:There’s No Such Thing as Clean Code by runald on Saturday January 29, 2022 @12:07AM (#30123964)
When starting, yes it's easy to replace code, even with a shitty design. If it had to take more than ten hundred thousands lines of code to realize that the design is wrong, then it means the author lacks enough awareness or foresight to plan ahead, and no amount of planning will fix that. Code should be replaced/rewritten if the earliest signs faulty design show up, which should be trivial if the code was and remains "disposable".
Re:There’s No Such Thing as Clean Code by mint2 on Friday January 28, 2022 @10:42AM (#30115990)
Not having to pay for physical materials doesn’t mean there are no costs. Throwing hours, days, or weeks of focused work time out the window does not sound cost free to me or Whoever signs paychecks.
Re:There’s No Such Thing as Clean Code by skohan on Friday January 28, 2022 @12:00PM (#30117302)
It's not throwing it out the window if it's an iteration toward a better solution. There's a reason nobody does waterfall anymore in software - up-front planning is less productive than rapid prototyping in most cases.