 |
 |
|
 |
|
 |
|  |
|  |
|
 |
From: Orchid XP v8
Subject: Re: A question about Java generics (not a flame)
Date: 9 May 2008 13:48:38
Message: <48248e76$1@news.povray.org>
|
|
 |
|  |
|  |
|
 |
Warp wrote:
> Yes, I know it would be better to ask this in a Java forum, but I'm just
> too lazy to dig one up (as well as not too eager to show my ignorance in
> a random forum ;) ). Given the amount of programmers here, I'm sure at
> least someone knows the answer to this.
[insert ironic comment here]
> Java supports generics.
...OK, I just learned something.
> Is there a way in Java to shorten those long type names?
Given the statement above, is there any point in my answering this? ;-)
--
http://blog.orphi.me.uk/
http://www.zazzle.com/MathematicalOrchid*
Post a reply to this message
|
 |
|  |
|  |
|
 |
From: Orchid XP v8
Subject: Re: A question about Java generics (not a flame)
Date: 9 May 2008 13:54:36
Message: <48248fdc@news.povray.org>
|
|
 |
|  |
|  |
|
 |
Warp wrote:
> I will never understand why they decided to drop 'typedef' when they
> designed Java in the first place. It's so handy in C++.
Well, in Java everything is a class. So it's not 100% obvious where
you'd *put* a typedef. (I suppose it could be something that's local to
a class or something...)
>> It's interesting to note that in scripting languages, all that could be a
>> one-liner. In Javascript:
>> var theMap = {"foo": [["one", "two"], ["three", "four"]]};
>
> Yeah, but that's only possible in languages with weak typing (I think
> that's the term?) In other words, in languages where you don't have to
> specify types explicitly, as they are inferred from the values.
Two cases here:
- JavaScript is dynamically typed. Types become known only at runtime.
Types are checked only at runtime. Many scripting languages follow this
model. (Smalltalk immediately springs to mind here.)
- Haskell is statically typed, but types are [usually] inferred
automatically. Types are checked at compile-time only. Types are not
known at runtime at all. [With the exception of types belonging to a
class of some kind.]
Obviously nobody cares, but:
theMap = fromList [("foo", [["one", "two"], ["three", "four"]])]
--
http://blog.orphi.me.uk/
http://www.zazzle.com/MathematicalOrchid*
Post a reply to this message
|
 |
|  |
|  |
|
 |
From: Warp
Subject: Re: A question about Java generics (not a flame)
Date: 9 May 2008 14:29:08
Message: <482497f4@news.povray.org>
|
|
 |
|  |
|  |
|
 |
Orchid XP v8 <voi### [at] dev null> wrote:
> Warp wrote:
> > I will never understand why they decided to drop 'typedef' when they
> > designed Java in the first place. It's so handy in C++.
> Well, in Java everything is a class. So it's not 100% obvious where
> you'd *put* a typedef.
You'd put it in the exact same place as you'd put a class.
--
- Warp
Post a reply to this message
|
 |
|  |
|  |
|
 |
From: Warp
Subject: Re: A question about Java generics (not a flame)
Date: 9 May 2008 14:34:49
Message: <48249949@news.povray.org>
|
|
 |
|  |
|  |
|
 |
Orchid XP v8 <voi### [at] dev null> wrote:
> > Java supports generics.
> ...OK, I just learned something.
Java generics are a bit ironical because before they existed the
common consensus among Java people was that C++ templates are an
abomination (in the same category as, for example, multiple inheritance,
if not even worse).
Of course this was before all the generic programming craze, and when
it hit, the Java people had to swallow their pride and introduce some
crippled template mechanism into Java. Naturally since templates were
always considered an abomination they couldn't call them that, so they
tried to save even a bit of their pride by renaming them to "generics".
(I suppose "generics" rides more on the whole "generic programming"
thing.)
Of course Java generics are a bit crippled because they don't support
basic types (such as int). Thus they solve only part of the problem which
Java had before.
--
- Warp
Post a reply to this message
|
 |
|  |
|  |
|
 |
From: Orchid XP v8
Subject: Re: A question about Java generics (not a flame)
Date: 9 May 2008 14:50:19
Message: <48249ceb$1@news.povray.org>
|
|
 |
|  |
|  |
|
 |
