IssueRaiser

As alluded above, the biggest problem with the constructor syntax in languages that borrow from C++ is that in the common case of a class...

As alluded above, the biggest problem with the constructor syntax in languages that borrow from C++ is that in the common case of a class with just one constructor, the parameters of that constructor aren't available in the body of the class, leading to awful code like the following: class Point { public float x; public float y; public Point(float x, float y) { this.x = x; this.y = y; } public String toString() { return "(" + x + ", " + y + ")"; } } This hurts. Fortunately, we've already made that pain go away in Ceylon. Well that seems like a laudable goal. Let's take a look at the example code, then, to see what the alternative is: class Color { shared Integer rgba; &#x2F;&#x2F;default constructor shared new (Integer rgba) { assert (0 <= rgba <= #FFFFFFFF); this.rgba = rgba; } ... string => "Color { \ alpha=``hex(alpha)``, \ red=``hex(red)``, \ green=``hex(green)``, \ blue=``hex(blue)`` }"; } Maybe it's just me but it looks like the pain is still there?

Posted by couchand on Jun 22, 2015, 12:15 PM

Tags

Related issues

Raise real-world problems, find people facing the same issue, and discuss solutions.6,000 issues0 comments

hackernews (Other)

As alluded above, the biggest problem with the constructor syntax in languages that borrow from C++ is that in the common case of a class...

couchandJun 22, 2015, 12:15 PM

As alluded above, the biggest problem with the constructor syntax in languages that borrow from C++ is that in the common case of a class with just one constructor, the parameters of that constructor aren't available in the body of the class, leading to awful code like the following: class Point { public float x; public float y; public Point(float x, float y) { this.x = x; this.y = y; } public String toString() { return "(" + x + ", " + y + ")"; } } This hurts. Fortunately, we've already made that pain go away in Ceylon. Well that seems like a laudable goal. Let's take a look at the example code, then, to see what the alternative is: class Color { shared Integer rgba; &#x2F;&#x2F;default constructor shared new (Integer rgba) { assert (0 <= rgba <= #FFFFFFFF); this.rgba = rgba; } ... string => "Color { \ alpha=``hex(alpha)``, \ red=``hex(red)``, \ green=``hex(green)``, \ blue=``hex(blue)`` }"; } Maybe it's just me but it looks like the pain is still there?

Comments (0)

No comments yet. Start the discussion.

Comment on this issue