Live data from Hacker News

Paving the on-ramp to Java

openjdk.org

41–50 of 156 posts

Re: Paving the on-ramp to Java

#41
When i read the title, I thought they were finally going to fix gradle or improve maven. Those are the real on-ramps and they are a much bigger barrier to entry than main().

A cleaner/simpler alternative was Kobalt, but it’s now abandoned. A simple, official build tool would make the ecosystem easier to learn.

https://github.com/cbeust/kobalt

Re: Paving the on-ramp to Java

#42
post #40
post #9

Earlier quoted context omitted.

C# just went through this for C# 10, which I find a waste of resources, optmizing for "Hello World" is not what matters in large scale engineering.

It's not optimising for Hello World. It's optimising for a new student's learning experience, so that concepts can be introduced in a more reasonable order.

I beg to differ, as soon as they need a second file, import a dependency or use additional helper methods, they get to face all of it anyway.

And then there is the issue with leaky abstractions when the code that gets compiled interfers with the ideal worlds that the compiler injects, and possible confusing error messages get generated.

Like it happens with all guest languages that target the JVM pretending to be Java, and one gets a confusing stack trace only understandable by those with proper Java background.

Re: Paving the on-ramp to Java

#43

I am amused by this: > Worse, the early exposure to static methods will turn out to be a bad habit that must be later unlearned. I have been using Java since 1.0 and it is my default language. I am writing Java code today. I write functions using ‘static’ all the time. I prefer that a function be static. It shows that it does not depend on state of the enclosing object. Using ‘static’ on methods is not a bad habit. H…

You can't really mock static methods though, so it makes testing harder.

Static methods should be treated like functions. Same input same output. Keep them small. If you find yourself needing to mock them they are doing too much.

Re: Paving the on-ramp to Java

#44

I am amused by this: > Worse, the early exposure to static methods will turn out to be a bad habit that must be later unlearned. I have been using Java since 1.0 and it is my default language. I am writing Java code today. I write functions using ‘static’ all the time. I prefer that a function be static. It shows that it does not depend on state of the enclosing object. Using ‘static’ on methods is not a bad habit. H…

Couldn't agree more.

Recently I tried another take on the same idea: using default methods in Interfaces. It has nice properties, as it enables ~mixins in a way not dissimilar to what Scala provides, and enables overriding (e.g. for tests). Give it a try, it's ... refreshing :)

Re: Paving the on-ramp to Java

#45
post #43

Earlier quoted context omitted.

You can't really mock static methods though, so it makes testing harder.

Static methods should be treated like functions. Same input same output. Keep them small. If you find yourself needing to mock them they are doing too much.

>like pure functions

Small nitpick :p

Re: Paving the on-ramp to Java

#46
post #43

Earlier quoted context omitted.

You can't really mock static methods though, so it makes testing harder.

Static methods should be treated like functions. Same input same output. Keep them small. If you find yourself needing to mock them they are doing too much.

That will only work when your functions don't have side effects. So no database access, no network calls etc. You could work around that by passing in your database client as parameter but when you have a DAO class with lots of functions this quickly becomes tedious.

Re: Paving the on-ramp to Java

#47
post #31
post #17

I wonder - why he has not take it a step further and propose to get rid of return type (void) also? It would look even more slick (add optional semicolons and we will get javascript out of this :)). main() { println("Hello World"); } I know that this notation is traditionally reserved for constructors but I'm not 100% sure why we cannot differentiate between methods and constructors just by looking at class name?

I see very little gain for quite a high price here. It would break the grammar quite a bit, potentially causing even breaking changes, for something that is usually not absent even in languages that do strong type inference. The proposed changes don’t have these negatives, while still provide benefits.

It's not as bad as it seems because the language already have constructors. So instead of having a peculiar case for constructors, you unify constructors and methods by saying that void does not have to be specified.

And i do not buy your argument that it will break the grammar, the parser of javac consider constructors as methods.

Re: Paving the on-ramp to Java

#48
I have long considered that having to have the class definition explicit in the file is redundant, especially as the 2 have to have the same name anyway. Obviously if you need to `extend` or `implement` then an explicit declaration is needed. But otherwise, just defaulting to the file base name is more than sufficient.

Re: Paving the on-ramp to Java

#49

I am amused by this: > Worse, the early exposure to static methods will turn out to be a bad habit that must be later unlearned. I have been using Java since 1.0 and it is my default language. I am writing Java code today. I write functions using ‘static’ all the time. I prefer that a function be static. It shows that it does not depend on state of the enclosing object. Using ‘static’ on methods is not a bad habit. H…

You can't really mock static methods though, so it makes testing harder.

[deleted]

Re: Paving the on-ramp to Java

#50
post #43

Earlier quoted context omitted.

Static methods should be treated like functions. Same input same output. Keep them small. If you find yourself needing to mock them they are doing too much.

That will only work when your functions don't have side effects. So no database access, no network calls etc. You could work around that by passing in your database client as parameter but when you have a DAO class with lots of functions this quickly becomes tedious.

OP said:

> I write functions using ‘static’ all the time. I prefer that a function be static.

This, however, does not mean that all the functions should be static. IMHO, the more static stuff you can extract from your instance methods while keeping parameters count to max 3 (magic number that works for me), the better.

Post reply on HN