News for hackers. Stuff that matters.
Re:Goodbye, Clean Code by bcrosby95 on Saturday January 11, 2020 @11:13PM (#22024423)
The rule of 3 usually is in reference to small scoped abstractions, not whole modules or subsystems. We're talking about extracting a short function, not significant and potentially thorny chunks of code.

But I guess no one explicitly spells this out, so I could see where someone could become confused.

Re:Goodbye, Clean Code by valand on Sunday January 12, 2020 @01:15AM (#22024793)
Premature abstraction. Rule of 3 helps. But I found better principle for it:

Any abstraction MUST be designed to be as close as possible to be language-primitive-like. Language primitives are reliable, predictable, and non-breaking. If they do, they don't affect business logic written on top of it. If parameters are added, defaults are provided. They don't just abstract, they enable developers to express business logic more elegantly.

The challenge is to pick the part of the code abstractable to be primitive-like first and make it a top priority.

This is why language features like Rust async, Go channel-based comm, ES6, C++ smart pointer was such hype in their time and is used up until now. It also applies to enabling tools such as React, tokio, wasm-bindgen, express, TypeScript, jquery (even this which is not a thing anymore).

Re:Goodbye, Clean Code by pvorb on Sunday January 12, 2020 @03:14AM (#22025142)
I find abstractable parts in code by thinking about potential names for it. If there is no good name for a potential common function, it's probably not a good idea to extract the section into a function. Maybe it can be extracted into two separate functions with good names?
Re:Goodbye, Clean Code by konschubert on Sunday January 12, 2020 @05:10AM (#22025497)
This is a proxy for having a well-defined purpose for a function.
Re:Goodbye, Clean Code by pvorb on Sunday January 12, 2020 @08:23AM (#22026169)
Yes, absolutely, but it's one that's easier to teach juniors.
Re:Goodbye, Clean Code by aj7 on Sunday January 12, 2020 @12:55PM (#22027768)
Like.
Re:Goodbye, Clean Code by Stratoscope on Saturday January 11, 2020 @11:22PM (#22024461)
Yes, exactly, and it is such a good rule to go by so much of the time. But like many rules, you need judgment to know when to apply it.
Re:Goodbye, Clean Code by hyperpallium on Saturday January 11, 2020 @11:25PM (#22024474)
Rules are a poor substitute for actual thought.
Re:Goodbye, Clean Code by thunderbong on Sunday January 12, 2020 @12:11AM (#22024616)
> Rules are a poor substitute for actual thought.

This should be the guiding principle of life!

Re:Goodbye, Clean Code by HomeDeLaPot on Sunday January 12, 2020 @12:15AM (#22024628)
The guiding principle... a rule, so to speak!
Re:Goodbye, Clean Code by NegativeLatency on Sunday January 12, 2020 @02:03AM (#22024956)
Everything in moderation, even moderation itself.
Re:Goodbye, Clean Code by speedplane on Sunday January 12, 2020 @05:32AM (#22025580)
> Everything in moderation, even moderation itself.

This was my guiding principle in life, and I thought I was pretty clever for coming up with it, but later found out that someone far more clever got a lock on the phrase in history: https://www.goodreads.com/quotes/22688-everything-in-moderat...

Re:Goodbye, Clean Code by a1369209993 on Sunday January 12, 2020 @06:02PM (#22030303)
No, no, no; it's "Everything in moderation, especially moderation.". :)
Re:Goodbye, Clean Code by Stratoscope on Sunday January 12, 2020 @03:49AM (#22025234)
Really? I'm sure you know that all generalities are false.
Re:Goodbye, Clean Code by antonvs on Monday January 13, 2020 @10:55PM (#22041701)
Only a Sith speaks in absolutes
Re:Goodbye, Clean Code by pvorb on Sunday January 12, 2020 @03:18AM (#22025156)
You nailed it. I will print this and hang it on the wall in our office.
Re:Goodbye, Clean Code by he0001 on Sunday January 12, 2020 @02:55AM (#22025099)
I thought rules were a way of organizing thought, like a language which is governed by rules.
Re:Goodbye, Clean Code by scarface74 on Sunday January 12, 2020 @11:27AM (#22027104)
The rule of 3 usually is in reference to small scoped abstractions, not whole modules or subsystems. We're talking about extracting a short function, not significant and potentially thorny chunks of code.

I would say it’s for entire features sometimes. For instance, we are a B2B company. We have features on the roadmap or a feature might be suggested by a client. Either way, you hit the jackpot if you can get one client to pay for a feature that doesn’t exist in your product that you can then sell to other clients.

The problem is that you don’t know whether the feature is generally useful to the market. But you think it might be, in that case, you build the feature in a way that is useful to the paying client and try not to do obvious things that are client specific. But until you have other clients you don’t know.

Re:Goodbye, Clean Code by Gibbon1 on Sunday January 12, 2020 @09:32PM (#22031380)
That's been my experience doing embedded stuff. Customers will tell you they want a feature. You'll implement it then find out they don't need it enough to devote resources to utilize it on their end. So then it just lingers in the code base. And never gets real world testing. Lately I've been pulling unused features and consigning the code to the land of misfit toys. Just so I don't have to maintain them.
Re:Goodbye, Clean Code by scarface74 on Monday January 13, 2020 @10:51AM (#22035464)
If that’s the case and they were willing to fully pay for the feature, at professional services + markup hours, it wasn’t a loss. In our case, we still got unofficially professional services and recurring subscription revenue and now we have a “referenceable client”.

If it’s behind a per client feature flag, it doesn’t cause any harm.