Ask HN: Do you use programming tricks in real life too?
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 ] threadThat's something I do all the time in real life.
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.
That sounds a lot like query caching!
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:
(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:
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.
Sorting
Exception handling the wife (sorry honey if you read this)
Loop unrolling
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?
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.
It was more about the problem of matching socks when I put them away, but the same principle applies.
(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.
http://news.ycombinator.com/item?id=1695794
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. ;)
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.)
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 ;)
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".
If you don't know this, you shouldn't be on hacker news.
"Delegate completely, verify periodically - and slowly build up trust when good results are repeatedly shown" is more like it.
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 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.
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?).
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 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 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...