Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I want more syntactic sugar in my Java! [closed]

Syntactic sugar for properties for example in C#:

private int x;

public int X{
    get { return x; }
    set { x = value; }
}

or simply

 public int X{ get; set; }

I am missing verbatim strings in java... @"C:\My Documents\" instead of "C:\\My Documents\\"

Do you agree Java needs more "sugar"? Any one knows is there is sugar coming in next Java versions?

like image 511
João Avatar asked Dec 19 '08 18:12

João


4 Answers

"Syntactic sugar causes cancer of the semicolon."

-- Alan Perlis. Epigrams on Programming.

like image 158
Diomidis Spinellis Avatar answered Nov 19 '22 18:11

Diomidis Spinellis


While I don't necessarily agree with Java's philosophy, I think that adding lots of syntactic sugar to Java would go against its philosophy. Java is supposed to be a very simple, easy to reason about language with few constructs, kind of a lowest common denominator lingua franca in the programming community. It was largely a reaction to the complexity of C++. There is supposed to be very little "magic" in it, beyond what is needed (garbage collection, mostly) to make it a memory-safe language.

If you want more sugar, etc. in a reasonably high-performance, statically typed language, I would say that Java is just the wrong language for you. You're probably better off just using C#, or maybe D.

like image 23
dsimcha Avatar answered Nov 19 '22 16:11

dsimcha


Sounds like you want Groovy... Apparently properties are on their way, although not in Java 7 (as @erickson helpfully corrected me about in a comment).

Groovy does have nice string sugar.

like image 14
Dan Vinton Avatar answered Nov 19 '22 17:11

Dan Vinton


I've also developed in both Java and C# the last few years, and find C# a superior language with regards to expressiveness and powerful language constructs. The Java language does not undergo the same degree of changes and updates as C#, atleast not at the same pace. I still don't necessarily mean that Java should be drastically updated, but we need a powerful and expressive statically typed language on the Java platform. I think Scala is going to develop into this replacement language, which we Java developers can switch to when ordinary Java does not cut it.

C# is an absolutely fantastic language; probably the "best" statically typed language these days, but Java is still in my opinion a superior platform. I like Java the platform, and I like C# the language.

like image 6
Bent André Solheim Avatar answered Nov 19 '22 16:11

Bent André Solheim