Ask HN: Do you use programming tricks in real life too?

87 points by jacquesm ↗ HN
I suddenly realized that I'm practicing 'programming tricks' in real life all the time.

Specifically, the divide and conquer strategy for problem solving and building larger things out of smaller sub assemblies, but the more I think about the more I see that plenty of the stuff that I do on a day-to-day basis has it's roots in programming (or at least that's where I picked it up).

For instance, assume nothing, trust but verify, be strict in what you send but forgiving in what you receive and so on.

Those all have real-life equivalents for me.

Professional deformation or useful trait? Do you have it too ? In what way ?

90 comments

[ 2.8 ms ] story [ 152 ms ] thread
I'm currently binary searching to find the changelist that broke my project.
So what's taking so long?
I think the searching thread is blocked waiting for the cooperative HN-browsing thread to return control.
I've seen people use exceptions for flow control: rather than constantly checking if it's OK to keep doing something, just keeping doing it until there's a problem, handle it, then gracefully stop.

That's something I do all the time in real life.

similar here. this pattern reminds me also of "better to ask forgiveness than permission" in order to maximize productivity. Just Do It. alter/correct/stop later if/as needed.
That's an idea that I explicitly learned from computing, coming from a mathematical background where that pattern doesn't really have an analogue. I really never thought that way until I conceived of it as an adult and immediately connected it to some code I had written recently. The closest pattern of thinking I had prior to that was the idea of the scientific method, which isn't exactly the same and isn't nearly as applicable to problems in daily life.
Are you kidding? I use the scientific method quite consciously all the time. Form a hypothesis, try to come up with some relevant experiments, perform them, notice that they (usually) disconfirm the hypothesis, repeat until the hypothesis is not disconfirmed.
(comment deleted)
ooh, my wife hates that. I typically fix our cars myself when they break. When something starts making noise that I can't diagnose, I do everything I can to make it worse hoping it'll help me figure out the problem. Apparently, that's counter-intuitive.
My wife is far more analytical about most tasks than I am - I drive her crazy by not really being able to explain how I can fix most things, using a process she describes as "fiddling randomly until it works".
Your mechanic might hate that too. One difference between software and hardware is that you can't just revert the checkin that cracked your cylinder head when you were over-revving the engine to see if you could make the ping louder.
I do this, and I'm pretty glad to see I'm not the only one.

Applying query tuning techniques to my daily commute saves me about 10 minutes of driving each day. I recently realized that freeway lanes have similar performance characteristics as database tables do - the more transactional the lane, the more likely it's going to have a backlog. So, instead of driving in the fast lane, the one immediately to the right of it is usually faster. My guess is that this happens because of people swerving in and out of the HOV lane illegally in an attempt to save a few minutes or whatever. Avoiding the furthest 2 right lanes is important when you can as well as people tend to merge twice immediately after entering the freeway (this is on I-10 in Phoenix, which is between 4 and 7 lanes across each way, depending on what part of town you're in).

Knowing which lanes contain forced merges allows for planning ahead as well, since you know that you're going to have to deal with double the traffic in a rate-constricted channel.

Knowing which lanes contain forced merges allows for planning ahead as well, since you know that you're going to have to deal with double the traffic in a rate-constricted channel

That sounds a lot like query caching!

There cannot be more lane changes into and/or out of the left most lane than the 2nd to left most lane (assuming no left exits) because all lane changes go through it. Furthermore it is fairly easy to get a sense of the best lane by just paying attention.
In the UK people in the 'fast' lane (over taking on the inside is illegal here). Will generally leave less space between cars, so that lane is more likely to suffer from a cascade of over-breaking causing a jam.
Yes there can be, because people who hop in and out of the HOV lane don't traverse all lanes every time they do it.

For example, Alice gets on the freeway and merges 4 times (after the initial merge) to get to the "fast lane". For ease of explanation, the lanes will be referred to like this:

  | HOV | 5 | 4 | 3 | 2 | 1 | Onramp |
(So lane #5 is the fast lane in this example)

Traffic starts slowing down, so she merges from lane 5 to the HOV lane in order to pass a few cars. She's in this lane illegally so she doesn't remain in this lane. After a few passing a few cars, she merges back into lane 5. She repeats this 3 more times before she gets off the freeway.

So, in this limited example, this is the "transaction count" of Alice's lane changes:

  Onramp <-> Lane 1 : 2
  Lane 1 <-> Lane 2 : 2
  Lane 2 <-> Lane 3 : 2
  Lane 3 <-> Lane 4 : 2
  Lane 4 <-> Lane 5 : 2
  Lane 5 <-> HOV : 8
The problem isn't people just getting over to the fast lane, staying in it and leaving, the problem is the number of transactions that the HOV <-> Fast lane pairing have due to it being relatively empty even during crowded freeway conditions.

Similarly, lanes 1 and 2 have higher transactions due to people getting on the freeway for a mile or two and exiting shortly thereafter. This may be limited to AZ freeways since the exits tend to be regularly spaced about a mile apart. The other problem is that there are quite a few people who will merge on to lane 1 going 45MPH, which causes many drivers to pass them in Lane 2.

Chronic lane changers seem to use all lanes roughly equally, so their habits mostly cancel out.

Another thing that may be different depending on where you live is that AZ allows entry and exit from the HOV lane at any time. It's not like CA where there are specific entries and exits to the HOV lanes.

Let me know if this still doesn't make sense.

This still does not make sense

  Onramp <-> Lane 1 : 2
  Lane 1 <-> Lane 2 : 2
  Lane 2 <-> Lane 3 : 2
  Lane 3 <-> Lane 4 : 2
  Lane 4 <-> Lane 5 : 2
  Lane 5 <-> HOV : 8
So the total transactions for lane 5 is 10 and HOV is 8. This is not a counterexample to what I stated.
By "fast lane", I believe icey is refering to lane 5, not HOV. He is saying lane 4 is better than lane 5 because of all the people switching between land five and HOV. He's not saying that lane 5 is better than HOV.
I would say that those tricks you mentioned are real life skills I use in development.
I tend to "regression test" things. eg. after I clean the toaster, I plug it back in and pop it down to make sure it still works.
Sure thing:

Sorting

Exception handling the wife (sorry honey if you read this)

Loop unrolling

You do loop unrolling on purpose? I think loop unrolling is one of the disadvantages we have in real life.

I already made my bed, now can't you do it for me for d in days? It's the same every time! What's with all this premature optimization?

Oh sure I do, especially in cooking. Rather than just repeat the same procedure with cleanup and all, I do all of them then clean up, i.e. chopping peppers, shredding cheese, frying sausage, etc.
"When in doubt, use brute force."
From my blacksmithing days: "When in doubt, get a bigger hammer."
I use the Birthday Paradox when I'm searching for matching socks in the morning -- rather than pick a sock and look for one that matches it, I accumulate socks and choose the first pair that match.
That's an excellent metaphor!

My other favorite programming metaphor is about skiplists: they're like a set of subway lines, with some extra express lines that skip a random (and increasing, for each level) number of stops.

I use Lisp for that same purpose whenever I do my laundry. I cons my socks ahead of time, then serialize the pairs to a drawer. O(1) lookup FTW!
Quite possibly the geekiest hn comment I've read :)
I use the futon in my bedroom as an L1 cache for frequently worn clothes.
instead of casting other types, just make everything a string: buy a whole lot of pairs of the same type of sock so you don't have to worry about matching types!
Rather, you're using problem solving tricks in real life. If anything, programming often gives a good vocabulary for problem solving* , especially if you're not a mathematician, but it's not exactly the same. Programming works similar mental muscles, but can also encumber problems with meaningless details.

(Also, be wary of "be strict in what you send but forgiving in what you receive", it gets you web "standards". :) )

* No small thing, see e.g. Iverson's "Notation as a tool of thought". Having a good vocabulary for a problem is a great aid to brainstorming. The most recent wave of people discovering this have been buzzing about "DSLs". Before that, "little languages". Before that, I don't know.

You frequently see reference to "an algebra" or "a calculus" of something or the other :)
I used to work as sysadmin in a research institute. the language difference between researchers who program, vs your typical coder in a software shop was interesting. the researchers were in the habit of referring to "a code". to a programmer, its either "code" or "a piece of code", but never "a code". that would be like saying "a software". when I hear "a code", I think of "an error correcting code".
Yes, that usage ("a code", meaning a program) is actually quite old in the numerical modelling community -- I heard it in the early 1970s, and I think it's older than that.
Reverse engineering problem spaces in physical reality works just as well as it does in digital reality, case in point;

