begin  quoting David Brown as of Sun, Jan 06, 2008 at 05:29:12PM -0800:
> On Sun, Jan 06, 2008 at 05:11:01PM -0800, SJS wrote:
> 
> >Then again, putting all the variable declarations at the top of the
> >method/function gives you much of what you want.
> >
> >function name( args ... ) {
> >  LongArduousType foo; 
> >    . . .
> >  foo = new LongArduousType(...);
> 
> This is considered bad style in most modern languages.

Oh, joy.

>                                                         In fact, it is
> forbidden in some.  The idea isn't to move the initialization up to the
> top, but to move the variable declaration down to where it is first
> assigned.  You don't ever declare variables without giving them their
> initial value.

LongArduousType foo = null; 

:)

> C# is kind of enough to consider use before initialization to be a static
> compilation error.  Most other languages just consider it a warning.

Well, C# is just a Java ripoff. That's nothing new.

> I still think something like:
> 
>   auto foo = new LongArduousType(...);
> 
> is much cleaner.

It's cleaner than never declaring foo at all, just using it. I'll go
with that.  And it *seems* like it would be cleaner than always having
to declare a type even for something where you Just Don't Care.

But it also seems to open the door for auto-return-types.

auto foo( auto input ) {
   auto bar = processInput( input );
   ...
   return bar;
}

At the moment, I'm actually wondering about heading in the other
direction.  What if objects _have_ a type, but do not _define_ a type?
What if, to define an type, you had to define an interface, and
variables (and parameters, and return-types) could _only_ be
interefaces?

-- 
There's probably a language that already does that
And then takes five files to recreate the tool 'cat'.
Stewart Stremler

-- 
[email protected]
http://www.kernel-panic.org/cgi-bin/mailman/listinfo/kplug-lpsg

Reply via email to