To quote Odersky: "This convention supports the uniform access principle which says that client code should not be affected by a decision to implement an attribute as a field or method."
It makes sense if you want to implement something that may be a field but needs to be computed.
I think the idea of computed fields implemented via methods is better represented via C#-style properties, although I'd prefer to be able to access their methods directly, when suitable.
foo.Sort(x.compare _)
And Scala's getters and setters are essentially equivalent to C#'s properties: class A {
private var _x = 0
def x = _x
def x_=(value: Int) { _x = value }
}
val a = new A
a.x = 5
println(a.x)This is not an improvement, it is an unnecessary complication.
There is a simple, unambiguous rule -- () calls, no-() references. In order to... what? save two keystrokes? -- you have added a strange corner case, and then tacked on a new bit of punctuation for partial application. Though now it seems you're adding the rule that functions without parameters can't be referenced.
This takes a simple yes-or-no rule and adds edge cases for no reason. Two keystrokes on the occasional parameterless function call is not a real savings, and you've just made it harder for someone reading the code to spot all the function calls.
This fundamentally makes no sense. Why would this be a good idea?
I used scala for a while, I admit there's a whole bunch of features that can get you confused. This takes 30s to spot.
Of course, Java doesn't have method reference types. But it's an ambiguity worth bearing in mind.
foo("bar") ;
(a + b)
The semicolon is necessary for disambiguation in a case like this, but there is no reason to require the programmer to put in semicolons everywhere. I think the operator precedence hierarchy and optional parens to override it is way more complicated, but people seem to deal with it fine.This is why semicolons should be mandatory or illegal. The whole "optional semicolon" thing is a mis-feature designed by language committees that can't make a decision. One's codebase becomes a mismash of lines with and lines without semicolons, sprinkled in as magic to make the compiler happy.
There are plenty of interesting language features which are useful -- support for "optional semicolons" isn't one of them. The feature needs to die, and people should just choose to use a language that suits their need to type -- or not type -- a ';'.
I agree Javascript's "automatic semicolon insertion" is a terrible feature, but largely because the description is so hard to understand that programmers don't know when the semicolon is required.
In an expression-oriented language, like Xtend seems to be, the rule for when you need a semicolon is simple. The parser makes the longest legal expression it can, if that's not what you mean, then add a semicolon. It's no harder to understand than the lexer equivalent (the lexer makes the longest token you can, if you want to resolve the ambiguity insert a space), or the operator precedence rule (the parser will interpret infix operations using this precedence table, if that isn't what you mean use parentheses).
Matlab, for example, doesn't require commas to separate list elements, and doesn't require but allows semicolons at the end of lines, and nobody complains.
foo("bar") * a
It will parse the call to 'foo', then see the '*' which is an infix operator and parse the whole thing as a multiplication expression. In most C-like languages, '(' is both a prefix operator (for grouping) and an infix operator (for function calls). So: foo("bar") (a + b)
Is ambiguous if you don't require semicolons to separate expressions. The parser will parse the call to foo, then see the '(' and parse that as a call to the value returned by 'foo'. To stop that, you use the semicolon to stop parsing one expression, so the next '(' is treated as a prefix operator.The fact is that the visual style of a language is trivial to get used to. Breaking my text editor is a real issue though.
filetype plugin indent onAll those new "cool and innovative" languages are just rediscovering it after almost a decade of everything with C syntax.
Not that it's bad or anything, it's just my OCD tingling.
var x = 1
to (not great code, but illustrative of the point) private var _x: Int = 1
def x: Int = _x
def x_= (value: Int) = {
if (value > 1337)
throw new ArgumentOutOfRangeException()
_x = value
}
The convention is to use empty parents after zero-argument functions that have side effects, much like the ! in Scheme.This trend of trying to strip programming languages down to their "essence" is a fools errand and the pendulum will swing back eventually (not fast enough in my opinion).
obj.compute instead of obj.compute()
That seems silly. The optional semicolons also irritate me.
----------------- (Added)
I imagine a committee of Java developers, in a penthouse boardroom at Oracle, meeting with management to discuss Java's descent into disuse.
"Lets make Java more concise," suggests a senior developer.
"Yes! Lets get rid of the parenthesis like Ruby!"
"And the semicolons like Javascript."
All falls silent. Everyone stares at the programmer.
"But... But..." stammers an important board member. "I thought we needed those."
"We could make them optional."
"Yeah, we'll be multi-paradimatic like Perl!"
And so Extend was born. A cargo cult at its best.