[Date Prev][Date Next][Thread Prev][Thread Next][Author Index][Date Index][Thread Index]
Re: Trivial suggestion
- To: <ravi>
- Subject: Re: Trivial suggestion
- From: Michael McClary <michael>
- Date: Wed, 12 Sep 90 15:29:35 PDT
- Cc: <xtech>
> But it does so by substituting run-time type-checking for compile-time
> type-checking.
>
> Not exactly. In fact, CAST(Bar, OK(baz->fetchFoo())) could safely be
> turned into a hard cast by some hypothetical optimizer if Bar is equal
> to or a superclass of Foo (the return type of fetchFoo).
Still, in the absence of the hypothetical optimizer, you do the overhead
all the time.
> If Bar is a
> subclass of Foo, then the run-time type checking would be necessary
> even if we had a getFoo method.
Right. But you have lost any flagging in your source that run-time
mismatches are possible, so you won't be thinking about whether they
can happen. I'd rather you were writing code without casts, letting
the c++ tranlator gripe when one was needed, then thinking about
whether it's the right thing to do.
We have these tools to warn us about bugs. Why discard them? Casting
down is a strong indication that a subtle bug is possible, and human
attention is required.
> Using OK(fetchFoo) instead of getFoo
> merely avoids writing a zillion fetchX/getX pairs.
So how about this:
Define a smalltalk-only method nilCheck: in Tofu. Hack the translator so:
[...] nilCheck: fetchFoo
translates to:
[...] getFoo()
and a getFoo is emitted whenever a fetchFoo that just returns the foo is
translated. (nillCheck: can go through run-time gyrations to mimic the
automatically-generated error message if the translator makes it informative.)
Really, though, what's hard about writing the getX method? I'd think
you'd just:
- Bring up an existing getY method in another browser.
- Double-click at the end of it.
- Copy
- Double-click at the end of your fetchX method
- Paste
- Change the name from getY to getX
- (Change the returned type if necessary)
- (Change the message if you're feeling ambitious)
- Accept
and do the analogous thing in an editor when writing native C++. (You
don't actually TYPE those things every time, do you? I almost never
write anything de-novo - it's too error-prone. Not to mention bOOOOring.)
Twenty seconds? Five? How about if you have a "prototypes" file of
generic abstract and concrete heapers at the bottom of the CXX browser
file pane?
How about if the prototypical "fetchFoo" method had the prototypical
"getFoo" method as a comment? (Then you could edit them both at the
same time, accept the fetchFoo, then rip out all but the getFoo and
accept that.)
How much time do we LOSE if there's one bug that we must track the
hard way? How much if there's thirty? How many sales do we lose
if some of those bugs escape to the customer code?
michael