Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

Re: The first cargo cults

by talexb (Canon)
on Jan 11, 2002 at 19:19 UTC ( #138024=note: print w/replies, xml ) Need Help??

in reply to The first cargo cults

That's a fascinating peek at history. Where was all this great stuff in high school?

To go left-brained for a minute, copying and pasting can be a good thing if it means you're not "re-inventing the wheel" to quote a popular phrase from one of the monks. I would hasten to add that the utility of cutting and pasting varies indirectly with the size of the piece of code involved.

If it's ten lines that you want to re-use, but the second use is different enough that it doesn't make sense to build a common subroutine, go ahead. If it's 80 lines from someone else's script, but you're not sure how it works (and what're all these modules!), that's cargo cult.

The corollary to that is, if you're doing a lot of copying and pasting while writing a script or a module, you should really stop yourself and ask why. Couldn't that be put into a subroutine? Are you sure? Really, really sure?

--t. alex

"Excellent. Release the hounds." -- Monty Burns.

Replies are listed 'Best First'.
Re(2): The first cargo cults
by FoxtrotUniform (Prior) on Jan 11, 2002 at 21:21 UTC

    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.

      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.)

Re: Re: The first cargo cults
by jepri (Parson) on Jan 11, 2002 at 19:44 UTC
    That's a fascinating peek at history. Where was all this great stuff in high school?

    Almost by definition, the people who teach science are the people who (didn't want to go it|couldn't cut it) in research, thus making them ill equipped to teach the important things about research. Many of the good researchers I have talked to resented having to give lectures because lectures take away from research time (you may only see one hour of class, but it takes three or four hours to prepare, not counting marking homework). Feyman was a good researcher who was different enough to enjoy teaching too.

    Of course I should shut up now, since I'm not yet doing research, but I've researched doing research, if that makes sense. I have however noticed that the quality of a teacher can be enough to drive an entire class of people away from a subject, or to pack a lecture hall for a subject - even among third-year students.

    If it's ten lines that you want to re-use, but the second use is different enough that it doesn't make sense to build a common subroutine, go ahead.

    I can't think of a situation where this would happen. I suspect you mean that the in the second use the code is likely to diverge from the first over time, so factoring the ten lines in a subroutine would end up with lots of conditionals in the routing to deal with changing circumstances. In that case, definately don't factor.

    It has been pointed out that typeing use CGI is as much cargo cult as rolling your own, but that's not quite true. Using a module is like buying a manufactured product, like a plane. Rolling a quickie is like trying to make one from scratch is inherently dodgy, like trying to make a plane of of bamboo and get it flying. It worked for Daedelus, kinda, but it's not a good way to do it for production code.

    I didn't believe in evil until I dated it.

      Sorry, but you just hit a pet peeve.

      I likewise have talked to many good researchers who hated to teach. And when I have sat in their classes I have found that their students quite rightly disliked being taught by them as much as they disliked teaching.

      Teaching well and doing quality research are different skills. Setting good researchers in front of classes does not result in good teaching. Making researchers teach classes without quality feedback while rewarding them almost entirely for their research results in dreadful teaching.

      One of my favorite books is about exactly this. It focusses on math education, and explains why the state of math education at the college level is so dreadful. (The problems there tend to trickle down, but that is another story.) And it isn't just a rant, it is accurate, and the more you know the more you can recognize that accuracy. I have seen mathematicians say, in all seriousness, "That book is my biography."

      And, as I just found out from Google, this book is available online! Why the Professor Can't Teach by Morris Kline. The next time you see someone suggesting that ability at research is a good qualification for teaching, I suggest handing them this link.

      (An incidental note. The author, Morris Kline, was both respected as a researcher and an educator.)


      You wrote:

      Almost by definition, the people who teach science are the people who (didn't want to go it|couldn't cut it) in research

      That is probably true as a generalization, but I can certainly think of exceptions. I, for instance, think of myself as a good researcher, and very much enjoy teaching. I would happily teach at the high school or college level, but the sad truth is I can't afford it. I have a family and gigantic student loans to pay back, so I can't give up my good job in industry (which I also enjoy) to take a huge pay cut to teach. :-/ It says something very sad about our education system that I am in this situation.


        That was indeed terribly unfair of me, and I should have included a catagory for "does it for pleasure". I have had a couple of excellent teachers, and they were probably the thing that kept me in school. However I think we both have met the teachers I am referring to :(

        I'm sorry to hear you are trapped by your commitments, and I hope you manage to get some teaching in, because the best teachers I had were the people who came from industry or research.

        The whole education thing does seem weird, but nobody seem to have come up with some thing better.

        I didn't believe in evil until I dated it.

Re: Re: The first cargo cults
by toadi (Chaplain) on Jan 14, 2002 at 15:19 UTC
    I use modules on CPAN, some I have a had a peek in the see how they work. But some I didn't so I don't know how they work...

    So follolwing your explantion I'm doing cargo cult?

    My opinions may have changed,
    but not the fact that I am right

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://138024]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (4)
As of 2018-06-24 02:11 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (126 votes). Check out past polls.