|
Re: Some initial suggestions (or perhaps things I don't understand): msg#00014lang.scala
Hey, Nathan, thanks for the detailed comments! You should be sure and grab the beta release. It seems to address some of your concerns. I don't know the details of Scala 1 versus 2 extremely well. I'll answer based on Scala 2. > Constructors and instance variables in Scala are confusing and sort of > frustrating. For example, if I use the default constructor, then it > seems I have to commit myself to using its arguments as values rather > than variables. I would really like to be able to specify mutable > instance variables in the default constructor. All you need to do is put "var" in front of the parameter you want to be modifiable: class Foo(var somestuff: String) { ... } Also, you can perfectly well create mutable variables, and even give them some code. Note, by the way, that all loose code in a class is executed whenever a class is instantiated through any constructor. class Foo { ... var myivar = some_initializer... ... } > Not being able to reference local variables with the "this" keyword is > also a little frustrating. It means that if I want to refer to > instance variables within accessor methods then I must give the formal > parameters slightly different names. In Java I have often used a > trailing underscore on instance variables but that isn't allowed in > Scala either. This works fine as well, at least in Scala 2. Here's a tongue-twisting example: class Stuff(var stuff: String) { def stuff(stuff: String) = { this.stuff = stuff } } > Also, a convenient way of defining accessor methods for values and > variables that didn't rely on using case classes would be really nice > to have. Public vals and vars are accessible from the outside. This is also true for constructor parameters, if you put "val" in front of the parameter. class Foo(val myPublicIvar: String) { ... } > Also, a question... what happened to the Ord trait mentioned in > Programming In Scala? Has it become Ordered? I used "view bound types" > in place of the book's example that used Ord, and things seemed to > work. I guess I need to look more into views. Thanks again for > creating this awesome language. You are probably looking for the "Ordered" trait. Be aware that views are being replaced by implicit coercions. Views still work but are deprecated. Be sure to grab the "changed" document from the web site! Overall, Scala most certainly is intended to be convenient to use. It would be very helpful if you continue to post whenever you run into things like the above! -Lex |
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | "scala" script and classpaths: 00014, Lex Spoon |
|---|---|
| Next by Date: | Re: new plugin problems: 00014, Sean McDirmid |
| Previous by Thread: | Some initial suggestions (or perhaps things I don't understand)i: 00014, Nathan Sobo |
| Next by Thread: | Re: Some initial suggestions (or perhaps things I don't understand): 00014, Nathan Sobo |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |