[Israel.pm] What does this code do? (No. 2)

Shlomi Fish shlomif at iglu.org.il
Tue Jun 22 12:29:24 PDT 2004


On Tuesday 22 June 2004 22:20, Eli Billauer wrote:
> I tell you what the code does: It disgraces the language. While Perl
> golf is a matter of taste, this piece of shitty code is something I
> would never want anyone to see. 

I don't know if it "disgraces" the language, but I agree it is not very 
Perlish. I explicitly stated that I originally wrote it in C, and then 
translated it to Perl. The entire point of this exercise is so people will 
understand what it does, and try to re-write it better.

> It makes the Perl language look
> ridiculous as if it was something like a distorted and slower version of C.
>

You are allowed to write C-like code in Perl, and sometimes you even have to, 
because the built-in mechanisms don't give you what you need. You can't do 
everything with regexps, at least not always efficiently.

> Anyone who knows Perl, and will care to read that idiotic piece of code,
> will soon realize that it can be written in one or two lines of real
> Perl. 

You are right. It _can_ be written in a few lines of Perl.

> But this is something I wouldn't like "the children to see". And 
> mind you, there are children around (newbies, I mean, of course).
>

While it is not example of the right way to do things in Perl, it is still 
something that we can show newbies, at least as something not to do. I 
believe knowledge of the C language is something every programmer needs to 
acquire after a while. So why do you think a C-like Perl program, and 
especially one that was given as an exercise in understanding code, and not 
as a model for good or efficient way of doing things, is something newbies 
are not allowed to see?

> I've never liked the way you presented Perl in your "Perl language
> course", 

It is possible my "Perl for Perl Newbies" lecture series, could use some 
rework. What do you find wrong with it?

> and neither do I think that you ever grasped the sting about 
> it, 

What makes you think so? (note that this particular example is not a prime 
example of my Perl programming, nor was intended as such).

> as well as other languages that you've managed to present in a 
> disgraceful way (Haskell, for example). But this was really too much!
>
> Keep in mind that everything written in this mailing list is archieved
> and googled, and may be used as a reference for programming. The example
> you've shown is exactly what is going to appeal to a typical C
> programmer, and it's sooooo totally wrong!
>

I realize that. However, it was labeled as an exercise in understanding code, 
and I explictly stated that it was written in C and converted to Perl, and 
that it is possible to write a more Perlish version. I didn't even note what 
it does in that context, so I don't expect people to copy and paste it into 
their programs. (much less find it in interesting Google searches)

So far, three people have replied, with their take at understanding what the 
program does and more Perlish versions. Through their programs I was able to 
find bugs in their versions, bug in my Perl versions, overlooks of the 
test-suite, and also learned some new things about Perl. So, in my opinion it 
was a success, and I'll post a summary and conclusions of it after a week 
passes. 

Regards,

	Shlomi Fish

-- 

---------------------------------------------------------------------
Shlomi Fish      shlomif at iglu.org.il
Homepage:        http://shlomif.il.eu.org/

Knuth is not God! It took him two days to build the Roman Empire.



More information about the Perl mailing list