Here's an example of an English sentence to keep you interested…
400-year-old spoiler: someone defeats him.
$
, @
and %
— could &
be considered a sigil?
Sigils imitate human language
Look out of the window, what do you see?
That applies to scalars and arrays … English doesn't have a direct match to hashes, although many languages have a 'dual' form specifically for two instances of things.
Language | Single instance | Exactly two instances | Three or more |
---|---|---|---|
English: | Sea | n/a | Seas |
Arabic: | Bahar | Baharain | Baharaat |
Sigils began in BASIC where they were originally on the right
Other languages have them too
PHP uses the dollar sign, so that you know $something is … something, but you don't know what.
Hungarian notion, artificial sigils for languages which don’t have them:
bSomething
is a booleanfSomething
is a floatiSomething
is an integerusSomething
is "tainted" --
see Joel Spolsky, “Making Wrong Code Look Wrong”Pronouns in English are substitutes for the full names of things
Rather than say the whole name again, the pronoun stands in for the whole name.
In Perl, the equivalent of this is $_, and in a plural form @_
while reading each line in a file, print it
for each item in an array, print it
for each key in a hash add its value
Perl actually goes further, you can even skip the default pronoun:
print foreach @array;
—is there an equivalent of this in English?
Perl has a number of words which aren’t strictly necessary,
unless
, which is the opposite of if
, and until
, which is the opposite of while
.
They are “unnecessary” because you can always write if(! $foo )
So why the extra words? Only because it makes it easier to write and to understand.
Show of hands—Do you use "unless" or "until"?
In perl we can write with different word orders and still achieve the same thing, just as you can in English
print $foo if $bar;
if ($bar) {print $foo;}
or even
$bar && print $foo;
If a language is flexible, does that make it easier for ambiguity to happen?
“See that nail? When I nod my head, hit it”
and, less hilariously:
“Let him have it, Chris”
“Let him have it, Chris” was said by this gentleman in 1952:
and the UK legal and political establishment were still arguing over it in 1998 …
… long after his death by hanging.
Some examples in perltrap
and perlop
note that
print ($foo & 255) + 1, "\n";
probably doesn't do what you expect at first glance.
Personally, I’ve got caught before with or
and ||
which mean the same thing in one sense but not another and have very different contexts and precedence.
print FILEHANDLE $foo or die;
is very different to
print FILEHANDLE $foo || die;
$ perldoc perlstyle
Just because you can write very terse perl, doesn’t mean you should.
Less widely-used features of Perl:
Loop labels (almost like an executable comment):
LINE:
for (;;) {
statements;
last LINE if $foo;
next LINE if /^#/;
statements;
}
use English;
Short name | English pragma name |
---|---|
$_ | $ARG |
$" | $LIST_SEPARATOR |
$/ | $INPUT_RECORD_SEPARATOR |
$& | $MATCH |
$@ | $EVAL_ERROR |
$$ | $PROCESS_ID |
copy the third word of the text of window 1 of application "BBEdit" as string to myVarName
A now defunct language which really was like executable pseudocode:
on mouseUp
answer file "which file?"
put it into theFilename
if there is a file theFilename then
put 1 into theNumber
open file theFilename
repeat forever
read from file theFilename until return
put it into currentLine
if currentLine is empty then
exit repeat
end if
delete last character of currentLine
answer "Line " & theNumber & " contains " & quote & currentLine & quote
add 1 to theNumber
end repeat
close file theFilename
else
answer "there is no file by that name"
end if
end mouseup
Anyone know any others?
Shakespeare's "Macbeth"
So … who defeats him and how?
Despair thy charm
And let the angel whom thou has served
Tell thee Macduff was from his mother’s womb
Untimely ripped.
(5.10.14-16)
MacDuff technically wasn't born, but delivered by Caesarian Section.
Larry Wall didn't just design a language.
He designed a community and a culture around that language.
A language is not a set of syntax rules. It is not just a set of semantics. It's the entire culture surrounding the language itself. So part of the cultural context in which you analyze a language includes all the personalities and people involved.
So that's where we come in.
/