You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Jeff <ja...@aquabolt.com> on 2002/11/02 13:13:19 UTC

RE: [OT]: In my Farthers House there are many mansions

> -----Original Message-----
> From: Perrin Harkins [mailto:perrin@elem.com] 
> Sent: 01 November 2002 18:43
> To: Tony Bowden
> Cc: modperl@perl.apache.org
> Subject: Re: [O] Re: Yahoo is moving to PHP ??
> 
> 
> Tony Bowden wrote:
> 
> >It sounds like you're saying that you should only use a 
> subset of Perl
> >as some programmers may not understand the other parts of it?
> >
> 
> That is what I'm saying.  I'm aware that this is a controversial 
> opinion in the Perl world.  However, I think it's reasonable to 
> know your audience and write for them.  That's the good part of 
> More Than One Way. 
> The New York Times writes their articles for a certain reading 
> level, and I do the same with my code.
> 
snip...
> - Perrin
> 
> 

Have to agree 100% with Perrin - in my experience, refactoring for 
performance is often used as an excuse for 'rewrite in my style',
and at this point, future maintainability is usually severly 
compromised. Someone decides to replace all foreach loops with map,
because this is more advanced and kewl.

Does anyone else here remember the COBOL construct ALTER GOTO? I knew
a chap who styled himself 'Super Hot Software Systems', whose favourite
thing was ALTER GOTO - mmmm he soon got told where to go to! Look it 
up - it's a nightmare.

Another time, a contractor working for me complained bitterly about
someone elses obtuse code and lack of comments - the other party 
said 'Why don't you scroll up?', which he did - lo and behold, about 
two pages of beautiful comment. Mmmm as he read the comments, from 
the top, the complainant highlighted each line [easier to read] and 
when he understood the point of it all, pressed Enter - not 
realising that this replaced two screens of comment with an empty 
line... ah ha! we finally figured out the answer to the song:
'Where have all the comments gone?'

8-)


Re: [OT]: In my Farthers House there are many mansions

Posted by Les Mikesell <le...@attbi.com>.
From: "Jeff" <ja...@aquabolt.com>

> Another time, a contractor working for me complained bitterly about
> someone elses obtuse code and lack of comments - the other party 
> said 'Why don't you scroll up?', which he did - lo and behold, about 
> two pages of beautiful comment. Mmmm as he read the comments, from 
> the top, the complainant highlighted each line [easier to read] and 
> when he understood the point of it all, pressed Enter - not 
> realising that this replaced two screens of comment with an empty 
> line... ah ha! we finally figured out the answer to the song:
> 'Where have all the comments gone?'

Good story - and a good tie-in to the other off-topic thread about
whether on not it is worth the trouble to use CVS.  If you make sure
that the only way to get between your workspaces and the test/production
servers is a commit/update step, cvsweb can always provide a color-coded
answer to questions like that.

---
  Les Mikesell
    lesmikesell@attbi.com



Re: [OT]: In my Farthers House there are many mansions

Posted by "Randal L. Schwartz" <me...@stonehenge.com>.
>>>>> "Tony" == Tony Bowden <to...@kasei.com> writes:

Tony> We're drifting further and further off topic here, but the trick to the 
Tony> Schwartzian Transform is the caching, not the maps. The maps are just a
Tony> convenient construct that allows the whole thing to be written in one
Tony> command, without lots of temporary variables. 

Exactly.  You're caching the complex sort-function so that it
doesn't need to be recomputed for the various pairings, leading
to either a slowdown or phase errors.

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<me...@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!

Re: [OT]: In my Farthers House there are many mansions

Posted by Tony Bowden <to...@kasei.com>.
On Sun, Nov 03, 2002 at 11:48:55AM -0600, Steven Lembark wrote:
> >I'm not sure anyone has actually posited using map for performance, but
> >in most cases that would indeed be a pretty stupid reason to use it.
> See the Schwartzian Transform for an excellent example of
> where you would use map for performance. 

We're drifting further and further off topic here, but the trick to the 
Schwartzian Transform is the caching, not the maps. The maps are just a
convenient construct that allows the whole thing to be written in one
command, without lots of temporary variables. 

In terms of speed, the difference between

  my @sorted = 
    map  { $_->[0] } 
    sort { $a->[1] <=> $b->[1] } 
    map  { [$_, -M $_] } @files;

and

  my @cache; push @cache, [$_, -M $_] foreach @files;
  my @sorted_cache = sort { $a->[1] <=> $b->[1] } @cache;
  my @sorted; push @sorted, $_->[0] foreach @sorted_cache;

is quite neglible compared with the speed difference of doing

  my @sorted = sort { -M $a <=> -M $b } @files

especially as the cost of the operation (-M in this case) increases.


Tony



Re: [OT]: In my Farthers House there are many mansions

Posted by Steven Lembark <le...@wrkhors.com>.

-- Tony Bowden <to...@kasei.com>

> On Sat, Nov 02, 2002 at 12:13:19PM -0000, Jeff wrote:
>>>> It sounds like you're saying that you should only use a subset of Perl
>>>> as some programmers may not understand the other parts of it?
>
>>> That is what I'm saying.  I'm aware that this is a controversial
>>> opinion in the Perl world.  However, I think it's reasonable to
>>> know your audience and write for them.
>
>> Have to agree 100% with Perrin - in my experience, refactoring for
>> performance is often used as an excuse for 'rewrite in my style',
>
> I'm not sure anyone has actually posited using map for performance, but
> in most cases that would indeed be a pretty stupid reason to use it.

See the Schwartzian Transform for an excellent example of
where you would use map for performance. Main advantage is
getting perl to manage the list space. If I find myself
writing for(blah){ push @foo, something } it can usually be
done more simply via @foo = map { something } ( blah ). If
you end up making large lists, especially in loops, then map
can be a speedup. It is also faster if you have to flatten
out strucures frequently (vs iterating over keys %foo and
assigning things one at a time).

map can also be convienent in allowing for lexicals that
are assigned when they are built, similarly grep:

	if( my @process_this = grep {-s > $cutoff} @filz )
	{
		deal with @process_this here, know it won't
		outlive the braces.
	}

Defining the lexicals in a scope where the don't outlive
their purose can be a big help in maintainability.

--
Steven Lembark                               2930 W. Palmer
Workhorse Computing                       Chicago, IL 60647
                                            +1 800 762 1582

Re: [OT]: In my Farthers House there are many mansions

Posted by Tony Bowden <to...@kasei.com>.
On Sat, Nov 02, 2002 at 12:13:19PM -0000, Jeff wrote:
>>>It sounds like you're saying that you should only use a subset of Perl
>>>as some programmers may not understand the other parts of it?

>> That is what I'm saying.  I'm aware that this is a controversial 
>> opinion in the Perl world.  However, I think it's reasonable to 
>> know your audience and write for them.  

> Have to agree 100% with Perrin - in my experience, refactoring for
> performance is often used as an excuse for 'rewrite in my style',

I'm not sure anyone has actually posited using map for performance, but 
in most cases that would indeed be a pretty stupid reason to use it.

> and at this point, future maintainability is usually severly
> compromised. Someone decides to replace all foreach loops with map,
> because this is more advanced and kewl.

Automatically replacing all 'foreach' loops with maps would also be
pretty stupid.  They're different thing, used for different purposes.

But using a foreach when you should be using a map is no better.

When someone misuses something, the wrong approach is to no longer use
it.

The correct approach is to educate people on the correct use.

Tony