9 ms·
Algorithms we develop software by
- from-nibly 2y ago> "gun to your head, you have to finish in 24 hours, what do you do?" PSA: if you are a project manager / owner or some other similar position you do not get to ask this. This is a personal educational excercise not a way to get stuff done faster.
- colechristensen 2y ago"gun to your head" is maybe not appropriate for work, but the exercise is good for cutting to the core of a task when necessary. It's really the same question as what is the minimum viable product.
- zug_zug 2y agoYeah, I've certainly seen cases where something was overbuilt and 90% of the time was wasted. But I've also worked at places where things were underbuilt (e.g 0 test environments whatsoever except prod). If there was a gun to my head, to finish something in 1 hour, I'd test in prod. So I think advice that sometimes is useful, sometimes is damaging, isn't really helpful. Not unless there's an easy way to tell which situation is which.
- phildawes 2y agoI think the exercise is more about exposing you to other solution options (to 'break your anchoring bias'). You still have to exercise judgement as to which solution is right for the situation.
- bckr 2y agoHow about “building is on fire” or “company is dead tomorrow”?
- aidos 2y ago> In practice, none of the day-long plans are actually a day. The gun isn't actually to your head. You can go home and sleep.
- Lws803 2y ago100% this should never be an excuse to push for a faster outcome. I have to admit though, as a personal mental exercise, this has saved me countless of hours from going down the rabbit hole of over-engineering. Some problems just need a simple solution, sometimes even without any changes to code.
- haliskerbas 2y agoat work? just shoot me then
- dclowd9901 2y agoSo glad someone’s here saying it. I am absolutely dreading tomorrow morning now with the thought our manager has also read this article.
- athrowaway3z 2y agoI mistakenly read your comment as "dreading tomorrow morning now that our thought-manager has also read this article" which I must have subconsciously decided was inline with the situation.
- hn_go_brrrrr 2y agoSounds like you need a different manager.
- probably_wrong 2y ago"Here, you have a gun to your head, you have to finish in 24 hours. What do you do?" "I set aside the slides for the pointless CEO presentation tomorrow and work exclusively on this." "No, you can't cancel on the CEO. Let's say you have two guns to your head and 24 hours, what do you do?" "I take lots of coffee, skip sleeping tonight, cancel the group status meeting for Wednesday and focus on these two things." "If you do that we'll look bad in front of the whole group. Let's say you have three guns to your head..."
- richk449 2y agoAnyone have a reference to this technique? I’d like to learn more.
- mempko 2y ago"Write everything twice" is a great heuristic. Extreme programming and unit tests is a dumb and wasteful technique. You end up cornering yourself.
- nkozyra 2y agoSorry, are you saying unit testing is dumb? Not that you'd be the first to say such a thing, but I've never really understood this if people find them valuable. 100% test coverage is one thing, but having some interdependent functions that do one small thing is a perfect use case for unit tests.
- mempko 2y agoUnit tests are a waste of time. Design by Contract + system tests are a far superior technique that take less time and find more bugs.
- dataflow 2y agoConfused, how do you ensure that a change to your implementation of some function isn't going to break clients after deployment if you don't have a unit test?
- mempko 2y agoThe client doesn't run your unit tests, but will run you contracts (because contracts deploy with you software while unit tests dont). You might have realized users of software do things the engineers don't expect, which are not covered in unit tests.
- dataflow 2y ago> The client doesn't run your unit tests That's kinda the whole point... you run them to catch bugs and fix them so your clients never see the bugs you caught in the first place. > but will run you contracts (because contracts deploy with you software while unit tests dont). So you'd prefer your contracts to blow up your bugs in your clients' faces, rather than catch bugs yourself prior to releasing the code to them?!
- nkozyra 2y agoWrite everything (generally, new features) twice has turned out to be really good strategy for me, but it doesn't sit well with bizdev or project managers and tends to be perceived as unnecessary slowness. But if you plow through a feature and get it "working," you'll do much of that work cleaning up the logic and refactoring through your first pass. What rewriting allows you to do is crystalize the logic flow you developed the first time and start cherry-picking in a more linear fashion to meet the blueprint. It also tends to reduce the urge (/ need) for larger scale refactorings later on.
- andsoitis 2y agoA project manager or bizdev person writes, rewrites, and rewrites again the document they produce do they not? Or do they write the perfect document at first go?
- stanac 2y agoWorst kind of jira ticket is just a link to a document that can be edited anytime. In that case I just replace the link with a new link pointing to the fixed version of the document and inform the author of the ticket/document about it.
- throwaway87483 2y agoDepending on what kind of document it is, I often resort to extracting its contents with pandoc by converting it into markdown, and then replacing the original description. Makes search work properly too.
- bdw5204 2y agoIf I'm writing something, I'm writing it once. That "prewriting" stuff they teach in schools just slows down the process and makes you overthink your choice of words. I take the same "1 take" approach with code with the idea being to write the best solution on the first try. Why waste time writing something bad just so you can fix it later? That doesn't make any sense. As I'm writing, I do go back and make changes as they pop into my head. But once I'm done writing it, I'm done unless I notice an obvious mistake after the fact.
- jesse__ 2y agoThis is one of the best "programming advice" posts I've ever read, right up there with the grug brained developer.
- 201984 2y agoNot sure why this was downvoted?
- jesse__ 2y agoSurprised me too..
- gamegoblin 2y agoI appreciated the comment (author here)
- BoiledCabbage 2y agoLikely most people don't know what you're referring to and assumed you thought the advice was bad.
- halfcat 2y agohttps://grugbrain.dev/ https://grugbrain.dev/ for those not familiar, by the creator of HTMX
- a1o 2y ago> Write everything twice There's an enhancement in a software I use/maintain that I wrote once and lost (the PC I wrote kaput and I was writing offline so I also didn't backup). It was an entire weekend of coding that I got very in the zone and happily coded. After I lost that piece of code I never could get the will to write that code again. Whenever I try to start that specific enhancement I get distracted and can't focus because I also can't remember the approach I took to get that working and get lazy to figure it out again how that was done. It's been two years now.
- mgaunard 2y agoThat's a good point. Particularly good pieces of work are hard to rewrite. I remember rewriting some piece of infrastructure once when I moved to another job, but I failed to summon the energy to rewrite it a second time at another job.
- AlotOfReading 2y agoEvery time I've pushed through that feeling and rewritten it anyway, the end result was better than the original. The memories eventually come back once I get into the problem and hindsight makes clear how much stuff past-me missed.
- HappMacDonald 2y agoEspecially in cases where its a project that got derailed or interrupted and I have to start over, the biggest problem for me is inability to concentrate the second time largely from overwhelming and vertiginous deja vu. Namely, at any given moment my memories of doing the same thing before interfere with my current reality of trying to do it again like intrusive thought microphone feedback.
- Etheryte 2y agoI really like the footnote that indirectly says that sometimes you just need to spin up a background thread to figure something out. Resonates heavily with my experience, to the point where I feel like a lot of the value my experience brings is identifying this class of problems faster. You stumble onto it, recognize it's the think about it passively type and move on to other things in the meanwhile. It would be easy to bang your head on it and get nowhere, sometimes you just need to let it sit for a bit.
- mgaunard 2y agoMost software has a finite lifetime of a few years. You rewrite everything eventually. What you should be worried about is the code that hasn't been rewritten in ten years.
- spc476 2y agoMy blogging engine [1] is almost 25 years old now. Have I rewritten it? If by "rewritten" you mean "from scratch", then no. I haven't. It has, however, seen several serious workings and refactorings over the years (the last great one was the removal of all global variables [2] a few years ago). Starting over would have been just too much work. [1] https://github.com/spc476/mod_blog https://github.com/spc476/mod_blog [2] As therapy for stuff going on at work.
- snapcaster 2y agoWeird, i would actually have the opposite conclusion. Can you say more? >What you should be worried about is the code that hasn't been rewritten in ten years. Why would I worry? it's been running for 10 years without significant changes. Isn't that a sign it's more or less accomplishing its purpose?
- HappMacDonald 2y agoWell, there's bitrot. Needs shift. Expectations shift. The foundations that the code relies upon shift. And familiarity with how things actually work inside of the black box evaporates leaving things distressingly fragile when the foundation finally gives way. It's like when an old dam has "stood the test of time". More and more people (and business practices) wind up naively circle their wagons around presuming it will remain in operation forever and the consequences of what will happen when it finally does fail add up faster than unchecked credit card debt.
- mgaunard 2y agoThe people that wrote it probably moved on, so ownership and fit must be weak.
- justinl33 2y ago> start over each day This reminds me of "spaced repetition" in learning theory. Drilling the same problem from scratch is a great way to get better at iterating through your rolodex of mental models, but so many people prioritize breadth because they think it is the only way to generalize to new problems.
- rmnclmnt 2y ago> Write everything twice I’d say « Write everything three times » because it usually take 3 versions to get it right: first is under-engineered, second is over-engineered and third is hopefully just-right-engineering
- passion__desire 2y agoDamped oscillation, approaching the right value?
- steve918 2y agoI like the "gun to the head" heuristic but I would probably rephrase it to be something like "If you only had 24hrs to solve this or the world would come to an end".
- hintymad 2y agoI remember seeing somewhere a popular list of top 10 algorithms used in systems, and it's kinda depressing to realize that the most recent algorithm on the list, Skip List, was invented roughly 30 years ago, and every single one of them was taught in an introductory data structure course. That is, we most likely do not need to study the internals of algorithms nor need to implement them in production. For such a long time in history, smart and selfless engineers already encapsulated the algorithms into well abstracted and highly optimized libraries and frameworks. Of course, there are exceptions. ClickHouse implemented dozens of variations of HashTable just to squeeze out as much performance as possible. The algorithms used in ClickHouse came from many recent papers that are heavy and deep on math, which few people could even understand. That said, that's just exception instead of norm. Don't get me wrong. Having a stable list of algorithms is arguably a hallmark of modern civilization and everyone benefits from it. It's just that I started studying CS in the early 2000s, and at that time we still studied Knuth because knowing algorithms in-depth was still a core advantage to ordinary programmers like me.
- smusamashah 2y agoDid you read the article?
- hintymad 2y agoYou're right. I rushed and assumed. Thanks
- layer8 2y agoThis reminds me of https://ntietz.com/blog/throw-away-your-first-draft/ https://ntietz.com/blog/throw-away-your-first-draft/, previously discussed in https://news.ycombinator.com/item?id=37003910 https://news.ycombinator.com/item?id=37003910.
- pkoird 2y agoA good code, in my opinion, is written by appropriate selection of suitably contained abstractions. The problem with this, and the article does try to talk about it, is that for you to select appropriate abstractions, you need to know the "entire" thing. Which is to say, you need to have a knowledge of something that isn't there yet. In other engineering disciplines like say civil or architecture, this problem is solved by using a good blueprinting paradigm like CAD layouts, but I find a distinct lack of this in software[1]. Ergo this advice which is a rephrasing of "know first and build later". But it is also equally easy to lose oneself in what's called an analysis paralysis i.e. get stuck in finding the best design instead of implementing a modest one. In the end, this is what experience brings to table I suppose, balance. [1]closest I can think of are various design diagrams like the class diagrams etc.
- ww520 2y agoI usually won't rewrite the whole thing twice, but would rewrite parts of it multiple times. For the very least, the second time around I would format things and add comments to make things easier to be understood. Code should be written for comprehension.
- halfcat 2y agoDan Abramov talks about WET (write everything twice) [1] as generally a good approach, primarily because you often don’t know the right abstraction up front, and a wrong abstraction is way worse than a copy/paste. He has some good visuals that illustrate how incorrectly dependent and impossible to unwind wrong abstractions can become. [1] https://youtu.be/17KCHwOwgms https://youtu.be/17KCHwOwgms
- aleph_minus_one 2y ago> Another heuristic I've used is to ask someone to come up with a solution to a problem. Maybe they say it'll take 4 weeks to implement. Then I say "gun to your head, you have to finish in 24 hours, what do you do?" Pretend to be capable of doing this, and in the short moment where the other person is not attentive, get the gun and kill him/her. This satisfies the stated criteria: > The purpose here is to break their frame and their anchoring bias. If you've just said something will take a month, doing it in a day must require a radically different solution. > The purpose of the thought experiment isn't to generate the real solution. :-) --- Lesson learned from this: if you can't solve the problem that the manager asks you for, a solution is to kill the manager (of course you should plan this murder carefully so that you don't become a suspect). :-) :-) :-)
- vanjajaja1 2y ago> If, after a few days, you can't actually implement the feature, think of what groundwork, infrastructure, or refactoring would need to be done to enable it. Use this method to implement that, then come back to the feature really good, this is key. building a 'vocabulary' of tools and sticking to it will keep your velocity high. many big techs lose momentum because they dont
- physicles 2y agoAgreed. I've also heard this stated as: > for each desired change, make the change easy (warning: this may be hard), then make the easy change" (earliest source I could find is @KentBeck on X) I love the idea of that vocabulary of tools and libraries, too. I strongly resist attempts to add to or complicate it unnecessarily.
- simpaticoder 2y agoVery interesting suggestions, all worth trying. Having a very capable coworker can help here, because they can show you what can be done in a short amount of time. Specifically I've noticed that some devs get "winded" by a change and want to take a break before moving on; others simply continue. This ability can be improved with practice, both within and across contexts. Doing things quickly is valuable for many intrinsic reasons that are often overlooked because we descry the poor extrinsic reasons. As with car repair, the odds that you forget how to reassemble the car scales with the time the repair takes. Similarly, if you can execute a feature in a day (especially a complex one that requires changes to many parts of a repo, and/or more than one repo) this is much less risky than taking many days or weeks. (To get there requires that you have firm command of your toolset in the same way a mechanic understands his tools, or a musician understands her instrument. It also requires that externalities be systematically smooth - I'm thinking particularly of a reliable, locally repeatable, fast CI/CD process.) (The calculus here is a little different when you are doing something truly novel, as long periods of downtime are required for your brain to understand how the solution and the boundary conditions affect each other. But for creating variations of a known solution to known boundary conditions, speed is essential.)
- DrScientist 2y agoI find the follow approach quite useful. 1. First write down a bunch of idea of how I might tackle the problem - includes lists of stuff that I might need to find out. 2. Look at ways I break the task down to 'complete-able in a session'. 3. Implement, in a way the code is always 'working' at the end of session. 4. Always do a brain dump into a comment/readme at the end of the session - to make it easy to get going again.
- gregors 2y ago"you have 24 hrs" and "write everything twice" ......they go hand in hand don't they? You're definitely going to rewrite it if you slap code out there.