3 ms·
Care to point out the reason then? Not sure why you assumed I don't care to find out, especially given I've stated that I've been using Scala since 2009 and lov
by azinman2 12y ago
Care to point out the reason then? Not sure why you assumed I don't care to find out, especially given I've stated that I've been using Scala since 2009 and love the language.
- ArturSoler 12y agoIt's () instead of [] because it's a regular function call. It's related to the scalability thing that Odersky also mentions (as much functionality in libraries as possible, rather than in the language).
- azth 12y agoI'm assuming it's to unify the `apply()` operation between collections (maps, sequences, arrays, etc). The collection library derives from a trait hierarchy, and an array is one of these collection types.
- acjohnson55 12y agoNot just between collections, but functions as a whole. An indexed sequenced is essentially a mapping (read: function) from the integers to whatever the element type is. Scala makes that explicit, rather than creating another mapping operator, as though they failed to notice the symmetry. I would characterize this sort of thinking as one of the core principles of the language design. The designers search for underlying generality and bring it to the surface of the language. This can be a little frustrating at times, since humans aren't necessarily geared toward abstraction. But investment in understanding the abstractions pays off again and again.
- sixbrx 12y agoThe square brackets are used already for type parameters on types. I do think they are easier to read than angle brackets are, for some reason. There was some discussion on this point in the Rust community as well recently where it was noted several people found square brackets easier to read and wanted to emulate Scala here (and another group wanting emulate D, using () for both!). Another reason is that an IndexedSeq is really itself a function (extends Function1), so the parens are literally function application, not some specially interpreted syntax for indexing.
- shogun21 12y agoWhen it comes to arrays, they use () to emphasize the fact that this is a function- arr(1) is arr.apply(1)- instead of directly accessing an element like other languages. Scala makes sense and has a logic behind all its reasons, but sometimes it seems to go against convention for the sake of its own philosophy.