Related articles |
---|
Q: Definition of a scripting lang. ariel@ccs.neu.edu (1995-03-04) |
Re: Q: Definition of a scripting lang. macrakis@osf.org (1995-03-10) |
Re: Q: Definition of a scripting lang. eifrig@beanworld.cs.jhu.edu (1995-03-15) |
Re: Q: Definition of a scripting lang. lwall@netlabs.com (1995-03-27) |
Re: Q: Definition of a scripting lang. rpereda@wotangate.sc.ti.com (1995-04-05) |
Re: Q: Definition of a scripting lang. lwall@netlabs.com (1995-04-16) |
Re: Q: Definition of a scripting lang. leichter@zodiac.rutgers.edu (1995-04-18) |
Newsgroups: | comp.compilers |
From: | lwall@netlabs.com (Larry Wall) |
Keywords: | design |
Organization: | NetLabs, Inc., Los Altos, California. |
References: | 95-04-013 95-04-056 |
Date: | Sun, 16 Apr 1995 19:53:20 GMT |
Ramon Pereda, <rpereda@wotangate.sc.ti.com> wrote:
: Forgetting a trailing semicolon is a common goof in a variety of
: languages such as Perl, Ada, Pascal, and C.
If it's a common goof, it behooves the compiler writer to give a good
diagnostic. Here, let's try it:
$ perl
foo(1,2,3)
bar(4,5,6);
Semicolon seems to be missing at - line 1.
syntax error at - line 2, near "bar"
Similarly for allowing newlines within a string constant:
$ perl
print "A string missing its trailing quote;
print "Another string";
Bare word found where operator expected at - line 2, near "print "Another"
(Might be a runaway multi-line "" string starting on line 1)
Admittedly, many C compilers give you confusing diagnostics when you
leave out a semicolon. This results from a conspiracy of ambiguity
between the C grammar and yacc. It's one of the reasons I don't like
dangling statements (and why Perl doesn't have them).
: I see pitfalls like this as flaws in the language, not the novice
: programmer. Perhaps his semi-conscious act of leaving out the
: semicolon has a natural elegance. Programming language designers
: should not beat this innate habit out of the novice programmer.
While I usually come down on the side of intuition, I must point out
that every novice programmer has a multitude of bad habits that must be
beat out of him or her. Our abhorrence of violence (which was beat
into us by our culture) should not deter us from beating civility into
those who need it.
The fact is, people think in terms of statement terminators. Every
time you finish speaking a sentence, you change the intonation at the
end of it, and insert a pause before the next sentence. This is pretty
much universal in human languages.
The only way I can see you winning this argument is if you liken a
program to a poem. Line structure is more important in poetry than in
prose, and there are some forms of poetry that allow you to omit the
punctuation. This often comes at the expense of other syntactic
restrictions, however, such as the number of syllables allowed per
line. On the other hand, there are poets that write unpunctuated free
verse to get more of a stream-of-consiousness feel, or to keep the
clausal bindings purposefully ambiguous. That's fine in poetry. But
I don't think you can argue that this is intuitive to the novice.
Experts are purposefully ambiguous; novices only accidentally so.
: I don't have any hard rules for justifying leaving out the semicolons.
: I just appeal to your intuitions (when you FIRST STARTED programming if
: you can think back that far). Isn't simpler? Less clutter?
Simpler? Less clutter? In some sense, maybe. Would you consider your
life simpler and less cluttered if we removed all the stop signs from
our streets?
Odd that you should appeal to my intuition. When I FIRST STARTED
programming, I used a language like that, and I always felt that
line-continuation markers were exceedingly ugly and unnatural.
Similarly for any other cute line-continuation tricks depending on
unfulfilled syntactic expectations, where you're allowed to use a
newline in certain places in the grammar but not others. Ugh.
I breathed a great sigh of relief when I discovered languages with
statement terminators. Your mileage has obviously varied.
Note that C has the worst of both worlds here--ordinary statements are
semicolon terminated, but macros definitions are terminated by the end
of the line, and therefore need backslash as a continuation marker.
Despite the fact that I write many more statements than macros, I
forget the backslash *far* more often than the semicolon. This is
because line continuations are (for me) conceptually outside the syntax
of the language, while the statement terminators are very much an
explicit part of it. I suspect most C programmers would agree here.
Maybe even some shell programmers. :-)
: The semicolon pitfall is pervasive and very easy to remedy.
No, it's not. You haven't considered all the ramifications. Zeroing
in on one feature without considering it in context doesn't achieve
any good in the long haul--it's just moving piles of complexity and
risk around to the other end of the prison yard. The warden might
enjoy it, but the prisoners certainly won't.
: Now, if only English were as easy to fix...
It's easy enough to trash English, and I even laughed like I was
supposed to, but I also note that you enjoy your English punctuation
sufficiently to use at least three different statement terminators:
?
.
...
And I don't see any place where you accidentally left one out. Perhaps
statement terminators are intuitively obvious to some people...
Larry Wall
lwall@netlabs.com
--
Return to the
comp.compilers page.
Search the
comp.compilers archives again.