A few years ago I had a friend that was just about to learn the hard way that backing up their files was essential and what the click of death really meant, but this particular episode resulted in her collapsing onto the couch in her home and sobbing quietly.

Call me a softy but I can't deal well with people I care about in such a state so instead of the usual "That'll teach you, next time you ought to backup regularly" I suggested taking her drive to a data recovery specialist, however this was off the table due to cost concerns apparently and timeliness of data required from said device. This does of course exacerbate the original error of not keeping that data backed up, but I still felt the need to help her out.

So, I sat there and I thought about it for a very long time, reverse engineering the process of exactly what happens during a head crash on a hard disk platter, the head collides with the spinning platter causing physical damage to it and/or getting jammed on it and unable to reset.

Opening the drive and physically realigning the components required tools and an environment that I did not have access to, I did not have the spare parts to implement a platter switch out on a spare of the same model drive, and no clean room environment to do the job at any rate, so I thought if this were a simulation of reality and I could just magic it back like in software, how might I do that and got the image of lifting the head off the platter to reset it without opening the drive casing.

Thinking about it a bit longer made me come up with the crazy idea that the disk was constructed of metal, and metal contracts when cooled. Possibly this could result in the head being lifted off the platter for long enough for the disk spin up to realign the head if it was booted quickly after being cooled dramatically, but condensation would destroy the electronics on the drive and this would need to be accounted for.

It's kind of a crazy idea anyway and if the data is really critical and it could've been sent to a recovery specialist I would've recommended that but on hearing my idea she immediately begged me to do it. Apparently she had no idea what I was actually proposing beyond it involves the freezer and the disk or why it might work, but afterward she told me that I had that same cautiously optimistic vocal tone I get when I'm on the edge of a solved problem when we're working together and that was enough to convince her it was a surefire winner.

So, multiple freezer bags wrapping the drive and four hours later with said freezer on lowest temperature it was capable of, I quickly removed the drive, cut a hole in the outer bag that had not been covering the power and data connections, and put it into the system, spin up, no clicks. Rapidly booted into linux live CD and copied all the files off the drive, it kept running not only for the three hours necessary to do this, but apparently runs to this very day also (this was about three years ago).

She does however backup religiously now, and doesn't store anything critical on that drive anymore, and this incident was the genesis of a new dropbox customer. ;)

That's a good story, but it's about problem solving (informed by physics), not programming as such. Still cool, though.
I suppose it came to mind because to me it felt exactly like debugging.
Definitely. I'd bet a lot of good mechanics would have the knack for debugging, too, if they learned the programming stuff. (The bike shop mechanics I've known certainly have the mindset.)

Problem solving is more general than programming, that's all. I'm all for sharing good problem-solving strategies, but focusing on programming is a bit narrow. (I get a lot of inspiration from House and Berton Roueché's writing, personally, but I'm a medical history / epidemiology geek.)

Oh man, yeah. Debugging skills are totally real-life. Back when my son had an allergy/kidney problem (which he still has, but his labs have been normal twice now, fingers crossed) I always had the feeling I was debugging my child.
I don't buy that you came up with this well known hack on your own. Thanks for sharing this lie with us.
And why not? That's the whole idea behind patents on stuff that does not require years of research being nonsense.

I've come up with plenty of stuff off the cuff like the GP writes, sometimes it works, plenty of times it doesn't. I only brag about the times it worked ;)

And rightly so. Sports guys talk about various glory moments where pure luck or doing the wrong thing (according to the fundamentals) worked out well. Fishing stories are all... yeah..

Basically all groups have their lore. Everyone knows it contains an element of bragging, a lot of BS and some downright fabrication. It's not about fact reporting, its about bonding, it's about highlighting certain aspects to demonstrate traits valued in the group, it's about passing on a generalized knowledge. Hell, some places "shooting the shit" is called "telling lies with the boys".

(comment deleted)
I've done this multiple times and never once had anyone flinch at the idea... its just WHAT YOU DO when your hard drive is messed up as one of the steps.

If you don't know this, you shouldn't be on hacker news.

