Live data from Hacker News

Modern Java – A Guide to Java 8

github.com

151–160 of 203 posts

Re: Modern Java – A Guide to Java 8

#151
post #141

Earlier quoted context omitted.

I believe this use is a real overuse and is definitely abusing. Sure, use optional as a return type when clarity is needed, but otherwise don't do all of this when you could use a simple conditional ala: String foo = defaultValue; if (parameter != null && ...) { foo = doAAndB(parameter); }

Does that really look better to you? More understandable? Methods with the word "and" in them are really awful smells to me too. Comparing your code and mine, I ask you this: which one do you thing is more maintainable after 5 years of edits? Each time a new developer needs to add a new case, a new rule, a new whatever, on my Optional (ab)usage, they just add a new line in the appropriate spot, a .filter or a .map or…

Java does not have a full FP story, so to bastardize newer code as though it does becomes unreadable IMO. The "and" was just for the example, since "..." wouldn't have made it clear. I do not find it more readable personally, but that is a personal opinion. Because other code eagerly returns (doesn't usually bother me in an imperative language) is a different problem with code path complexity that can be addressed elsewhere. There is still a practicality in normal conditionals and traditional linear paths.

Re: Modern Java – A Guide to Java 8

#152

Earlier quoted context omitted.

In addition to the other answers, I bet it's easier for a CFG to parse knowing that "->" can't also be "negate and greater than" (since negation is only a prefix op) whereas "=>" can easily be a fat arrow or greater-than-or-equal.

Why would that be any harder? The tokens are different.

True, Java does not support => as an alternative for >= so the ambiguity does not exist. It was just a guess, but since it was probably not right, I decided to dig. This mail post[1] explains that the extra equals sign becomes a bit annoying w/ other equal signs in the same expression.

1 - http://mail.openjdk.java.net/pipermail/lambda-dev/2011-Septe...

Re: Modern Java – A Guide to Java 8

#153
post #132
post #127

Earlier quoted context omitted.

The thing that always kills me on new Java projects is wading through these enormous hierarchies of folders full of interface classes just to find one actual line of implementation code. Of course, right after that one line of implementation code there's an invocation of some other interface class that then leads me on the next goose chase to find line 2. I think it's not so much a problem of verbosity as it is this…

Hence why IDEs with their code navigation tools rule.

Yeah, I don't know. Java developers need IDEs like Rob Ford needs crack cocaine, but it's more a comment on the deficiencies of the language than the purported benefits of an IDE.

Re: Modern Java – A Guide to Java 8

#154

Earlier quoted context omitted.

I don't know how you can find even average Java code unreadable. If anything it's incredibly verbose. Only now with the most recent features is it really likely that you'll run into some one-liners and magic functions. Now, if you were talking about frameworks/app servers and not being able to figure out which levers and knobs to push to get them to behave, I would agree wholeheartedly. I'm not saying Java is good lo…

> I don't know how you can find even average Java code unreadable. If anything it's incredibly verbose. Not bad_user, obviously, but excessive verbosity can be antithetical to readability. (As can excessive conciseness.) It can make the overall structure and meaning of the code hard to discern, even though can clearly tell where what gets assigned to what variables, etc.

The verbosity not just directly affects readability by simply being longer and more to read. It also affects writeability which in combination with lazy developers (as we all are) leads to bad, unreadable, code. This is true for any language and can most often be seen on sloppy error handling, if you have to write 2x the amount of code to handle errors will you do it? 10x?

Re: Modern Java – A Guide to Java 8

#155
post #132

Earlier quoted context omitted.

Hence why IDEs with their code navigation tools rule.

Yeah, I don't know. Java developers need IDEs like Rob Ford needs crack cocaine, but it's more a comment on the deficiencies of the language than the purported benefits of an IDE.

IDEs were created for Interlisp-D, Smalltalk and Mesa/Cedar.

Were popularized in the PC, Amiga and NeXT eco-systems, thanks to Turbo Pascal, Delphi, VB, AMOS, GFA, Objective-C, Eiffel, Oberon, ...

Java wasn't even a thing in those days.

Re: Modern Java – A Guide to Java 8

#156
post #92

My Java code has improve dramatically since I started (ab)using Optionals. String foo = Optional.ofNullable(paramater) .filter(...) .map(a -> ...) .map(b -> ...) .orElseGet(() -> ...) .orElse(defaultValue) Between this kind of thing, and similar playing with Streams, some of the ugliest code I work with is suddenly quite clear, coherent, understandable.

Hear hear. A couple more features that'd be nice: - An `public Optional or(Optional other)` so if optA is empty, then `optA.or(optB)` would return `optB` - A `toStream` method on `Optional` (I believe this is coming in Java 9) or have a `Stream.flatMap` signature that flattens `Optional`s without needing to call `Optional.toStream` (Scala does this, arguable if this is an acceptable munge of Monadic types, but it's r…

Coming in java 9: http://download.java.net/jdk9/docs/api/java/util/Optional.ht...

Re: Modern Java – A Guide to Java 8

#158

so... when is this coming to android?

Support for java 8 will come with jack & jill. It might also need a new API level (24 ? ), which would seriously hamper its adoption. This is why many people see kotlin as a great thing for the future of Android (even though kotlin on android could also benefit from java 8 as a target)

Re: Modern Java – A Guide to Java 8

#159
post #64

Earlier quoted context omitted.

Good luck with your experiments. Many of us in the 90's jumped into Java, in spite of its issues, because it made it more pleasing to write cross platform code, than using C or C++ with CORBA/COM across OSes with compilers that were still playing catchup with the standards.

I never understood the following : Eiffel had a better syntax, better support for core issues, Void type, design by contract, multiple-inheritance and an intermediate virtual machine for portability although the most common target was C code. To name a few. I was using Eiffel in a small side project just about when Java released their 1.1.4 (a version before the object serialization library, iirc). It was a sticking…

Syntax is not a big deal. Ideally it should be small. If you don't like java, please don't use it. move on. Why create ugliness in java?

Re: Modern Java – A Guide to Java 8

#160
post #92

My Java code has improve dramatically since I started (ab)using Optionals. String foo = Optional.ofNullable(paramater) .filter(...) .map(a -> ...) .map(b -> ...) .orElseGet(() -> ...) .orElse(defaultValue) Between this kind of thing, and similar playing with Streams, some of the ugliest code I work with is suddenly quite clear, coherent, understandable.

Welcome to the world of functional programming =D. I personally (and professionally) suggest moving toward Scala when you feel that itch to dig deeper into FP.
Post reply on HN