News for hackers. Stuff that matters.
Re:What should every programmer know about programming? by jacquesm on Wednesday September 15, 2010 @03:48PM (#1695603)
If there would be only one thing that you would really have to know it would be divide and conquer, everything else follows from there. It allows you to tackle any size project and to solve problems that are too complicated at first glance.

It allows you to debug really tough bugs and keep moving.

The guy that taught me that trick was a long time COBOL programmer, he took pity on me after not being able to crack a certain problem and it was like someone handed me an electric drill after puttering about for years with a pocket knife.

Re:What should every programmer know about programming? by danilocampos on Wednesday September 15, 2010 @03:54PM (#1695626)
What would be an example of a successful application of this approach?
Re:What should every programmer know about programming? by jacquesm on Wednesday September 15, 2010 @04:04PM (#1695650)
When faced with a problem too large to solve divide it in to two roughly equal halves.

Pick the first half of the two and see if you can solve it.

If not recurse with the first half, else solve it.

Now look at the other half and see if you can solve it.

if not recurse with the second half, otherwise solve it.

For debugging it mostly relates to chopping up the program in to bits that are 'verified good' and 'unsure', until you are literally staring at the bug.

Some sort/search algorithms are an almost literal implementation of divide-and-conquer.

edit: the more I think about this the more I realize that this has pervaded in to just about everything that I do. I'm currently rebuilding a car that has crashed and I find I use divide and conquer to troubleshoot and to repair. Tomorrow I'll be puling the engine to replace a cracked gearbox casing and for sure I'll use it again, both to remove the engine, to remove and replace the gearbox and to put the whole thing back together again, one small 'obvious' step at a time.

edit2: see also: http://news.ycombinator.com/item?id=1695794

Re:What should every programmer know about programming? by varjag on Wednesday September 15, 2010 @05:11PM (#1695860)
> For debugging it mostly relates to chopping up the program in to bits that are 'verified good' and 'unsure', until you are literally staring at the bug.

It should be noted there's a whole class of bugs where divide and conquer simply doesn't work. E.g. about anything with race condition.

Good points otherwise.

Re:What should every programmer know about programming? by jacquesm on Wednesday September 15, 2010 @05:14PM (#1695870)
True enough, and interrupt driven programs tend to exhibit very nasty ones as well where that strategy does not work.

It's not a 100% silver bullet but it will get you quite far.

Re:What should every programmer know about programming? by achompas on Thursday September 16, 2010 @12:52PM (#1698331)
Excellent suggestion. This open course lecture from MIT has more, for those who want an example or two:

http://ocw.mit.edu/courses/electrical-engineering-and-comput...

Re:What should every programmer know about programming? by brown9-2 on Wednesday September 15, 2010 @04:19PM (#1695705)
MapReduce