Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

On Perl's "contractions"

by merlyn (Sage)
on Aug 10, 2004 at 13:52 UTC ( #381585=note: print w/replies, xml ) Need Help??

in reply to Legible or Obfuscated?

I recently noticed that Perl is a language with "contractions".

In English, it's much more efficient and common to say "can't" rather than "cannot" or "can not". Sure, it's redundant: you could have always used the longer form. But by permitting the contraction of "can't", you reward the more experienced English speaker with the savings of a bit of time and effort.

Similarly, foreach $_ (...) { ... } is semantically identical to foreach (...) {...} which is semantically identical to for (...) {...}. Sure, the latter are redundant in a pure sense, but they perform the "contraction" for the experienced Perl speaker.

So, it's best to learn the common "contractions". It saves time and typing for the expert, although it might slightly confuse a beginner. In fact, not using the contraction will likely confuse or call unduly attention for an expert, much like someone saying "can not" is when speaking English. An expert will wonder why the speaker didn't use "can't", because it sounds odd.

When I program in other languages, I miss Perl's contractions. Having only one (or two) ways to say something leaves me without a convenient short way to do something. I'm glad I have the opportunity to write mostly in Perl.

-- Randal L. Schwartz, Perl hacker
Be sure to read my standard disclaimer if this is a reply.

Replies are listed 'Best First'.
Re: On Perl's "contractions"
by shenme (Priest) on Aug 11, 2004 at 03:00 UTC
    An expert will wonder why the speaker didn't use "can't", because it sounds odd.
    Was the choice of example conscious? Because it is wonderful. It both describes the barrier to those new to the language, and the utility to those who know the "cant".
Re: On Perl's "contractions"
by biosysadmin (Deacon) on Aug 11, 2004 at 04:08 UTC
    Right on. There's an amazing amount of natural language principles in Perl, including contractions and pronouns. I really enjoy reading Larry Wall's writing about Perl and the linguistic concepts he incorporated into the language, he has a great essay on his site about it: Natural Language Principles in Perl.

    I definitely know that I miss Perlish idioms in other languages, and I'm certain that I'm not the only one. Other languages are learning though, Java recently added a foreach loop in Java 1.5. :)

Re: On Perl's "contractions"
by SciDude (Friar) on Aug 11, 2004 at 05:32 UTC

    Your request for an example such as "will not" vs. "wont" prompted the following thoughts...

    What about use warnings, carp, cluck, croak, and confess? This spans the reporting with more severe results starting with simple warning and ending with Die and backtrace (confess.)

    You might relate these to should, shall, shant, will not, and wont.

    The first dog barks... all other dogs bark at the first dog.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://381585]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (5)
As of 2021-06-24 09:40 GMT
Find Nodes?
    Voting Booth?
    What does the "s" stand for in "perls"? (Whence perls)

    Results (124 votes). Check out past polls.