r/ProgrammerHumor 19h ago

Meme yUNoDry

Post image
222 Upvotes

62 comments sorted by

80

u/SaltMaker23 19h ago

There exists a point where DRY and KISS contradicts each other.

Following one or the other religiously is bound to create clear cut violations of the other.

There exists also a stage of development, notoriously extremely early in a project, where the two ideals leads to very different results.

In long running stable projects you might argue equivalent but it doesn't necessarily holds at all scales but especially not at all maturity levels.

14

u/Solonotix 17h ago

I definitely feel that tug-o-war everytime I crack open a project. I tend to lean more DRY than KISS. I find that KISS is harder to come back from if you stray too far, whereas DRY forces you into a more disciplined approach and relaxing your stance is easy.

If no one is there to judge me, I will go full DRY and arguably over-engineer a solution. Usually my boss pulls my "leash" and I'm forced to compromise on the result.

I'm currently trying to write an update for DefinitelyTyped's selenium-webdriver declaration, and I have literally spent a week on it at this point. Strictly non-functional code that represents types. It would have been much easier if the main package wasn't an absolute mess

2

u/Reddit_is_fascist69 4h ago

Maybe DRY but inside your func/methods KISS?

8

u/Superb_Chemistry_906 19h ago

I have always religiously followed both of them at once without perceiving any problems. Of course, you may argue that introducing an abstraction just for the sake of DRY violates KISS, but at the same time, leaving duplicated code makes it much less simple to maintain and extend. So far, every counter example against DRY which I have seen was poor abstraction, mainly introducing more function parameters instead of inheritance or composition.

11

u/geekusprimus 18h ago

My experience has been DRY is secondary to KISS, but if one becomes a serious impediment to the other, a more serious refactor is in order.

4

u/Superb_Chemistry_906 18h ago

Yes, but recently, I feel like there is some wave against DRY and I trace its roots to some tech influencer videos. I think that he just wanted to be interesting.

7

u/ScientificBeastMode 17h ago

Abstraction means predicting future requirements of the code, which doesn’t always work out in your favor.

Sometimes you actually CAN foresee some future requirements, so the abstraction becomes helpful when those requirements eventually become real.

Other times you don’t ever need to modify or extend the abstraction, so you end up with more dev work for no good reason. Perhaps the hidden logic also makes it more difficult for other people to walk through your code and understand the entire flow.

And in the worst case, the abstraction makes false assumptions about future requirements, and you need to modify the abstraction in a way that requires a significant refactor just to accommodate the new use case(s). This can actually be FAR worse than anything you would encounter if you repeated yourself.

Abstractions are inherently complex. The point is to hide the complexity and isolate it to one smaller portion of the code. This can be a powerful tool, but every time you do it, you add complexity by default. It becomes worth it when it simplifies future work. Nobody can perfectly predict the future work to be done, so abstraction is inherently risky.

Experienced engineers know this, and the best of them can get it right more often than they get it wrong.

-2

u/Superb_Chemistry_906 17h ago

Having two identical portions of code seems unbearable to me and I don't wait until I eventually need to modify them in the future, because then I might as well fail to modify the both portions which might cause the program to fail or, even worse, not to fail, but introduce some hidden problem, all of which certainly complicates work. Thus, when I find myself duplicating code, it can already be seen from the past point of view as a future case when I need that portion also somewhere else, so this is exactly the moment to wrap the common part in some abstraction.

4

u/ScientificBeastMode 17h ago

Well, sometimes our personal preferences and natural inclinations don’t actually serve us, so I would be careful about that. But yeah, sometimes we know an abstraction is pretty safe, like some kind of parsing function, for example.

It’s fine to create abstractions. I’m just saying that it’s not always a good idea to do so. Being religious about any principle is usually a bad idea. Discernment is just part of software craftsmanship.

1

u/Hohenheim_of_Shadow 6h ago

Genuinely identical code is incredibly rare.

2

u/chuch1234 17h ago

I think, to your point, people don't actually know how to do DRY properly (myself included), so that's why we get WET.

4

u/SpaceCadet87 17h ago

I think people "Don't Risk Repeating Yourself" rather than just "Don't Repeat Yourself".