If this was really your idea first, thanks. I have used this technique to recover data. I didn't bag the drive though. I got the data off, and the disk lasted about 20 minutes before dying forever.
Minimizing context-switches and exploiting caching sure helps get housework done a lot faster and with less hassle (be it doing the dishes, sweeping the floor, doing laundry, or tidying up the place). Also sort-then-process (which can be n log n if processing is linear) is usually a lot faster than sort-as-you-go (which can easily go to n²).
premature optimization: rather than order and sort bills and receipts into separate folders, i just toss them into a big pile. why waste time on the INSERT when you SELECT from it so rarely?
Agreed -- my filing system became so much easier when I realized that reads were rare. Just bucket (well, box) by a suitable parameter, typically date, and you're done.
I like to try different sorting algorithms when sorting physical things. I tried patience sorting last time I had to sort a big pile of books (I was sorting by width).
Quicksorting a deck of cards is not actually that quick, oddly.
I don't like the phrase "trust but verify". I believe it gives the wrong idea of how to handle people you depend on to accomplish things.

"Delegate completely, verify periodically - and slowly build up trust when good results are repeatedly shown" is more like it.

Of course. I think Cesar picked up "divide and conquer" from his experience with COBOL.
I wonder what would have happened if Caesar had had access to modern problem solving tools.

After all, if he could come up with something that directly leads to recursion what would he have done on the algorithm front given a mechanism more suited to the development of more complex algorithms? Regular language only gets you so far in that respect.

I swear a lot.
1) I use non-blocking I/O all the time :

- I don't like to answer phone calls because I'm generally busy, I'd rather listen to my voicemail and call back people later.

- I don't wait for things to finish (eg. TV ad break) by staring at them, I do something else until they are done.

2) I also treat my life as a task queue :

- I will analyze what needs to be done and tackle each problem individually (GTD-like).

3) I have an object-oriented worldview :

- I'm careful to always pass in the right arguments to people's "methods".

- My very own existence is defined by a multiple iheritance from my mom and dad classes.

4) Finally, I tend to RTFM a bit too much before taking action IRL.

How about the idea that the best range specification is: position of first item in the range, position of first item just past the end of the range.

Programming examples: Python range function & slice notation, C++ STL ranges.

Real life example: A room is being renovated. It is unavailable starting on the 3rd, and available again starting on the 8th (as opposed to unavailable from the 3rd to the 7th -- how many days is that?).

I write software, but I consider myself, in a way, a professional scientist. I use the scientific method every day. I'm sure I work differently than pure researchers, but the gist of it is the same. Assume nothing, trust-but-verify means I make sure to have controls to compare my experiments against, and I repeat observations that others tell me they made. I form hypotheses and discard the ones that don't agree with observations until I find the one that explains the problem. Further testing and I've got a theory. Then I implement a solution. I'm much better at solving problems than I used to be, and that's a skill that's not limited to writing software. Unfortunately, I don't really do much else. If I had a life, I'm confident I would use my improved problem solving skills to solve real life problems.
This reminds me of a book on the work of Jean Piaget. Basically he tried to teach children to learn by teaching them programming.

Because programming provides you with the patterns of building up in chunks, testing each section independently.

If you look at alot of the revolutions in sports teaching it has come from breaking down movements via slow-mo replay and then being able to teach / debug those movements.

I would suspect that all programmers use the mental patterns from programming when faced with other tasks, but I'd be surprised if they would realize, I certainly don't.

I read a book by Focault in which he said similar things about the evolution of efficiency in the military. There was a correlation between the number of precise movements of the armies and its efficacy. This was before modern wars.
A/B testing on dates and on random women I've met in bars. No, really.
I am not sure what "real" means but, I use programming tricks in my non-programming job.

I make big and obvious the important things that I need to remember in a hurry. I hack away at removing stuff that isn't necessary.

I use a rough binary search from time to time. For example, if I'm looking for something in a collection of named documents I know are filed, but don't what the starting and ending documents are. This comes up from time to time.

I also use heuristics I've learned debugging - just about when to challenge assumptions, and detecting when part of my mind is trying to stick to assumptions it shouldn't. Difficult to explain precisely - sort of a 'self delusion alarm bell'.

I've also learned something about structuring debate and discussion, from programming - I sometimes keep a mental model of the discussion under progress as a stack - tangents result in a push, and I've sort of learned to 'pop' afterwards to go back to the part of discussion I'd otherwise forget.

Not sure this is so much programming tricks as a set of heuristics and mental faculties that have been trained or enhanced by programming...