News for hackers. Stuff that matters.
Re:Red Hat's top secret Java Killer/Successor: The Ceylon Pr... by beagle3 on Wednesday April 13, 2011 @02:34AM (#2441046)
People, please learn from mistakes of the past. Using less-than and greater-than as template parameters was a horrible idea by Stroustroup, but was copied by Java and C#.

Although C# and Java do not suffer from the craziness that is C++, by virtue of requiring a class name, e.g.

  template <boolean t> void myclass() { ... code ...};
  ...
  myclass<3>4>(); /* myclass<false>? or syntax error? */
is unique to C++ - but still, all lexing/parsing/syntax highlighting/analysis of the language is much harder because of this horrible choice.

For heaven's sake, please use {} or [] or some other character which does not also function as an infix operator.

(Even APL and K, which overload every character in fifty different ways, don't mix grouping with infix operators)

Re:Red Hat's top secret Java Killer/Successor: The Ceylon Pr... by fleitz on Wednesday April 13, 2011 @03:11AM (#2441120)
I suggest the ' operator as in

  let sum (x:'T) (y:'T) = x + y  
I have no idea why you even have to specify that a method is generic shouldn't it be generic by inference?
Re:Red Hat's top secret Java Killer/Successor: The Ceylon Pr... by beagle3 on Wednesday April 13, 2011 @03:20AM (#2441142)
If quotes are used for grouping characters (as they are in C, Java, C#, Python etc.) then this is just as bad as using <>. How can you tell if it is a character literal or a type?
Re:Red Hat's top secret Java Killer/Successor: The Ceylon Pr... by fleitz on Wednesday April 13, 2011 @03:38AM (#2441180)
I have no idea but F# does exactly that.

I'm guessing that it uses a context sensitive grammar that doesn't allow you to use string literals for variable names.

Re:Red Hat's top secret Java Killer/Successor: The Ceylon Pr... by kiiski on Wednesday April 13, 2011 @04:56AM (#2441315)
Maybe, but the problem was that "all lexing/parsing/syntax highlighting/analysis of the language is much harder because of this horrible choice". Using quotes doesn't really fix that.
Re:Red Hat's top secret Java Killer/Successor: The Ceylon Pr... by munificent on Wednesday April 13, 2011 @01:59PM (#2443392)
The problem is that you often need to decorate a generic parameter with additional information (like its type constraints or variance). If the type parameter doesn't have a singular place where it's "declared", there's no convenience place to do that. In your example, how would you specify that T must implement Summable?
Re:Red Hat's top secret Java Killer/Successor: The Ceylon Pr... by danssig on Wednesday April 13, 2011 @05:50AM (#2441429)
I'm afraid <> is too ingrained at this point to turn around, but seriously; is it such a problem? In C# a template can show up in a class like:

public class Foo<T> { ...

a method like:

public void EatAFoo<T>(...

and usage like:

var f = new Foo<int>();

someObj.EatAFoo<int>(...

I don't see how any of these cases could be confused with a greater than or less than operator. Could you expand on where the problem comes in?

Re:Red Hat's top secret Java Killer/Successor: The Ceylon Pr... by primodemus on Wednesday April 13, 2011 @10:47AM (#2442468)
The statement: F(G<A, B>(7)); could be interpreted as a call to F with two arguments, G < A and B > (7). Alternatively, it could be interpreted as a call to F with one argument, which is a call to a generic method G with two type arguments and one regular argument.

See the C# specification section 9.2.3 (grammar ambiguities) for more details: http://www.ecma-international.org/publications/files/ECMA-ST...

Re:Red Hat's top secret Java Killer/Successor: The Ceylon Pr... by riffraff on Wednesday April 13, 2011 @10:20AM (#2442295)
is this really a big deal? I wrote my share of Java code with generics and the issue never popped up, because generics are way more restricted than c++'s templates. E.g.

   myclass<3>4>  
can only be a syntax error because you can't have a value in there, inly a type name
Re:Red Hat's top secret Java Killer/Successor: The Ceylon Pr... by beagle3 on Wednesday April 13, 2011 @11:03AM (#2442539)
Ok. Still, it makes syntax highlighting and everythink lexical so much harder and ambivalent (think a<b<c>> - close paren or right shift?) with no benefit compared to e.g. []
Re:Red Hat's top secret Java Killer/Successor: The Ceylon Pr... by riffraff on Wednesday April 13, 2011 @01:05PM (#2443153)
again a syntax error, you can't have generics in an expression in which operators such as > are allowed, the java syntax is really simple and unambiguous to parse.

On the other hand, [] is used for arrays in java so it _would_ conflict with something

Re:Red Hat's top secret Java Killer/Successor: The Ceylon Pr... by beagle3 on Wednesday April 13, 2011 @05:41PM (#2444365)
See this comment above in this thread: http://news.ycombinator.com/item?id=2442468

It is a semantic error, not a syntax error (in the sense that an annotated grammar CANNOT, without semantic analysis, find that this is an error).

The example given in this comment, F(G<A,B>(7)) is syntactically ambiguous and can only be resolved to either F( (G<A) , (B>(7) ) - a two argument function call, or F( (G<A,B>(7)) ) - a one argument function call - when the types of F, G, A and B are known.

Also, things like F<G<A>> (which are perfectly legal) make lexing very hard - you can't assume '>>' is the shift right token without syntactic (and semantic) analysis. Or, you can decide like early C++ that you must write it F<G<A> > which is confusing.

Re:Red Hat's top secret Java Killer/Successor: The Ceylon Pr... by riffraff on Thursday April 14, 2011 @12:34PM (#2447437)
sorry, but are you sure a C# problem applies to Java?

AFAIK the syntax for passing type arguments to a generic method in the latter would be

   obj.<A,B>G(7)
so

   F(G<A,B>(7))
is once again unambiguous, at a syntactic level.

It would seem the java designers thought of the issue :)

Re:Red Hat's top secret Java Killer/Successor: The Ceylon Pr... by rbanffy on Wednesday April 13, 2011 @08:25AM (#2441804)
> please use {} or []

How about a Pascal-ish:

(List of Integer) l = new List();