Page 1 of 1

Perl for Fun and Profit

Posted: Fri Sep 10, 2004 3:07 pm
by Allan_ecker
Hee hee! I learned the basics of Perl for work! It will be MOST helpful when I'm taking my commentary file and using it to generate the 300+ html pages I'll need for the UHCD.

Bwa ha ha!

Perl is actually a really, really WIERD language, what with wraparound array addresses, four billion-odd keywords, and context-sensitivity up the wazoo. BUT. It's very useful for manipulating text files.

Re: Perl for Fun and Profit

Posted: Thu Sep 16, 2004 10:35 am
by Candide
allan_ecker wrote:Perl is actually a really, really WIERD language, what with wraparound array addresses, four billion-odd keywords, and context-sensitivity up the wazoo. BUT. It's very useful for manipulating text files.
I've written whole programs in Perl.

The toughest part of learning Perl is learning to use regular expressions. Otherwise, if you know C, Perl's syntax is pretty easy.

Actually, the other weird part of Perl is the whole package & OOP facility. It takes a bit-o-learning to get writing packages down. As for OOPerl, all that bless/carp stuff is just too unfamiliar to pick up quickly, especially if you know C++/Java/C# or some other OO-language.

Posted: Thu Sep 16, 2004 10:53 am
by Randyg
Perl is fun... I've had to teach it to students, although at an introductory level.

Many people seem to aspire to make their perl look like random line noise... which, although that's quite possible with the language, really isn't how to produce good code. I've sometimes noticed that new students write prettier code than many experts, since they use simple, blocked structures instead of huge messes with default variables, trailing conditions, etc. Of course, my definition of pretty may be different than other people's, and I'm a die-hard C fan...

Regexps are pretty easy, and quite powerful... if you've used sed (or awk) at all, you probably know half of it already. then again, I seem to annoy people on irc/aim when I make a typo, and correct it with s/typo/fix/g.


Only 4 billion keywords? you must just be counting the ones composed entirely of punctuation. :P


--Randy

Posted: Thu Sep 16, 2004 8:11 pm
by Candide
randyg wrote:Many people seem to aspire to make their perl look like random line noise... which, although that's quite possible with the language, really isn't how to produce good code.
Actually, it's possible to make any programming language look like line noise.

Now, I agree that some let you produce legal code that's more random-noisy-looking than others. However, that doesn't mean you cannot generating write-only code in those other languages. You most certainly can.

That's why, like in a human language, following good style while programming is vital if you want what you're writing to be readable by anyone else.

Posted: Thu Sep 16, 2004 9:07 pm
by Randyg
several years ago, someone gave me a line-noise-ish perl program to compute primes... my response was the following C program, which I stated would also print out primes:

Code: Select all

int main(void){int e=1,s=-1;while(s++,e)printf("%c%s",((e="0@ />\
^&[S#$( 0@ 1B(&+8 $( ^[#/>(JZS!?_!0@ !*(2* #$( 0@ !2^&[[!$( W=W=\
W=W=W=W=/R'?.!/$Y$!/G$!!$1!1H$%A@H(!!$1!10$%!GH(!!$1!10$%!H((R'$\
.?/0XX@'G$"[s/6])-32)&1<<s%6?'1':32,(s+1)%78?"":"\n");return 0;}
(note: you can eliminate a half line or so if you don't mind gcc giving warnings.. such as int, void, return, etc.)

(WARNING: there are NO optional spaces in that code. Nor can spaces be added in most places. If your browser adds leading spaces to the lines, please strip them, as none of the lines have leading or trailing spaces)

note that I've yet to see a BASIC program look like line noise. it may look like the person who wrote it should be shot, but it can't look like line noise. it's missing all the fun operators needed. :)

Of course, if you really want ugly, you can get into intercal, brainfuck, lisp... *ducks before the AI people find him* (ok, I admit, I'm actually reasonably proficient at common lisp... it's just easy to make it really, really ugly)

I've written a few intentionally line-noise-ish C programs... another one I have somewhere, if I could find it, prints out all permutations of the numbers 1 through n where each adjacent pair of numbers adds to a perfect square. plus one to display mandlebrots in ascii art, that I don't think I have any more.

However, I never wrote any of these as serious programs. Something about perl fans seems to make them consider line-noise to be an acceptable coding style. :)


