News for hackers. Stuff that matters.
Re:Eclipse launches new language to cut down Java boilerplat... by nyellin on Friday November 04, 2011 @06:46PM (#3198020)
Parenthesis for method invocations are optional, if the method does not take any arguments.

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.

Re:Eclipse launches new language to cut down Java boilerplat... by oacgnol on Friday November 04, 2011 @06:55PM (#3198067)
That's what Scala already does: if a method does not take any args then the parentheses aren't necessary.

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.

Re:Eclipse launches new language to cut down Java boilerplat... by MichaelGG on Friday November 04, 2011 @09:08PM (#3198464)
How do you differentiate between referencing a method, and calling the method? I.e., foo.Sort(x.compare)?

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.

Re:Eclipse launches new language to cut down Java boilerplat... by ankurdave on Friday November 04, 2011 @10:10PM (#3198621)
You'd use an underscore to form a partially applied function:

    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)
Re:Eclipse launches new language to cut down Java boilerplat... by nknight on Friday November 04, 2011 @10:42PM (#3198687)
So instead of a simple, uniform rule that () invokes a function, and no-() references the function, you add yet a third syntax?

This is not an improvement, it is an unnecessary complication.

Re:Eclipse launches new language to cut down Java boilerplat... by skaalf on Saturday November 05, 2011 @12:08PM (#3200061)
That's not the same thing. You obviously use partial application only if the function takes params. And I just can't see why you'd like to pass a reference on a parameter-less function.
Re:Eclipse launches new language to cut down Java boilerplat... by nknight on Sunday November 06, 2011 @12:48AM (#3201875)
Closures don't need to take parameters to be useful, but you're missing the point.

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?

Re:Eclipse launches new language to cut down Java boilerplat... by skaalf on Sunday November 06, 2011 @01:47PM (#3203423)
There's no ambiguity when you're using closures. Concerning partial function application, you need a special syntax anyway (unless you consider all functions to be curried by default). You don't do that to save keystrokes, you omit parenthesis because "All services offered by a module should be available through a uniform notation, which does not betray whether they are implemented through storage or through computation."

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.

Re:Eclipse launches new language to cut down Java boilerplat... by barrkel on Friday November 04, 2011 @07:09PM (#3198122)
This feature, which Delphi has, can be problematic - if you're assigning a method to a method reference variable, it's not always clear if you intend to assign the method itself, or the return value of the method (which may itself be a method reference).

Of course, Java doesn't have method reference types. But it's an ambiguity worth bearing in mind.

Re:Eclipse launches new language to cut down Java boilerplat... by rayiner on Friday November 04, 2011 @07:46PM (#3198243)
There is nothing wrong with optional semi-colons. In most cases, the parser doesn't need them, and the programmer doesn't want to type them. But they're useful in some cases for disambiguation, especially in a language like Xtend that doesn't use an explicit return. E.g.

    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.
Re:Eclipse launches new language to cut down Java boilerplat... by politician on Friday November 04, 2011 @08:23PM (#3198345)
"The semicolon is necessary for disambiguation in a case like this..."

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 ';'.

Re:Eclipse launches new language to cut down Java boilerplat... by rayiner on Friday November 04, 2011 @08:55PM (#3198430)
We should also use a fully-parenthesized prefix syntax so we don't get a mishmash of lines with and without parentheses used to override operator precedence!

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.

Re:Eclipse launches new language to cut down Java boilerplat... by MichaelGG on Friday November 04, 2011 @09:10PM (#3198468)
Sorry for not understanding, but can you explain what the ambiguity is here?
Re:Eclipse launches new language to cut down Java boilerplat... by rayiner on Friday November 04, 2011 @09:32PM (#3198529)
A C-like parser will keep parsing an expression as long as it's legal. Take:

    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.
Re:Eclipse launches new language to cut down Java boilerplat... by MichaelGG on Monday November 07, 2011 @11:25AM (#3206864)
Wow, yes of course. For some reason I thought Xtend was whitespace sensitive, so just having a newline was enough.
Re:Eclipse launches new language to cut down Java boilerplat... by philf on Friday November 04, 2011 @07:06PM (#3198110)
Talking about cargo cult, they added "def" to function definitions making it more verbose actually.
Re:Eclipse launches new language to cut down Java boilerplat... by aidenn0 on Friday November 04, 2011 @11:00PM (#3198732)
That's probably to make it easier to parse with type inference, since right now it's the type name that start's a method definition
Re:Eclipse launches new language to cut down Java boilerplat... by epicureanideal on Friday November 04, 2011 @10:07PM (#3198616)
Seriously, I was thinking, WTF? Increased verbosity and then it isn't even a full word like "define", it's verbose and then abbreviated. Are they just trying to make Javathon at any price?
Re:Eclipse launches new language to cut down Java boilerplat... by theshadow on Friday November 04, 2011 @07:24PM (#3198167)
Ruby does not get rid of semicolons or brackets. Heck, you can write Java/C++ style curly brace code in Ruby if you wanted.
Re:Eclipse launches new language to cut down Java boilerplat... by vidarh on Friday November 04, 2011 @10:33PM (#3198670)
Of course, if you did write Java/C++ style curly brace code in Ruby, those of us who like Ruby would bring out the pitchforks.
Re:Eclipse launches new language to cut down Java boilerplat... by Androsynth on Friday November 04, 2011 @11:05PM (#3198754)
At least then vim would understand it and you wouldn't have to deindent every 'end' yourself. It would be nice to be able to use % and some other stuff that you get with most other languages.

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.

Re:Eclipse launches new language to cut down Java boilerplat... by clownz0r on Saturday November 05, 2011 @01:52AM (#3199066)
vim does understand Ruby. As soon as I type end, it automatically de-indents the line 2 spaces. Put this in your ~/.vimrc:

    filetype plugin indent on
Re:Eclipse launches new language to cut down Java boilerplat... by zem on Monday November 07, 2011 @04:00AM (#3205511)
also matchit.vim to do %-bouncing between keyword/end pairs
Re:Eclipse launches new language to cut down Java boilerplat... by bartwe on Friday November 04, 2011 @08:03PM (#3198291)
Making the parenthesis optional makes it harder to differentiate between taking a method reference and the return value.
Re:Eclipse launches new language to cut down Java boilerplat... by maximusprime on Friday November 04, 2011 @06:54PM (#3198061)
It's pandering to hipsters. Parenthesis are just to obvious.
Re:Eclipse launches new language to cut down Java boilerplat... by nolok on Friday November 04, 2011 @07:18PM (#3198147)
Optional parenthesis if no argument is given was already a feature of at least pascal in the seventies.

All 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.

Re:Eclipse launches new language to cut down Java boilerplat... by DanielRibeiro on Friday November 04, 2011 @07:23PM (#3198165)
Well, Ruby does go beyond this: optional parenthesis with or without arguments. Of course, no public instance variables, like Smalltalk and Scala, makes this possible.
Re:Eclipse launches new language to cut down Java boilerplat... by maximusprime on Friday November 04, 2011 @07:56PM (#3198264)
IMHO, it's less readable, and more ambiguous. Is it a variable or a function? Who knows!
Re:Eclipse launches new language to cut down Java boilerplat... by eropple on Friday November 04, 2011 @11:10PM (#3198768)
This is actually half of the value of it. It allows you to easily change the implementation without breaking the public semantics. Generally speaking, the first-pass practice in Scala is to use public fields and to make them vals (final/C# readonly). Where you need to provide mutability, you use a var. But due to C#-esque properties, you can go from

  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.
Re:Eclipse launches new language to cut down Java boilerplat... by dextorious on Saturday November 05, 2011 @02:08AM (#3199096)
Cargo cult is actually your argument, i.e thinking you need the parenthesis and the semicolons, just because Java always had them...
Re:Eclipse launches new language to cut down Java boilerplat... by hackinthebochs on Saturday November 05, 2011 @12:11PM (#3200068)
The point is removing them accomplishes little and adds ambiguity. There's something to be said about not changing things that adds no value; momentum and familiarity are valuable features, even if technically they're not needed.

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).