4 ms·
Rule of Three
- ck45 3y agoI usually share this timeless gem: https://blog.codinghorror.com/rule-of-three/amp/ https://blog.codinghorror.com/rule-of-three/amp/
- sonofhans 3y agoHa! I thought this the survival “Rule of 3s”: * 3 minutes without oxygen * 3 hours without shelter * 3 days without water * 3 weeks without food
- Aardwolf 3y agoInteresting, I thought water was more important than shelter. But sources cite the same.
- gandalfgreybeer 3y agoSame thoughts on shelter vs water. But maybe there’s an assumption that there’s a barrage of elements or the environment.
- sonofhans 3y agoThe list is mostly for orienting around priorities. In a survival situation, what is truly most important to do next? Is it worth looking for water when you don’t have a shelter yet?
- ahofmann 3y agoTry walking with shirt and jeans in windy rain. After a hour or so, it will feel like torture. I can see why they put shelter over water.
- gandalfgreybeer 3y agoMakes sense. The fact that it’s not immediately clear to me, makes me believe I’ve had a sheltered life (pun intended). I should go out more often aside from usual city running or going to the beach.
- pinkmuffinere 3y agoI was confused about the 3 hours without shelter bit, as it seems most people would be totally fine without shelter until around the 18 hour mark. But there is some important context: - You can survive three minutes without breathable air (unconsciousness), or in icy water. - You can survive three hours in a harsh environment (extreme heat or cold). - You can survive three days without drinkable water. - You can survive three weeks without food
- adamzerner 3y agoI have linked to this so many times over the years. Very cool to see it on the front page.
- globular-toast 3y agoI honestly thought I made this up myself. I've told so many people over the years about the rule of three. I guess there's a chance I saw this before and forgot, or that I converged on the same rule.
- smokel 3y agoIn trying to look up the scientific word for this, I discovered "cryptomnesia" [1], which I certainly did not invent myself. Not sure if this is actually describing your phenomenon, it might also be "unconscious plagiarism". [1] https://en.m.wikipedia.org/wiki/Cryptomnesia https://en.m.wikipedia.org/wiki/Cryptomnesia
- mihaic 3y agoThis does seem like one of those rules that would be independently developed by many experienced developers, so neither is hard to believe.
- simonhamp 3y agoI prefer WET: Write Everything Twice, which I believe carries the same principle and has the nice appearance of being something of a counter to DRY
- AxelLuktarGott 3y agoI find bad abstractions to be a much greater liability than unabstracted code that could be combined into one function but isn't. It's relatively easy to combine code and much harder to disentangle it
- tasubotadas 3y agoI second this. Only remove duplication when it either becomes super obvious or painful.
- guytv 3y agoI am using rule of two. I refactor at the second appearance. I started doing this when programming Ruby on Rails a few years back, where DRY (Don't repeat yourself) was a big thing there.
- lostmsu 3y agoI am using rule of 1.5. It's just like rule of 2, but I also name (e.g. make a separate function) any block of code whose result value is not obvious from a single glance.
- tasubotadas 3y agoThat's a mistake that leads to premature generalization
- n2d4 3y agoIt's a mistake to pick any of those rules as an absolute truth. It varies by task, maintenance and time constraints. DRY makes a lot of sense in some cases, but some others even need a rule of four+ (think of heuristics-heavy code). IMO DRY is most useful when working on a codebase owned by someone else than you.
- okaleniuk 3y agoCloning things makes maintenance harder linearly. Generalizing things makes maintenance harder exponentially. Counterintuitively, generalization only makes sense on small numbers or reiterations, not the vice-versa. I started https://wordsandbuttons.online https://wordsandbuttons.online as an experiment in zero-dependencies architecture. No third-party, no self-reference. Every page is completely independent. I was told, that as it grew, it would inevitably become impossible to maintain. Five years passed, including a two-year pause for writing a book. I did more than half a hundred interactive tutorials and quizzes, and continue to add them when I have time. The thing simply refuses to go "too complex to maintain". All the maintenance problems I ever faced with this design were handled within minutes. If there is too much typing, I write a Python script. If not, I do the change manually, replicate it in a few pages, and go on. As a free bonus, since all my pages are essentially hand-written, no dependencies = no uncontrolled growth, they are all fewer than 64 KB each. Ultra-fast to load, and I never get a "Reddit effect" since even 1000 requests a second is only 64 MB of data. It's green then tea too. I usually have a few hundred thousand visitors a year, and they barely consume enough electricity to boil a kettle of water. I think this rule of three, like many others is just an attempt to escape well-known complexity issues by putting them under a carpet of less known complexity issues. I'm very happy to have ignored it when considering design for my site.
- lostmsu 3y agoThis looks like static pages. Not sure what your code style has to do with performance in that case. Even if it had ephemeral state 1000 rps for in memory data is trivial.
- jaakkis 3y agoNever heard of this rule of three, I was expecting this one: https://en.wikipedia.org/wiki/Rule_of_three_(C%2B%2B_programming) https://en.wikipedia.org/wiki/Rule_of_three_(C%2B%2B_program...