Live data from Hacker News

Modern Java – A Guide to Java 8

github.com

191–200 of 203 posts

Re: Modern Java – A Guide to Java 8

#191

Earlier quoted context omitted.

Odd that this is showing up as a jab against Java and not, say, Go.

Oh, it is very much relevant for Go, except that those of us interested in expressivity simply gave up on Go a long time ago. You see, Go is not popular enough to have users that don't like it. The people that end up trying out Go simply move to something else if they don't like it. Go's community is also strongly opinionated and has rejected any dialog for meaningful improvements. In other words the Go community is…

You misunderstand me. I find Go painfully verbose, mostly because of the elaborate if/else constructs around every single method call to handle errors. Even Java's ill-conceived checked exceptions (which can be suppressed with lombok's @SneakyThrows) are a massive improvement.

Re: Modern Java – A Guide to Java 8

#192
post #189

Earlier quoted context omitted.

Would be curious to find out what that means, since I see it repeated many times in favor of mainstream and verbose languages, such as Java. I get it to mean somehow that Java is more readable, however in my experience that doesn't make sense, as the IDE can deal with generating the boilerplate, but the IDE cannot help with readability. Not even if you include quick navigation by click, since that has been the purpos…

It means that anyone strange to the code is able to pick a pile of printouts and have a ruff understanding of the code. Which is very hard in languages that are a pile of hieroglyphics. This is very important in teams of 50+ developers, scattered around countries with high attrition rate, having various skill levels. Also generating boilerplate is just 1% of what an IDE is capable of.

The mathematical language is a "pile of hieroglyphics", yet mathematicians can speak it just fine. And in fact without their domain specific language mathematics would be much, much harder to deal with. We know this because the mathematical language in use today is newer than the discipline of mathematics and we can make a before and after comparison.

Personally I don't understand why some programmers insist on communicating only in english words. First of all because english words suffer from the problems of natural language, which is that natural language is imprecise, with the words having multiple meanings depending on surrounding context. For example when adding two numbers, should you use "add" or should you use "plus"? As it may be, "add" is actually incorrect according to its precise English definition, because the operation doesn't necessarily lead to increasing the size or amount. Yet this does not stop people from using it. Fortunately classes like BigDecimal are using "plus", yet I don't get why in the world would anybody think that "x.plus(y.multiply(z))" is more readable than "x + y * z".

You might thing picking on BigDecimal is a cheap shot. Well, how about the well known "ListUtils.union(a, b)" and why would that be better than "a ++ b". Speaking of "ListUtils.union", joining 2 lists is not a union, as union is in the context of sets or maps. Joining 2 lists is a concatenation and that matters, because concatenation is not commutative, whereas a union (of 2 sets or maps) is commutative. Basically the Apache Commons folks have got the naming wrong and if such mistakes happen in libraries that are so public, guess what happens inside corporate projects.

But much more problematic in languages like Java is not the wording as much as the way the logic is often expressed. In a functional programming language you usually get pure expressions that operate on immutable data-structures, pure as in true mathematical functions (for the same input you always get the same output). Such functions are much easier to reason about and much easier to test, because the output does not depend on some object's history (or in other words, an object's identity).

The worst and most unreadable code I've ever seen was written in Java, a language in which people often pass around mutable data-structures, like arrays, modifying them on the spot, for no good reason other than not knowing any better, in a dance of mutation that can only be considered an abomination of nature, with code so obtuse that it would make grown men cry. It's not uncommon for pieces of code to be commented with "here be dragons" with people no longer understanding what it does. Couple that with "enterprise design patterns" based primarily on IoC containers and best practices spawned from hell, with deep layers of inheritance that don't make sense and with chronic multi-threading issues and you've got a recipe for disaster. And you don't even have to search for proof for too long. Take any reasonably sized open-source project and you'll see this fact in all its glory. The last Java open-source project I interacted with is SpyMemcached and is a fine example of a Java project that works, that does its job well, that is reasonably well maintained, but that has internals that expose all the problems that I just mentioned. And sometimes I wonder why anything written in Java works at all, my guess being simply that people hit that code with the hammer until it quacks, in a process that resembles more natural evolution and mutation rather than engineering.

Therefore I'm personally dumbfounded by claims of readability. And in regards to the capabilities of an IDE, I do use IntelliJ IDEA, but I am wondering what the other 99% of its capabilities are, preferably that help with readability. Syntax highlighting?

Re: Modern Java – A Guide to Java 8

#193

Earlier quoted context omitted.

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.

Ugh, no. Skip Scala, which is on the decline and headed fast toward obsolescence, and pick a post-Scala language such as Kotlin or Ceylon.

Scala is not in decline - as far as I can see it's on the up and up. Scala has its share of warts but that comes with maturity - I would lay money that Kotlin won't look so nice when it's gone through a similar amount of change.

Ceylon OTOH is at least good design, though I don't think that outweighs the library and tool ecosystem that Scala has.

Re: Modern Java – A Guide to Java 8

#194

Earlier quoted context omitted.

