- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
Re: Java more terse than Scala?
Fri, 2009-04-03, 15:45
>>>>> "Dave" == Dave Griffith writes:
Dave> I'll note that both of these are considered bad Java style. I
Dave> personally am a bit surprised that Scala allows multiple vars to
Dave> be defined with one statement, particularly since you can't
Dave> initialize them in that case.
I imagine the real goal was to support:
scala> var a,b,c = 0
a: Int = 0
b: Int = 0
c: Int = 0
and support for this:
scala> val a,b,c = 0
a: Int = 0
b: Int = 0
c: Int = 0
came as an accidental consequence?
but yeah, the latter is pretty useless :-)
Fri, 2009-04-03, 16:17
#2
Re: Java more terse than Scala?
On Fri, Apr 3, 2009 at 4:52 PM, David MacIver wrote:
> 2009/4/3 Seth Tisue :
>>>>>>> "Dave" == Dave Griffith writes:
>>
>> Dave> I'll note that both of these are considered bad Java style. I
>> Dave> personally am a bit surprised that Scala allows multiple vars to
>> Dave> be defined with one statement, particularly since you can't
>> Dave> initialize them in that case.
>>
>> I imagine the real goal was to support:
>>
>> scala> var a,b,c = 0
>> a: Int = 0
>> b: Int = 0
>> c: Int = 0
>>
>> and support for this:
>>
>> scala> val a,b,c = 0
>> a: Int = 0
>> b: Int = 0
>> c: Int = 0
>>
>> came as an accidental consequence?
>>
>> but yeah, the latter is pretty useless :-)
>
> In fact it's not:
>
> scala> var i = 0;
> i: Int = 0
>
> scala> val a, b, c = { i += 1; i }
> a: Int = 1
> b: Int = 2
> c: Int = 3
>
> This fact is used to good effect in Enumeration for example:
>
> val Foo, Bar, Baz = Value
>
Right. AFAIRC the motivation for multiple initializations was to make
enumerations work smoothly.
Cheers
Fri, 2009-04-03, 17:17
#3
Re: Java more terse than Scala?
>>>>> "David" == David MacIver writes:
David> In fact it's not:
scala> var i = 0;
David> i: Int = 0
scala> val a, b, c = { i += 1; i }
David> a: Int = 1 b: Int = 2 c: Int = 3
Cool! That never occurred to me to try. It would be nice if Java
worked that way too, actually. But in Java this:
int a, b, c = 5 ;
initializes c to 5 and leaves a and b uninitialized.
The legacy of C is still with us...
2009/4/3 Seth Tisue :
>>>>>> "Dave" == Dave Griffith writes:
>
> Dave> I'll note that both of these are considered bad Java style. I
> Dave> personally am a bit surprised that Scala allows multiple vars to
> Dave> be defined with one statement, particularly since you can't
> Dave> initialize them in that case.
>
> I imagine the real goal was to support:
>
> scala> var a,b,c = 0
> a: Int = 0
> b: Int = 0
> c: Int = 0
>
> and support for this:
>
> scala> val a,b,c = 0
> a: Int = 0
> b: Int = 0
> c: Int = 0
>
> came as an accidental consequence?
>
> but yeah, the latter is pretty useless :-)
In fact it's not:
scala> var i = 0;
i: Int = 0
scala> val a, b, c = { i += 1; i }
a: Int = 1
b: Int = 2
c: Int = 3
This fact is used to good effect in Enumeration for example:
val Foo, Bar, Baz = Value