--Randy

Posted: Fri Sep 17, 2004 8:33 am
by Candide
randyg wrote:

Code: Select all

int main(void){int e=1,s=-1;while(s++,e)printf("%c%s",((e="0@ />\
^&[S#$( 0@ 1B(&+8 $( ^[#/>(JZS!?_!0@ !*(2* #$( 0@ !2^&[[!$( W=W=\
W=W=W=W=/R'?.!/$Y$!/G$!!$1!1H$%A@H(!!$1!10$%!GH(!!$1!10$%!H((R'$\
.?/0XX@'G$"[s/6])-32)&1<<s%6?'1':32,(s+1)%78?"":"\n");return 0;}
:
:
note that I've yet to see a BASIC program look like line noise. it may look like the person who wrote it should be shot, but it can't look like line noise. it's missing all the fun operators needed. :)
Well, yes, but that's in line with what I was saying (in an overgeneralized way, it seems): Some languages have extra things in them that let you write more compact, less readable code. Some languages have digraphs and trigraphs to replace characters like '
randyg wrote: may not exist on all keyboards around the world. However, all languages have operator precedence, making the use of parens optional in some cases. You can let operator precedence pair up the parts of a complex expression. Put it all on one line, and voila! Your "if"-statement will be unreadable by most mere mortals.
randyg wrote:Of course, if you really want ugly, ...
Listen, to paraphrase the noted linguist, John McWhorter, no language is inherently "uglier" or "harsher" or "more logical". That's 1 part personal aesthetics, and purely subjective, and 10 parts ego because you don't know the language (or don't know it well enough) and refuse to admit it.

I have found this to be true of human beziehungsweise computer languages.
randyg wrote:However, I never wrote any of these as serious programs. Something about perl fans seems to make them consider line-noise to be an acceptable coding style. :)
Oh, that's just the complex regexps and 2-char builtin variables. You can (and I do) type that extra "my $basenamePlusVersionNumber = $_;" to make the code literate. And it only takes a bit of learning to discover that:

Code: Select all

for ($someStringOfMine) {
    s/^\s*//;
    s/\s*$//;
}
...is pronounced, "Trim whitespace from both sides of the string, '$someStringOfMine'."

Larry Wall has stated that he wrote Perl with, "There's more than one way to do it," in mind.


As for languages, I have a complaint with Python. Not because I'm some Perl evangelist who's threatened by Python. Nope. It's part aethetic, part age-related.

Aesthetics: We decided back in the 70's that making whitespace a syntactic element of a programming language was a Bad Idea. Why resurrect a bad idea rejected 20+ years ago?

Ageism: Sure, you young'uns may be able to set your screen resolution to 1600x1200 with an 8-pt font to get 200-char long lines. You whippersnappers may be able to eyeball the start of a line and instantly know how many tab characters that indistinguishable whitespace equals.

Those of us with poor eyesight growing poorer with age can't. We need that extra visual guide of a '{' and '}' to tell which nested block we're in. We need larger fonts and lower resolutions, meaning shorter line sizes.

Consequently, due to my aged eyes, I actually find Python less readable than Perl, which I freely admit can get squirrelly. Was it really all that horrible to add '{' '}' to Python? Miguel de Icaza still could've required that, "A '\n' must be followed by a '\t' or a printing character. Any other whitespace at the start of a line is an error," and he'd have his style-enforcement, without making whitespace a language syntactic element. Heck, he even could've required that block start/end chars '{' and '}' must appear alone on a line, preceded only by '\t'. (And he could've been really nice to those of us aging by using a ' ' as the Lone Valid Whitespace Padding instead of a '\t'.)