Warp wrote:
> Orchid XP v8 <voi### [at] dev null> wrote:
>>> Java supports generics.
>
>> ...OK, I just learned something.
>
> Java generics are a bit ironical because before they existed the
> common consensus among Java people was that C++ templates are an
> abomination (in the same category as, for example, multiple inheritance,
> if not even worse).
>
> Of course this was before all the generic programming craze, and when
> it hit, the Java people had to swallow their pride and introduce some
> crippled template mechanism into Java. Naturally since templates were
> always considered an abomination they couldn't call them that, so they
> tried to save even a bit of their pride by renaming them to "generics".
> (I suppose "generics" rides more on the whole "generic programming"
> thing.)
>
> Of course Java generics are a bit crippled because they don't support
> basic types (such as int). Thus they solve only part of the problem which
> Java had before.
Well, actually Eiffel calls it generics too. I don't know when Eiffel
was designed, but it's had generics from day 1, and that has always been
its name.
I don't actually know how C++ templates work, but my take on it is this:
- Generics is the ability of a programming language to implement classes
that are parameterised over another class.
- C++ implement this ability using templates.
- Templates can do other things besides implementing generics.
So to say that Java's generics is a crippled copy of C++'s template
mechanism isn't entirely true.
OTOH, I haven't seen Java generics or C++ templates "for real", so maybe
I'm mistaken.
--
http://blog.orphi.me.uk/
http://www.zazzle.com/MathematicalOrchid*
Post a reply to this message
|
 |
|  |
|  |
|
 |
From: Warp
Subject: Re: A question about Java generics (not a flame)
Date: 9 May 2008 15:00:54
Message: <48249f66@news.povray.org>
|
|
 |
|  |
|  |
|
 |
Orchid XP v8 <voi### [at] dev null> wrote:
> - Templates can do other things besides implementing generics.
I think it suffices to say that with C++ templates you can, for example,
calculate at *compilation time* whether a certain number is prime or not.
Moreover, you can even do that without using any integer literals or
any basic type, such as 'int'. (Although doing it like that is really
not the most efficient way.)
--
- Warp
Post a reply to this message
|
 |
|  |
|  |
|
 |
From: Orchid XP v8
Subject: Re: A question about Java generics (not a flame)
Date: 9 May 2008 15:15:21
Message: <4824a2c9$1@news.povray.org>
|
|
 |
|  |
|  |
|
 |
>> - Templates can do other things besides implementing generics.
>
> I think it suffices to say that with C++ templates you can, for example,
> calculate at *compilation time* whether a certain number is prime or not.
So... it's Turing-complete?
--
http://blog.orphi.me.uk/
http://www.zazzle.com/MathematicalOrchid*
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
Warp wrote:
> Yeah, but that's only possible in languages with weak typing (I think
> that's the term?)
"Dynamic typing" is the term you're looking for - expressions have
types, but not variables.
"Static typing" being the alternative, where variables have types.
"Weak typing" is when type operations aren't enforced, like in C.
"Strong typing" is when type operations are enforced, like Java.
You can have strong typing that's also dynamic typing, like Smalltalk or
Lisp or Erlang, or static typing that's weak like in C, or static typing
that's strong like (say) Haskell (as I understand it), or dynamic typing
that's weak (like Forth or assembler).
--
Darren New / San Diego, CA, USA (PST)
"That's pretty. Where's that?"
"It's the Age of Channelwood."
"We should go there on vacation some time."
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
Orchid XP v8 wrote:
>> Java supports generics.
> ....OK, I just learned something.
Are they actually supported as new types? Or is it just syntactic
shorthand? I wouldn't think you could really have generics if you didn't
change the .class file format, which I think Sun's trying to avoid?
--
Darren New / San Diego, CA, USA (PST)
"That's pretty. Where's that?"
"It's the Age of Channelwood."
"We should go there on vacation some time."
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
Orchid XP v8 wrote:
> So... it's Turing-complete?
Yep. I saw a turing machine emulator written as templates, with a
series of error messages from the compiler tracing the path through the
state changes.
In any case, generics are a subset of templates. It's entirely possible
to think that generics are a good idea and that templates are a bad way
to implement them. For example, you have to parse and compile the
templates each time from source, and you get a new blob of code for each
type you instantiate a template with. Both of these are a bad idea when
you're trying to make a system where you can distribute object code
without source for generics, or you want to instantiate a generic at
runtime with some other class you just loaded.
Now, "crippled" is what I'd call the baroque C++ syntax. I mean, really,
folks, can't we accept that languages that aren't C don't need to avoid
C special characters in new syntax? :-) What's with this "::" for
namespaces in Tcl and <<>> for generics in Java? Ugly, guys, uUUUuugly!
--
Darren New / San Diego, CA, USA (PST)
"That's pretty. Where's that?"
"It's the Age of Channelwood."
"We should go there on vacation some time."
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |