Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

7
  • 7
    Is there a reason why the Scala compiler could not look at whether the value of the assignment is actually used, and generate efficient bytecode accordingly? Commented Jan 4, 2010 at 17:52
  • 43
    It's not so easy in the presence of setters: Every setter has to return a result, which is a pain to write. Then the compiler has to optimize it away, which is hard to do across calls. Commented Jan 4, 2010 at 22:06
  • 1
    Your argument does make sense, yet java & C# are against that. I guess you are doing something weird with the generated byte code, then how would an assignment in Scala being compiled into class file and the decompiled back to Java look like? Commented Jul 25, 2010 at 17:01
  • 3
    @PhươngNguyễn The difference is Uniform Access Principle. In C#/Java setters (usually) return void. In Scala foo_=(v: Foo) should return Foo if assignment does. Commented Dec 11, 2011 at 5:57
  • 5
    @Martin Odersky: how about following: setters remain void (Unit), assignments x = value get translated into equivalent of x.set(value);x.get(value); the compiler eliminates in optimizing phases the get-calls if the value was unused. It could be a welcome change in a new major (because of backward incompatibility) Scala release and fewer irritations for users. What do you think? Commented Feb 13, 2012 at 4:28