[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: why doesnt a[1] = 1 work?
- From: Don Hopkins <dhopkins@...>
- Date: Wed, 23 May 2007 16:49:16 -0700
Peter Odding wrote:
Markus Heukelom wrote:
However, I agree this might have some other (ugly) repercussions not
immediately obvious at this moment.
(In fact, to implement this behavior, I would have to change the
__newindex
methods of the nil, number, string, etc matetable (can only in c),
right?
Not that I will do that - just for the idea.)
Apart from whether it's possible to set a metatable for nil (never
tried), note that you'd only be able to do this for scalars, i.e. not
for tables and userdata, because there's no `global' metatable for
these types.
About this concept in general, I don't think it would fit Lua very
well. PHP allows it, and that's caused me a few hard to find bugs.
- Peter Odding
It's a VERY GOOD THING that Lua is nothing like PHP!
One of the many horrible design decisions in PHP, which encourages
people to write sloppy bug-ridden code, was to automatically create an
associative array when you go "$a[1] = 1".
Programming languages should never try to guess what you mean, nor
attempt to figure out what you would have wanted them to do when your
program has errors and ambiguities.
Unfortunately PHP has conditioned many programmers to expect and even
rely on that kind of misbehavior, many of whom actually run with warning
and error reporting turned off, so they don't even realize (or care)
that their programs contain many errors and warnings and ambiguities,
which is why so many PHP programs have such horrible bugs and security
holes.
Warren Teitelman's "DWIM" system for Interlisp is widely considered a
terrible failure.
People should learn from history, like Lua's designers did, instead of
repeating the mistakes of the past, like PHP's designers did!
-Don
http://en.wikipedia.org/wiki/DWIM
http://www.catb.org/~esr/jargon/html/D/DWIM.html
DWIM: /dwim/
[acronym, ‘Do What I Mean’]
1. adj. Able to guess, sometimes even correctly, the result intended
when bogus input was provided.
2. n. obs. The BBNLISP/INTERLISP function that attempted to accomplish
this feat by correcting many of the more common errors. See hairy.
3. Occasionally, an interjection hurled at a balky computer, esp. when
one senses one might be tripping over legalisms (see legalese).
4. Of a person, someone whose directions are incomprehensible and vague,
but who nevertheless has the expectation that you will solve the problem
using the specific method he/she has in mind.
Warren Teitelman originally wrote DWIM to fix his typos and spelling
errors, so it was somewhat idiosyncratic to his style, and would often
make hash of anyone else's typos if they were stylistically different.
Some victims of DWIM thus claimed that the acronym stood for ‘Damn
Warren’s Infernal Machine!'.
In one notorious incident, Warren added a DWIM feature to the command
interpreter used at Xerox PARC. One day another hacker there typed
delete *$ to free up some disk space. (The editor there named backup
files by appending $ to the original file name, so he was trying to
delete any backup files left over from old editing sessions.) It
happened that there weren't any editor backup files, so DWIM helpfully
reported *$ not found, assuming you meant 'delete *'. It then started to
delete all the files on the disk! The hacker managed to stop it with a
Vulcan nerve pinch after only a half dozen or so files were lost.
The disgruntled victim later said he had been sorely tempted to go to
Warren's office, tie Warren down in his chair in front of his
workstation, and then type delete *$ twice.
DWIM is often suggested in jest as a desired feature for a complex
program; it is also occasionally described as the single instruction the
ideal computer would have. Back when proofs of program correctness were
in vogue, there were also jokes about DWIMC (Do What I Mean, Correctly).
A related term, more often seen as a verb, is DTRT (Do The Right Thing);
see Right Thing.