News for hackers. Stuff that matters.
Re:How to build apps pragmatically by SirensOfTitan on Saturday February 01, 2020 @03:53PM (#22213153)
More often than otherwise, I’ve found code duplication preferable over abstraction. I only abstract code when I understand the problem space really, really well (I.e. have solved it before), or when I can have some certainty the wrong abstraction won’t cost me too much time to fix.
Re:How to build apps pragmatically by codr7 on Saturday February 01, 2020 @04:37PM (#22213426)
It takes time to build the kind of self confidence and humility it takes to allow a code base to sprawl for a while until you've seen enough examples to have an idea where it's going.

The first thing I like to do is solve the problem, period. Without inventing anything, just simply write code to cover most cases. Then I'll start improving on it in small ways, cutting down on duplication and inventing abstractions; until I reach a tipping point where I can visualize a complete design, which results in a major refactoring.

It looks messy in comparison to so called best practices, but it's faster and the code that comes out of the process is clearly better.

DRY is hurting more than helping if you ask me; because it shames inexperienced developers into premature abstraction, causing plenty of pain and misery along the way.

Re:How to build apps pragmatically by gpu_explorer on Sunday February 02, 2020 @01:56AM (#22215576)
This. 1000x this.
Re:How to build apps pragmatically by smoe on Saturday February 01, 2020 @04:18PM (#22213301)
Agreed.

Also one can get over-eager with abstractions over things that are not real duplicates. They just happen to look similar at this moment in time.

In this category, I would also put premature automation before learning what it actually is you are automating among other things.

Or more generally: Don't try to be clever about something you don't (yet) understand.

Re:How to build apps pragmatically by chubs on Saturday February 01, 2020 @04:27PM (#22213361)
I once read a guideline (by DHH I think?) "One, Two, Refactor" as in write it once, then duplicate it, and the third time think about refactoring it to be DRY. But yes it's all about discerning what's reasonable given the circumstances, and not being dogmatic.
Re:How to build apps pragmatically by gfodor on Saturday February 01, 2020 @04:00PM (#22213196)
It does seem that this lesson takes at least a decade to internalize, and as such one can usually estimate the level of experience a person has based upon how much they embrace “DRY” as a hard rule vs a guidepost.
Re:How to build apps pragmatically by ken on Saturday February 01, 2020 @11:12PM (#22215093)
I've been programming for over 20 years, and I can't say I've ever regretted being too DRY. I'll take abstraction any day.
Re:How to build apps pragmatically by gfodor on Sunday February 02, 2020 @03:51AM (#22215950)
Well, the pain you get from this is hard to peg as being due to over-DRYing, it manifests as bad abstractions, which are hard to trace the origins of.
Re:How to build apps pragmatically by meestaahjoshee on Saturday February 01, 2020 @07:19PM (#22214237)
"duplication is cheaper than the wrong abstraction"

i think i read that in POODR by sandi metz

Re:How to build apps pragmatically by ngcazz on Sunday February 02, 2020 @02:19AM (#22215666)
Her book with Katrina Owen “99 Bottles of OOP” lays out an even better case for this I think. Particularly useful is the introduced language to help measure the state of a codebase (“shamelessly green” vs “incomprehensibly concise” etc).

Also quite like Fowler’s observation in Refactoring that (to paraphrase) abstractions are earned, not enforced.

Re:How to build apps pragmatically by doctor_eval on Saturday February 01, 2020 @05:51PM (#22213770)
Wasn’t it Fred Brooks who said, “Plan to write it twice, you will anyway”?

I fell into the trap of premature abstraction yesterday: I spent an hour breaking down functionality to make it “easier” to implement different backends, only to realise that the “abstraction” was strongly coupled to the structure of the single backend I’d written.

Young me would have forged on regardless because “abstractions”. Old me threw it away.

Re:How to build apps pragmatically by thunderbong on Saturday February 01, 2020 @09:02PM (#22214656)