But, ultimately, my complaints about Python reveal something deeper: It is Pure Hubris to believe that you can write a programming language that enforces "good" style. It's like "idiot-proof" devices: G*d will design a better idiot. Likewise, there's no way to enforce good coding style using a language's syntax. Someone will find a way to abuse it.


Wow. A lot more than I intended to write.

Posted: Fri Sep 17, 2004 3:13 pm
by DetailBear
candide wrote:We decided back in the 70's that making whitespace a syntactic element of a programming language was a Bad Idea.
Says who?

Posted: Fri Sep 17, 2004 7:06 pm
by Allan_ecker
DetailBear wrote:
candide wrote:We decided back in the 70's that making whitespace a syntactic element of a programming language was a Bad Idea.
Says who?
I know I'll chime in.

Now, syntactic white space SOUNDS like a great idea on the surface.

Think; now you have to put in white space, even if you're one of those people who likes making code as difficult to read as possible.

HOWEVER, now you have MORE RULES than when you started. The rules taht create legible code should come from the user, not from the language; rules designed to create legible code are almost guaranteed to generate confusion, and worse, create syntactic "catch 22" situations where the requiered use of white space actually detracts from the legibility of code.

Good code should, ideally, be both legible and efficient. If white space is a required part of syntax, the most efficient way to write a certain operation might be to use REALLY AWKWARD white space. Or, alternatively, the most legible way to write a given function could be syntactically impossible.

When white space is outside the language, even a tortured rictus of code can be spaced apart, commented, and made legible. But if white space is part of that code, it is entirely possible that no trick of syntax could rescue the legibility of some optimized blocks of code.

Whoa. I forgot how passionate I could get about programming languages.

Posted: Sat Sep 18, 2004 1:54 pm
by DetailBear
allan_ecker wrote:
DetailBear wrote:
candide wrote:We decided back in the 70's that making whitespace a syntactic element of a programming language was a Bad Idea.
Says who?
I know I'll chime in.

Now, syntactic white space SOUNDS like a great idea on the surface....
I think I was too subtle, or not subtle enough. My point wasn't "why is syntactic whitespace a bad idea?", it was "what group decided it?". "Says who?" not "Says you!"

Was there a big meeting that I was too young for? Did the L'Academie Computais des Langues make a proclamation? Was every language using syntactic whitespace immediately dumped and never used again and no new ones created? It was a request for information, specifically proof of the statement. If you're going to tell me what to do, even indirectly, I'd like to know why.

I actually have no idea what the argument is about. I assume the equivilent would be "Whatiswrongwiththisquestion?" If that is true, I suppose the answer is 'nothing', if no human has to read it. In that case, enforcement of good legibility is easy: You'll never get hired by anyone to code it, if no-one else can read it.

And yes, I was both the teachers' pet for being able to make subtle distinctions, and a thorn in their side for bringing them up in class. :D

Posted: Sat Aug 20, 2005 5:29 pm
by Micro_Fur
<WARNING> Unstructured Rant Ahead <WARNING>




Anyone out there remember the cartoon series "REBOOT", and the movie "Jurrasic Park"? They were made on SGI computers namely the Indigo IRIS.

My point being is aside from working on my wonderful AMD Opteron desktop running Fedora Core 3 and Windows XP Pro SP1 (I absolutely detest SP2, but thats a rant for later, and no I'm not schitzo but my hardrive is another story :wink: :wink:), I still write -some- code under the irix operating system to help me with better modeling of those old poor circuits I used to build for profit in my days before the military. -sigh- I really miss my old hobbies/work, being a mechanical operator is just not the same, as a friend of mine once put it our workplace employs ". . . all the dangers of an industrial workplace along with the joys of a group of bored [often] intelectuals. . ."

BLAH! I'm starting to sober up, the weekend is alot more fun when you kave good buzz. NOT a drunk nor am I, I am a responsible drinker.

Posted: Sun Aug 21, 2005 6:20 pm
by Andrick
Proof again that "denial" isn't a river in Egypt. ^^