in reply to Re: Re: Re: Re: Re: Re: Re: A Perl aptitude test
in thread A Perl aptitude test
First of all you suggest that your response is partly because you feel that I am criticizing a kind of person that you feel you are. This always complicates things. Please don't take my comments as personal criticism, but rather as explaining an important trade-off which is going to be made somehow, both of whose sides have advantages and costs. To me being aware of this kind of issue allows me to learn to use the most complex system around me - my co-workers - to the greatest extent possible. The technical tools are less than half the battle.
The trade-off in question is between the advantages of being able to use subtle tricks for the programmer's convenience, versus the costs of maintaining the code which use those tricks. As usually happens in real life, this is not a trade-off which has a clearly right answer about where to draw it. You ask where to "draw the line". And my answer is that it is situation dependent. In practice what I tend to do is think hard about the problem and then decide what "bright lines" I think I can draw which are appropriate for the situation, then draw them and do not cross without specific reason. And by "bright line" I mean a line which is very easy to recognize, and hopefully is not too far off from what I think is optimal in the situation. (BTW I got the phrase "bright line" from a couple of lawyers...) But in different situations I draw different lines.
OK, so what are the signs that I use to say when someone is overusing tricks? Well I think it is fair to say that if a programmer has difficulty reading the code that they wrote 6 weeks ago because they don't remember the tricks used, then it is obvious that they are pushing language features more than they are ready for. Ditto if the programmer went out of his way just to use a cool trick. I also lean towards saying that anyone who can't clearly explain the subtle possible gotchas in a technique shouldn't be blithely using it. (I tend to be the person who sorts out what happens when they get bitten by the gotcha...and those just aren't fun bugs to track down and explain.) And if you have other people who have to back them up on the code constantly wondering how something could possibly work, then you have a problem of some sort (possibly more education needed on one side, possibly less trickery on the other *).
Going the other way, if a programmer is finding themselves constantly hampered because they cannot organize code in useful ways, then that is a sign that you want to enable more features. I am less sympathetic to tricks that save a line or two here or there. I am much less sympathetic still to tricks that only enable marginal optimizations. (Premature optimization is the root of all evil...) OTOH I am very sympathetic to someone who wants to be able to write modules, use OO design, or throw around hashes of anonymous functions. I become even more so if the feature is one that will be used constantly, meaning that the effort of teaching other people can be amortized over more code.
You can see one decision that I have made in real life based on this at Re: Re: Re: Hash sorting. My attitude is that the amount that I need to teach to be happy with
is not really worth it when for complex code I can just do:while (my ($k, $v) = each %foo) { ... }
and not have to worry about someone forgetting the subtle gotchas with the more efficient idiom. However I have found it worthwhile to teach the mindset from which it is perfectly understandable to write:foreach my $k (keys %foo) { my $v = $foo{$k}; ... }
though I might actually write that as...print join ",", map { &{$field_info{$_}{format}}($deal) } @fields; print "\n";
The reason that I treat the two idioms differently? The latter enables me to organize the overall program differently - big win - and once the mindset is understood it is easy to remember why it works. The former saves a line or two and avoids an unnecessary copy - small win - and having learned the trick, if you go away from Perl for a while it is easy to forget important facts about it.my @field_subs = map {$field_info{$_}{format}} @fields; # time passes.. print join ",", map $_->($deal), @field_subs; print "\n";
Plus the latter idea can be taken and used in languages like JavaScript or Python. The context-specific coding trick cannot. More bang for the buck.
Follow-up nodes with more on this issue that you might want to look at: Why I like functional programming (explains the map trick above), Re (tilly) 1: Teaching Perl Idioms (says what subset I last used), Re (tilly) 1: to perl or not to perl (suggested subset for writing Perl for Perl beginners), RE: RE: Shot myself in the foot with a pos (me having this argument with chip and RE (2): Filehandle Filter (I am not choosing out of not having learned more than I use). The trade-off that I am talking about between how much you have to keep in mind while programming and the utility of keeping it in mind reminds me of my thoughts about global variables (in obvious and disguised forms) at Pass by reference vs globals. More general context on my attitudes towards learning can be found at The path to mastery and Re (tilly) 1: Discipline.
* Note that I don't always say that the first programmer needs to use fewer tricks, that is as wrong as saying that every programmer should learn every possible technique before they do anything. Hopefully this answers your question about whether causing confusion in others makes something a candidate for the "proscribed list". Well, you should think about it. But it is just as likely that you will instead decide that "people around here should understand that", and think about what you can do to make sure that people are at the desired competence level.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Re: Re: Re: Re: Re: Re: Re: A Perl aptitude test
by BrowserUk (Patriarch) on May 14, 2003 at 03:10 UTC | |
by tilly (Archbishop) on Jun 28, 2003 at 00:22 UTC |