DRY is an over-rated programming principle?
371–380 of 501 posts
Re: DRY is an over-rated programming principle?
#372Re: DRY is an over-rated programming principle?
#373Every time I read an article like this, "why is overrated", I think, yeah you are right in theory. But most places I have worked, these best practices were not overused, but underused. If you have the problem that your coworkers create unneccessary abstractions, I envy you, because I have so often had the opposite problem. Maybe this is not the case if you work in a great software development team. But if you work so…
> People not able to factor out functions or structure their code in a readable way. Variables are called v1, v2, v3. Unit testing seen as a waste of time. CI seen as a fun toy. They lack the experience to even notice the difference. Had a colleague work under a 'team lead'. Needed to take a form with variable amount of rows of input data - max 50 - and take data, parse it, and store it. Took 20-30 lines of code. Nex…
My senior engineer advised me against using Java .sort() because “we didn’t write it so we couldn’t be sure it would do the same thing every time.”
Re: DRY is an over-rated programming principle?
#374Re: DRY is an over-rated programming principle?
#375Earlier quoted context omitted.
make_pepperoni_pizza() is bad code compared to make_pizza(toppings=[PEPPERONI]) How would you make Hawaiian pizza? I forget, does it include Ham? or just pineapple? you're forced to the remember that nuance in your suggested implementation, but not with "make_hawaiian_pizza()"
It's data. make_pizza(toppings=HAWAIIAN_TOPPINGS) or make_pizza(HAWAIIAN) or similar. Data should generally not be hard-coded, both because it changes and because it wants to be validated. Starting with: HAWAIIAN = { TOPPINGS: [ PINEAPPLE ... is okay. That can later be loaded from a config file, a database, or otherwise, as the system expands.
Re: DRY is an over-rated programming principle?
#376Earlier quoted context omitted.
Yeah there are a lot of definitions out there that are along these lines and they do hollow out my argument. But why call it "Don't Repeat Yourself" if it actually means something somewhat more subtle than that. I firmly believe many junior developers don't grasp the nuance and based on the comments I'm not the only one who thinks this. So if DRY is widely understood by developers to mean literally "don't repeat your…
I think the rule should be "Try not to repeat yourself" Rules are like alarms they draw our attention to some peculiar condition which gives us pause to think about if it's kosher and if not why not.
Someone says "never do this" or "always do that" and you can apply those rules with abandon (often leaving a maintenance nightmare in your wake).
There are no rules to programming.
Re: DRY is an over-rated programming principle?
#377Earlier quoted context omitted.
> People not able to factor out functions or structure their code in a readable way. Variables are called v1, v2, v3. Unit testing seen as a waste of time. CI seen as a fun toy. They lack the experience to even notice the difference. Had a colleague work under a 'team lead'. Needed to take a form with variable amount of rows of input data - max 50 - and take data, parse it, and store it. Took 20-30 lines of code. Nex…
It's not usually needed (especially these days), but there are times that it is better to repeat every possible iteration by hand and not have a loop. This is a technique called loop unrolling. It is done for performance reasons. This is something we used to do at a company working on games for the old feature phones (think Nokia 30/40/60 series stuff). The devices were very limited, there is no direct control over J…
Re: DRY is an over-rated programming principle?
#378The article is actually good. The criticisms of DRY here are valid! For criticism 1, I had a coworker once say something that resonated with me: "Just because two things are the same right now doesn't mean they _should_ be the same." So that criticism is totally valid - DRY has to be applied only when things _should_ be the same, and that can actually be hard to identify. That being said, of course the title of the a…
Re: DRY is an over-rated programming principle?
#379Yes, sometimes you may discover that you prematurely DRY'ed the code, and it was just accidentally similar. Easy, you just un-DRY the code. This is a trivial operation. In an IDE it might be a single keyboard shortcut. Going the other way is a difficult and error prone process.
Re: DRY is an over-rated programming principle?
#380DRY is mostly fine in code, but does not hold for data. There, inmutability and audit trails win over DRY, in my opinion.