6 ms·
The verbosity in Java is soon going to be reduced by an extensive degree by the three new features included in `Java 8`, namely: 1. Lambdas: Lambdas are brief
by rms_returns 11y ago
The verbosity in Java is soon going to be reduced by an extensive degree by the three new features included in `Java 8`, namely:
1. Lambdas: Lambdas are brief and to the point, the expressions reflect the terseness of `C/C++`. In many situations, you can totally do away with interface creation by just using a lambda instead. Consider all the lines of code saved in a legacy code by just using lambdas in code!
2. Default methods: Again, `Interface patching` is a curse that a lot of Java projects suffer from. Requirements change slightly and what your typical enterprise Java dev does is add patches upon patches and layers upon layers in an interface. With default methods, you can just add default methods to your existing interfaces without affecting the ABI of your app. Again, tons of redundant code saved here.
3. Type annotations: Again, your typical Java devs have to resort to ugly hacks to place any constraints on the object properties. With type annotations, all you have to do is:
@NonNull String str;
And lo and behold! The variable `str` cannot be assigned any `null` value. So, lots of validation code being saved here again.
To the best of my knowledge, none of the above features exist in the `C#` language (yet), so I take it as a Java's edge over C#.
- danielvf 11y agoLambdas are use all over in idiomatic C#.
- paulddraper 11y agoIf by "soon" you mean a year and a half ago, then yes, soon :)
- rms_returns 11y agoI don't know what major project you are talking which uses these features. I'm not talking about small projects by John Joes, I'm talking about LARGE infrastructure projects. For example, Android SDK is extensively used in Java world, and the Android SDK has tons of Interfaces as either arguments or class helpers which can be substantially overhauled by using these features.
- SideburnsOfDoom 11y agoPlease don't move the goalposts; You stated that c# does not have lambdas, but has for 9 years now. You also asked "I don't know what major project you are talking which uses these features". As far as I have seen, and I've seen a fair amount, any and every non-trivial c# program (and many of the trivial ones too) use lambdas. Even if it's just in the small-scoped, rote use e.g. of var matches = someList.Where(item => item.x > y); Technically that counts as "using a lambda". Don't knock it for being trivial, it's a gateway drug ;)
- paulddraper 11y agoConsidering that this is a comment on an article about Forth, I don't think "major project" is even in the realm of discourse :)
- latkin 11y agoC# has had lambdas for almost 9 years. (C#3.0, 2007) https://msdn.microsoft.com/en-us/library/bb308966.aspx https://msdn.microsoft.com/en-us/library/bb308966.aspx
- ikurei 11y agoI coded in C# for a few years, used plenty of Lambdas and a handful of annotations in Class definitions. Everytime I had to go back to Java I missed them to death. I never felt like interface patching was a problem for me, may be because I'm more of a FP than an OOP programer. Type annotations do sound interesting.
- SideburnsOfDoom 11y agoI talked about c#'s lambda syntax, which Java later borrowed, below. For the other points: I have seen a little of the interface vs function conversions in modern Java, and it seems a decent enough small convenient feature in the context of Java, but it doesn't feel like a big win that I would cry out for in C# code. Defaulting to not-null and immutable values is a trend in several recent languages, e.g. from Swift and Rust to F#. This IMHO looks like a good step forward and I welcome it, however it's hard to see how this would be comprehensively added into existing languages like Java or C# with an existing legacy of not working that way. Opting into Not-null in c# has been talked about many times (1) in various forms, even implemented using attributes (similar enough to type annotations). (2) 1) http://twistedoakstudios.com/blog/Post330_non-nullable-types-vs-c-fixing-the-billion-dollar-mistake http://twistedoakstudios.com/blog/Post330_non-nullable-types... 2) http://stackoverflow.com/questions/792531/c-how-to-implement-and-use-a-notnull-and-canbenull-attribute http://stackoverflow.com/questions/792531/c-how-to-implement...