I agree with you, up to a point. I find Ruby code pretty awful to make sense of with very little type information. Type inference with explicit return types for methods strikes a nice balance between verbosity and readability. I think Scala, Kotlin and to some extent C# do a better job of this than Java. There are also many less favourable cases where you see things like: Customer customer = new Customer(); String st…

Agreed, but: Animal customer = new Cat(); It makes it clear how the new object will be used. It does come up quite frequently, especially with Collection and List. Nobody was saying it is not verbose and can lead to boilerplate. The assertion is that when viewing a large code base, you are always sure of the type of value you are dealing with on a local level. If all of your objects are well defined, you don't even n…

That's there if you want it though.

    val customer = new Cat(): Animal
I can see arguments against inter-method type inference, but I think there's no real argument against type inference within a single method (requiring explicit types on method boundaries). If you have a billion-line method you have bigger problems.

Re: Modern Java – A Guide to Java 8

#195

Earlier quoted context omitted.

IMO Java doesn't shine anywhere. It's statically typed, but lacks support to be flexible. Thus many Java programs rely on reflection at runtime or casting. This negates all of the benefits of static typing, turning the language into a dynamic one. The main choice is then either Clojure or Scala. This comes down to dynamic versus static type checking. With a dynamic language, one is significantly less sure if a progra…

> Scala provides the best support for strong, static typing on the JVM I'd argue that Ceylon and Kotlin offer most of Scala's advantages with none of its baggage and bloat. And drama.

All those things will come as those languages mature, and until then neither has much library or tool support.

Re: Modern Java – A Guide to Java 8

#196
post #86

Earlier quoted context omitted.

I have been using Java since the first beta, and have written a large pile of Java books (pun not intended), but I too prefer Clojure as a practical, simple to use and simple to read language. That said, Clojure / Java interop is really nice. I frequently find myself simply adding existing Java code to my lein project file. I would suggest just keep using Clojure and when it makes sense, mix in Java when you want or…

This might sound like a snarky comment but it is actually not. If you want a dynamic language on the Java platform; then why not use JavaScript? There is an easy-to-use engine in Java 8 and JavaScript is widespread and somehow familiar to Java-developers.

JavaScript is just not a nice language to maintain - bizarre scoping, confusing inheritance model, extremely clunky syntax, confusing standard data types. Being "dynamic" isn't a feature so much as an acceptable cost, but JavaScript doesn't really give me any expressibility advantage over straight Java, yet alone compared to Scala.

Re: Modern Java – A Guide to Java 8

#197

Earlier quoted context omitted.

Two things. First, why is it better than: String foo; if (parameter != null) { foo = ... ; } else { foo = defaultValue; } or even this, if you express all your transformations as a single expression: String foo = parameter != null ? ... : defaultValue I don't get it. Your way of doing seem awfully more verbose. Please note that I'm not against Optional in general (although they are overplayed in my opinion). Second t…

Actually, your way is awfully more verbose, but you didn't notice it because you ellipsized the verbosity. If you actually take the time to translate OP's code with your own, you will soon find yourself indented six levels with "if (a != null) { ... if (b != null) { ... if (c != null) {... You get the idea. Monads (the type class that Optional belongs to) flatten all this boiler plate with a function called... flatMa…

Point taken. I'll tentatively argue if all your functions can return null you have other problems to contend with, but what you said makes sense.

Re: Modern Java – A Guide to Java 8

#198
post #195

Earlier quoted context omitted.

> Scala provides the best support for strong, static typing on the JVM I'd argue that Ceylon and Kotlin offer most of Scala's advantages with none of its baggage and bloat. And drama.

All those things will come as those languages mature, and until then neither has much library or tool support.

No tool support?

Kotlin and Ceylon both have very good IDE plug-ins that already work much better than Scala, despite Typesafe pouring a lot of money into their own plug-in.

Re: Modern Java – A Guide to Java 8

#199
post #195

Earlier quoted context omitted.

All those things will come as those languages mature, and until then neither has much library or tool support.

No tool support? Kotlin and Ceylon both have very good IDE plug-ins that already work much better than Scala, despite Typesafe pouring a lot of money into their own plug-in.

There are a lot more tools in the JVM ecosystem than just IDEs, and by now most of them have Scala support.

Re: Modern Java – A Guide to Java 8

#200

Earlier quoted context omitted.

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.

Ugh, no. Skip Scala, which is on the decline and headed fast toward obsolescence, and pick a post-Scala language such as Kotlin or Ceylon.

Definitely not true. Scala is at its strongest ever. It's now possible to write frontends, backends, and mobile applications in Scala. There's an incredibly diverse and growing ecosystem of libraries. The Scala tooling has really stepped up.

The fact that there's so much discussion on the new SIP (Scala improvement process) and SLIP (Scala library improvement process) issues is a testament that Scala is alive and well. This is what happens in a mature language: many people put stakes in the ground.

Also, Scala most certainly has a bright future to go with its vibrant present. EPFL is hard at work with dotty, which will be a simplification and improvement of Scala.

Post reply on HN