http://www.perlmonks.org?node_id=138056


in reply to Re: The first cargo cults
in thread The first cargo cults

IMNSHO, it's not the size of the code you copy, or the code's generality, that distinguishes between sloppy, dangerous cargo-cult programming and legitimate re-use, but how well you understand the code. (Sure, it's almost always better to generalize the code you want to copy and modify, make it a subroutine, and solve a whole class of problems -- I refer you to Perl's genesis for prior art -- but that's not so much the point here.)

In The Pragmatic Programmer, Hunt and Thomas talk about code "wizards" -- programs which take a rough specification and generate an application framework. This is classic cargo-cult programming, if taken the wrong way: you have a complete MDI interface before you, but you have no idea of how, or why, it works. You just fill in the templates and hope you don't clobber anything important. Hunt and Thomas suggest that the way to make wizard use healthy is to understand the code that gets produced.

So it's understanding that makes the difference between laudable re-use and cargo-cult programming. If I understand the code that I'm copying in, I'm fine. If I don't understand the how, but the code's in a library (or a module) and I grok the interface, then I'm fine using the module. (If I open it up and copy a likely looking function out of it, then I'm probably hosed.) If I don't understand even one line of it, but I use it anyways, and try to make the rest of that line's context look like the last place I saw it, then I've fallen into cargo-cult programming, and I deserve everything I get.

--
:wq

Replies are listed 'Best First'.
Re^3: The first cargo cults
by Aristotle (Chancellor) on Jan 12, 2002 at 19:32 UTC
    FoxtrotUniform++++++++++++ (if I could, which is why I'm posting instead). There is a definite tendency towards wizards and blackboxes everywhere and I hate it.

      Heh. Flattery will get you nowhere. ;-)

      I'm not necessarily opposed to wizards and generated code (in fact, I'm writing a script to generate accessors for database code from an SQL file); what annoys me is the tendency to use wizard code without understanding what it does or what its possible consequences are. (That, and the horrific quality of most generated code.)

      --
      :wq

        Well exactly. It's not like I don't try to make life easier on myself, either. In fact I tend to write scripts for just about every task I may end up doing more than 2 or 3 times.

        What annoys me most is how most wizards don't even give me a chance to understand what they're doing. I tried to get into VC++ - but it generates such a wad of code for anything but the most unrealistically trivial projects that I gave up trying. I found myself annoyed at the "doubleclick SETUP.EXE" culture in Windows - sure it's convenient, but what does it do?

        Now I'm using Perl on Slackware Linux. All modules are available in generally not overly hard to read source. I build all the software I install from source and use checkinstall to keep track of what make install actually did.

        No, this is not an MS bashing - if others can arrange with Windows and companions more power to them, I couldn't, I hated the guts of the bunch. I understand that many people don't care about computers and want to just get stuff done with one and then get on with their lives. But I found the trend is to cater exclusively for that class of users.