From: Michal Kleczek on
Tom Anderson wrote:

> On Tue, 29 Sep 2009, Michal Kleczek wrote:
>
>> Tom Anderson wrote:
>>> If you want to be able to have arbitrary units which can be checked at
>>> compile-time, sure, you need to add difficult stuff to the language. If
>>> you can satisfy yourself with a fixed set of units, or runtime-only
>>> checking, you can do it in java now.
>>
>> Fixed set of units is problematic because it is... fixed :)
>> Runtime-only checking is actually no checking at all (who cares if a bug
>> manifests itself in an IllegalArgumentException or otherwise?)
>
> Because that's going to be a lot more obvious during testing than a value
> being silently wrong.
>

There is no real difference. Testing would find that the value is wrong
anyway. And the value IS wrong - otherwise you wouldn't get the exception.
The only difference is that it can somewhat help finding the root cause.

--
Michal
From: Arne Vajhøj on
Lew wrote:
> Michal Kleczek wrote:
>> 2. First class type parameters ( "new T()" anybody? :) )
>
> No, thanks.

I think it would be nice to have.

And so natural that it would not add to the complexity of
the language.

Arne
From: Arne Vajhøj on
Joshua Cranmer wrote:
> On 09/29/2009 03:35 PM, Michal Kleczek wrote:
>> 2. First class type parameters ( "new T()" anybody? :) )
>
> What would happen if T were an interface or abstract? Better yet, what
> if it were a wildcard type parameter?

Obviously it would need to be a restriction that T is known to
have a parameter less constructor.

It works in C#.

Arne
From: Mike Amling on
Roedy Green wrote:
> Consider a program that uses a mixture of 10-character and 13-digit
> ISBN numbers (International Standard Book Number). From Java's point
> of view, they are all Strings.
>
> It would be nice if there were some mechanism to label Strings with a
> light-weight type, probably a purely compile-time concept, similar to
> generics. You would then label some string vars as ISBN13 and some as
> ISBN10, and similarly parameters to methods. Then the compiler could
> detect an improper passing of in ISBN13 string to an ISBN10 parameter.

You could define classes ISBN10 and ISBN13.

>
> An extension of this idea is units of measure, so that you could not
> pass a cm variable to an inch parameter (though possibly you could
> with an automatic conversion applied).
>
> Think how many times you have wondered if a variable is measured in
> seconds, ms, or ns. Here would be a formal way to specify and check
> your assumption was correct.
>
> Going a step further, your type might have a associated assertion to
> make sure the value were valid. Perhaps there would be a way to
> insert that assertion at every assignment.

Surely someone somewhere must have something like this already, with
classes or interfaces for time, distance, mass, etc.

--Mike Amling
From: Kevin McMurtrie on
In article <4ac1b9d1$0$21087$ec3e2dad(a)unlimited.usenetmonster.com>,
"Kenneth P. Turvey" <evoturvey(a)gmail.com> wrote:

> On Mon, 28 Sep 2009 23:25:39 -0700, Kevin McMurtrie wrote:
>
> > In article <alpine.DEB.1.10.0909282318480.8778(a)urchin.earth.li>,
> > Tom Anderson <twic(a)urchin.earth.li> wrote:
> >
> >> On Mon, 28 Sep 2009, Michal Kleczek wrote:
> >>
> >> > Roedy Green wrote:
> >> >
> >> >> Consider a program that uses a mixture of 10-character and 13-digit
> >> >> ISBN numbers (International Standard Book Number). From Java's point
> >> >> of view, they are all Strings.
> >> >>
> >> >> It would be nice if there were some mechanism to label Strings with
> >> >> a light-weight type, probably a purely compile-time concept, similar
> >> >> to generics. You would then label some string vars as ISBN13 and
> >> >> some as ISBN10, and similarly parameters to methods. Then the
> >> >> compiler could detect an improper passing of in ISBN13 string to an
> >> >> ISBN10 parameter.
> >> >>
> >> >> An extension of this idea is units of measure, so that you could not
> >> >> pass a cm variable to an inch parameter (though possibly you could
> >> >> with an automatic conversion applied).
> >> >>
> >> >> Think how many times you have wondered if a variable is measured in
> >> >> seconds, ms, or ns. Here would be a formal way to specify and check
> >> >> your assumption was correct.
> >>
> >> Gosling keeps talking about adding this to java.
> >>
> >> > That is not so easy to make it right. Read for example:
> >> > http://research.sun.com/projects/plrg/Publications/p109-allen.pdf
> >>
> >> If you want to be able to have arbitrary units which can be checked at
> >> compile-time, sure, you need to add difficult stuff to the language. If
> >> you can satisfy yourself with a fixed set of units, or runtime-only
> >> checking, you can do it in java now.
> >>
> >> tom
> >
> > Hopefully nobody 'solves' this by adding Generics to Strings. Java's
> > syntax is already going off the deep end. (And yet the simple things
> > like unsigned math and arrays of contiguous Object data are dismissed as
> > not worth the effort.)
>
> Both of those are real annoyances... I've got one more though, closures.
> Anonymous classes are ugly when unneeded.

That too. MacOS 10.6 now uses them for lightweight parallel code
execution. Java has the Future and Callable classes but they're clumsy.

--
I will not see your reply if you use Google.
First  |  Prev  |  Next  |  Last
Pages: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
Prev: Putting passwords in a properties file?
Next: Interview