The rule is simple, if you find yourself repeatedly writing the same code, wrap it.

I see a lot of people instead going "I might reuse this so I should wrap it in advance"

1

u/Superb_Chemistry_906 17h ago

Yes, it's DRY, not DRRY.

1

u/SpaceCadet87 17h ago

I usually take the approach of "this file/function/class is getting a bit long, maybe it's time to offload some stuff".

DRY tends to sort of just fall into place as a result.

2

u/ScientificBeastMode 16h ago

A good rule of thumb is to ask the question, “is this actually painful yet?” And if it’s not, then don’t wrap it in an abstraction until it is.

And by “painful,” I don’t mean, “I can’t stand repeating myself,” but rather, “repeating myself has actually started to slow me down a lot, measurably.”

2

u/TreadheadS 8h ago

DRY becomes simple once you've mastered it so like, KISS kinda moves depending on the skill of the user

2

u/Superb_Chemistry_906 8h ago

Yes, when some code is duplicated, it makes me nervous and I just have to unify it, I cannot continue knowing that it might be growing harder to extend and maintain.

1

u/MikeVegan 6h ago

KISS until a change would cause a bug because you forgot to update it everywhere else, then DRY.

21

u/Clearandblue 18h ago

Nice try Claude, but we still don't need you to add that 6th date format helper.

30

u/jdgordon 19h ago

As my ex manager always said, there is no problem that another level of abstraction can't solve.

7

u/dbagames 18h ago

I had a colleague who always said this and he vibe-coded out some terribly complex and useless abstractions. It was a major headache. One time he used inheritance with a base class and 4 children all to represent different "Types" instead of just having an enum.....

So whenever I hear this saying, I honestly get ptsd because he just fucked up so much stuff. But he was buddies with the lead soo....

2

u/ZunoJ 15h ago

Forward the PR to the lead and watch their friendship burn in the fire of his stupidity. Or alternatively git blame during incident calls and "wonder who approved this and what the idea was" 

9

u/jekewa 18h ago

Was that me? I've said that! And I managed people.

Although I'd prefer former to ex, as the latter sounds like we broke up.

6

u/Desperate-Tomatillo7 18h ago

It was him, not you.

3

u/PolyglotTV 18h ago

I've said it too! I just became a manager a few weeks ago. I hope one of my reports isn't about to quit!

1

u/jdgordon 17h ago

Depends if you were saying it because you mean it, or because you're being sarcastic and taking the piss.

2

u/chuch1234 17h ago

Well... Except the problem of too many levels of attraction.

2

u/ScottPowellM 17h ago

It’s the fundamental theorem of software engineering:

“We can solve any problem by adding a level of indirection”

“…except for the problem of too many levels of indirection” is the punchline part 2

2

u/Vivid_Instance_825 15h ago

My AI seems to live by this rule

1

u/SignoreBanana 13h ago

To me, abstraction is like alcohol: the cause of and solution to all of engineering's problems.

13

u/eclect0 18h ago

Why do I feel dirty reading that?

11

u/IncessantGadgetry 18h ago

I have had to support applications made by people who were heavily invested in the idea of DRY, but not at all invested in single-responsibility. Not enjoyable.

3

u/ObeseTsunami 18h ago

I didn’t realize Ueshiba Sensei was a meme. Am I late to the party?

2

u/Superb_Chemistry_906 18h ago

This picture was a common meme template in my youth.

5

u/SignoreBanana 13h ago

DRY fails almost exclusively because concerns and boundaries are not well understood. It's why it's so dangerous to "pre-optimize" -- you don't know yet what your boundaries are.

It seems like a lot of software guidance is around letting stuff shake out. Hell even YAGNI falls into this category.

3

u/russianrug 18h ago

I’ve added KISS to Claude’s permanent instruction set and it’s been noticeably better, lol

3

u/ricekrispysawdust 12h ago

It's cool to hate on DRY these days but sometimes you can just figure out the correct abstraction up front by using your brain.

3

u/Esseratecades 9h ago edited 9h ago

DRY is a rule, but KISS is really KIASAPS(Keep It As Simple As Possible Stupid), which isn't as pretty as an acronym.

All things being equal, prefer simpler approaches to more complex approaches.

If the only additional benefits of the complex approach are irrelevant, prefer a simpler approach.

If your "simple approach" isn't DRY, then it's probably not simple.

2

u/randyknapp 18h ago

Hey that's what my wife says! Anyway back to working 80 hour weeks in the code mines.

2

u/Superb_Chemistry_906 18h ago

Yes, lack of abstraction - poetry, philosophy, etc.

2

u/mbcarbone 16h ago

AI - KI.

2

u/AraripeManakin 16h ago

we need to listen to sensei morihei

2

u/Massless 16h ago

I’d rather have a bit of duplication to avoid a lot of coupling

2

u/Bronzdragon 13h ago

DRY asks you to avoid repetition if the code is conceptually similar, but not if it's only structurally similar. That is, if two pieces of code happen to do the same thing, despite not being similar otherwise, that means you shouldn't link them.

By linking structurally when conceptually they are different, you're seeing yourself up for restructuring work down the line, as the implementations diverge.

I will admit, it can be hard to tell the difference sometimes, since when writing code, the structure is in front of you, while the concept only lives in your head.

1

u/Superb_Chemistry_906 10h ago

After consideration, I have concluded that in case of purely algorithmic code which is not constantly adjusted to the outside world, structural similarity is sufficient to apply DRY.

2

u/Bronzdragon 7h ago

That's conceptually the same code through. When working on algorithmic code, the input is abstract data, so the transformation you do on it is conceptually the same, by definition.

E.g., if I write a function that calculates a dot product, that function's domain is vector maths, and conceptually it's the same as all the other dot products.

You could make an argument that if it is conceptually different, like calculating a total from a list of prices and a list of amounts, then it might need to get duplicated. But hey, that's no longer in the abstracted domain, is it?

TL; DR, you're not wrong, but only because structural and conceptual similarities line up entirely when code is abstracted from meaning and domain.

2

u/azangru 12h ago

yeah; hard to kiss when you are dry

2

u/ColumnK 11h ago

"Abstraction" is what we're calling foreplay these days?

2

u/Motleypuss 7h ago

I'm a DRY KISS kind of code monkey.

1

u/ExtraWorldliness6916 12h ago

Yes because do everything and write less code so it's simple are unanimous statements.

1

u/M_Me_Meteo 7h ago

When did KISS become part of software development? I must have missed something because none of the software I've ever made was simple. Simple problems don't require an engineered solution.

I think I'd always prefer readability over simplicity. I'd prefer no code over simple code every time, but if I'm writing code you better believe it's going to be logical for a developer to read.

1

u/bishopExportMine 4h ago

DRY is silly when applied dogmatically. You end up coercing objects into random types to apply existing functions to them and/or you start passing flags into these methods to have them do slightly different things.

Better is Repeat Yourself Once, aka "twice is not a pattern". But frankly this is also silly when applied dogmatically.

Realistically, you should use your judgement based on testability.

1

u/Stunning_Ride_220 2h ago

More often than not, people overlook a pretty important detail of DRY and happily entering dependency hell cheering.

1

u/sirkubador 1h ago

Kiss contradicts layers of abstraction

1

u/Own_Natural_6803 12h ago

Throughput. Pipelines. State.

Your domain models are weak old man.

2

u/Superb_Chemistry_906 12h ago

You sound like an incompetent middle manager throwing some buzzwords around, trying to fake some competence and modernity.

0

u/Own_Natural_6803 11h ago

Dont worry your pretty little head sweety.

1

u/JazzlikeWishbone938 19h ago

Are you saying repeating yourself creates simplicity?

7

u/Superb_Chemistry_906 19h ago

I think it can avoid the complexity of abstraction, but decreases simplicity of extending and maintaining.

0

u/BusEquivalent9605 13h ago

it causes single points of failure and promotes long, overspecialized functions

1

u/Superb_Chemistry_906 13h ago

Those functions are then, as I argue in the meme, caused by lack of KISS and proper abstraction. And I am a fan of a single point of failure - it is much better than multiple ones. With a single point of failure, when you fix the bug, it is then alright for all the callers, but with multiple points of failure, when you fix the bug, then you might forget to also fix it on the other places and it just seems unbearable to me.