r/java • u/Plethura • Jun 01 '20
Love it or hate it, Java continues to evolve
https://www.azul.com/love-it-or-hate-it-java-continues-to-evolve/18
u/wildjokers Jun 01 '20
The only two things I really wish Java had are multiple return values from methods and default parameter values. I miss those two things on a daily basis. Named parameters would be nice but I don't miss that one near as much as the other two.
It is really a great language and the ecosystem is of course outstanding.
15
u/couscous_ Jun 01 '20
Records should make it easier to return multiple values. Declaring them is just a single line.
4
u/meamZ Jun 01 '20
Either multiple return values or even tuples (basically like an anonymous struct) so that you could just return a tuple of say (String, int, MyClass) or something like that.
3
u/BoatRepairWarren Jun 01 '20
While not really the same and much more limited, I find myself using Map. Entry as return type sometime
1
u/meamZ Jun 02 '20
I mean that's basically abusing this type. You could easily write a pair class yourself.
2
u/SomervillainSB Jun 01 '20
I agree. Java has solutions for multiple return values, like records or generic Tuple classes, but other languages do it better.
I wonder why they never did named parameters or default values (even JAX-RS has that). It seems like an easy thing that would make life easier. I greatly prefer constructors and because people think they're confusing (& reasonably so), most default to setters, which are far more error-prone. I image named parameters in the constructor would make both sides happy.
6
u/pron98 Jun 01 '20
I wonder why they never did named parameters
Search for "named invocation" here. It might well be coming, combined with "reconstructors", i.e. the ability to copy a record and change only some of its components.
or default values
This is much more problematic (+ follow-ups).
1
u/JavaUserr Jun 02 '20
From the default values tweets:
The problem is not backward compatibility; that's fine. The problem is _migration compatibility_, and how it interacts with overload selection. (Suppose you have a method with 10 optional params. Then you add an 11th. What happens to old (binary) callsites? LinkageError?)
Can anybody explain what he means here? It sounds to me that he is asking what happens when you change a jar with a newer version of that jar. And then wonders what would happen if you try to run it. If thats what he means then I'm perfectly fine with a LinkageError for stuff that doesn't exist. What a crazy thing to do.
(And similarly: suppose you have `
foo(int x, int y = 0)` and `foo(int x, float z = 0.0f)`, and the user does: `foo(x: 0)`. What overload do you select?)This is the same as writing
foo(int x)twice in the same class. When you do that you get a compile error;foo(int)' is already defined in 'YourClass'. Seems fine to me.1
u/yoshord Jun 03 '20
Lets assume a class that currently has a
int foo(int x, int y)method and aint foo(int x)method whose implementation is exactlyreturn this.foo(x, 0). This is an obvious candidate to be migrated to one method with default parameters:int foo(int x, int y = 0). Intuitively, this should be a compatible change; however for the change to actually be compatible with previously-compiled bytecode, the jvm would need a way to link the oldfoo(I)Icalls to the newfoo(II)I with defaultsmethod. And the obvious "have the compiler write a syntheticfoo(I)Imethod" feels inelegant and probably gets worse when a method has more default parameters.1
u/JavaUserr Jun 03 '20
I think this is a different argument than what Brian Goetz was saying. But also with this argument I just don't see it. The obvious solution as you say is to have the compiler generate synthetic methods. Perhaps that feels inelegant to you but isn't that what we are doing with records? I define a few fields and the compiler gives me a class with synthetic constructor and accessor methods.
The other solution I see is storing the default along with the method. Then when you compile the code you rewrite the caller to insert the default where needed. You wouldn't have any synthetic methods.
1
u/Jonjolt Jun 01 '20
I'm pretty sure it has the capabilities as the byte code calls the method by name, parameter, and return type. The compiler puts in a synthetic bridge method that return's object on generic return types
if you had a class like:
class A implements Supplier<String> { public String get(){ ... } }The byte code would be:
public get()Ljava/lang/String; L0 LINENUMBER 6 L0 ACONST_NULL ARETURN L1 LOCALVARIABLE this LA; L0 L1 0 MAXSTACK = 1 MAXLOCALS = 1 // access flags 0x1041 public synthetic bridge get()Ljava/lang/Object; L0 LINENUMBER 3 L0 ALOAD 0 INVOKEVIRTUAL A.get ()Ljava/lang/String; ARETURN L12
17
u/egahlin Jun 01 '20
I've never heard complaints about C or C++ being verbose, even though they are much more so than Java, for example header files, include guards, and lack of default initialization.
28
u/BEgaming Jun 01 '20
Although it's a pleasant read, i would have liked that you pointed out that this article is a year old. I didn't notice it until the last paragraph about jdk 13. I assume (apparently wrongly) that posted articles are fresh new articles.
7
u/bondolo Jun 01 '20
Ignore the haters, it is unlikely they will ever be satisfied or ever change their minds. Focus on bringing joy to those who already use java and probably already like it.
4
u/renatoalencar Jun 01 '20
Nowadays, the only main issue I see with Java is actually Oracle throwing the IP bullshit everywhere. Java is a powerful and actually awesome language if you know how to write readable code.
12
u/pron98 Jun 02 '20 edited Jun 02 '20
Oracle completed open-sourcing the entire JDK, and made Java 100% free and open and unencumbered by field-of-use restrictions for the first time in Java's history.
1
u/ryosen Jun 02 '20
Use OpenJDK instead. No Oracle. No problem.
2
u/pron98 Jun 02 '20
OpenJDK is the name of Oracle's implementation of Java.
2
u/ryosen Jun 02 '20
OpenJDK is an open source version of Java. Oracle provides a build of OpenJDK and contributes to the project, but OpenJDK is not “Oracle’s implementation”. There are several builds of OpenJDK available from different entities including IBM, Red Hat and Microsoft.
7
u/pron98 Jun 02 '20 edited Jun 02 '20
OpenJDK is the name of the one and only Java Platform project done at Oracle (and I know, because I work at Oracle on OpenJDK). Yes, it is open-source -- Oracle completed open-sourcing the JDK, making it 100% free, open, and free of field-of-use restrictions for the first time in Java's history -- and other companies certainly contribute (Red Hat and SAP contribute quite a bit of great stuff, Intel and Google also, Microsoft has just started contributing small bits, IBM -- not so much) and many produce builds (including the OpenJDK builds by Oracle and the Oracle JDK), but Oracle does >85% of the work and provides the vast majority of funding. Oracle also chairs the OpenJDK board, and the platform architects are Oracle employees. You might also want to scroll down on the OpenJDK website, or read the OpenJDK license which is issued -- whether you download a build from Oracle, Red Hat or Amazon -- by Oracle.
For more on OpenJDK's governance, watch this video by Mark Reinhold, the OpenJDK lead (the head of the OpenJDK project) and the Chief Architect of Oracle's Java Platform Group.
So OpenJDK has "no Oracle" unless you count most of the leadership, the vast majority of work, and the license.
2
3
u/6510 Jun 01 '20
All this progress is great to see. The controversial modularization project seemed to cause other work to stall for some time while they sorted that out internally. However, with that behind us now the project has added features rapidly both to the language (like "var", switch expressions, text blocks etc) and to the JVM (CDS, ZGC, JFR and so on). And there's reason to hope we'll see a Kotlin-like non-nullability feature one day. Also value types is making good progress, which has obvious important use cases, but requires a ton of JVM-level work.
6
u/pron98 Jun 02 '20 edited Jun 02 '20
The controversial modularization project seemed to cause other work to stall for some time while they sorted that out internally. However, with that behind us now the project has added features rapidly
The more intensive work on new features is largely because of the "controversial modularization project," which allowed to reduce the maintenance burden of the JDK and divert resources to new work. And there are more significant dividends of modularization coming down the pike. It was like tearing up the street to lay in new cable ducts. It brought noise and dirt with little immediate benefit, but now you can upgrade your internet service much more easily.
5
u/ObscureCulturalMeme Jun 01 '20
I love the language, at least the language that it's now become. Ten or fifteen years ago, it was earning a big sigh and a "meh" shrug from me, but now it's quite solid. I'm glad of the evolution.
I hate the tools and the ecosystem.
2
2
Jun 02 '20
As someone who prett much only used JS now, I love java. I’m a huge fan of strongly typed langaues, I should probably check out TS
3
Jun 01 '20
I’ve seen a lot of questionable Java code. It was mostly because of developers with poor skills and/or people being rushed to do code. I’ve definitely met many java developers who just don’t want to learn anything else and don’t want to learn anything new.
Other than that I’d be comparing Java to something like Go which is less verbose, compiles super quickly, and has more useful errors. I can work with Java, I just don’t want to work with poorly written struts or your legacy crap with XML.
16
u/couscous_ Jun 01 '20
which is less verbose
I found golang to be more verbose. I think it gives the illusion of being less verbose because they use single letter variable names everywhere (which makes code less readable). Otherwise, it's
if err != nileverywhere, and multi-line one off functions that amount to nothing more than map/filter/etc calls that can be done in a single line in Java.more useful errors
Errors in golang are just strings, no stack trace, etc. They're quite horrid honestly.
6
u/_INTER_ Jun 01 '20
Go has a reputation for being a simple language. However when I dabbled in it for a while I was quickly overwhelmed by reading and placing all those punctuation, stars and brackets at different positions. Is this Perl all over again? Found it really complicated. I must be dumb.
2
Jun 01 '20
One line variable names piss me of endlessly. I can’t speak for other’s code bases. I’ve seen that anyone can make code more convoluted than it has to be.
1
u/freezerburnv Jun 03 '20
Errors are most certainly NOT just strings. The Error interface has a method that returns a string, yes, but there are a ton of implementations of the Error interface. (which include libraries that put stack traces into them, among other things)
Figuring out what kind of error you have, however, is much more convoluted. Especially when considering nesting errors inside other errors. (hence the As and Is functions provided in the stdlib errors package now, so long as the error type provides support for them)
3
u/couscous_ Jun 03 '20
So they're basically re-inventing exceptions, except in a more verbose, more cumbersome, more error-prone, and less performant way.
1
u/freezerburnv Jun 03 '20
Exceptions came after C-style error checking, so technically exceptions were the ones that re-invented error handling :)
On a more serious note: it’s more verbose and might take more time on the “happy” path, but the nice thing about error returns is that you know what stuff has error conditions. The bad part of exceptions is not knowing where it’s possible for one to happen. (Go still had the panic mechanism which acts as a kind of exception mechanism, but it’s generally reserved for cases where there’s a programmer error versus something happened that can be dealt with as part of normal operation of the code, whereas exceptions don’t tend to have that distinction and make normal operation of the code “harder” to deal with. An example being a file not existing which is an exception in Java but an error return value in Go. The error return value I’ve felt is a bit easier to deal with in a nice way. But that’s personal opinion at that point)
I don’t think either method is necessarily the “correct” or “best” way. They each have their own issues, gotchas, nice points, etc. It really comes down to which way a language wants to implement, and how the implementation works.
2
u/couscous_ Jun 03 '20
The issue is that error codes (at least how golang does them), are very error prone. I've worked on larger golang code bases, and I've seen several times errors being ignored, either on purpose, or accidentally (and there are several different ways where errors can be ignored accidentally). This would not have happened in a language that uses exceptions (you'd have to opt-in to swallowing exceptions via
catch (Exception e) {}). Now you have errors silently propagating in your system corrupting state. Much worse than dealing with exceptions at any level.7
u/helikal Jun 01 '20
Go is quite old now. It just feels young because not much ever became of it.
3
0
Jun 01 '20
[deleted]
4
2
4
u/SomervillainSB Jun 01 '20
Some issues are technology problems, some are HR issues. If your company hires low-end contributors, you will see horrendous code, no matter the platform.
However, I work for a big tech company that invests in Java, JavaScript, Python, C, etc. If you think the Java is bad...wait till you see the JavaScript and Python produced by the same cohort.
At least compilation will catch the most egregious errors. I have never felt as much pain as the time I inherited a NodeJS application from someone who left the company and I had to get its libraries in compliance. So many weeks of subtle runtime bugs....half of which would have been caught be a compiler...most of the remaining would have been caught quickly with basic unit tests in a compiled language. However, mixing the 2 meant several weeks of QA finding some new edge case.
So yeah, Java is not as fashionable as it used to be. However, having worked with JavaScript, Python, and Java...I have to say, the Java experience is the smoothest. I get that OOP ceremony is tedious, but it really pays off when the application is a success and changes hands when the original author leaves or gets promoted and it's inherited by someone who is granted a 2h handoff meeting and then thrown to the wolves.
1
Jun 01 '20
I worked at a company where most of the work was in Java with spring and JavaScript in React. The JS was better simply because there was a wider group of senior people blessed to give people feedback in PRs and help with issues that were brought up. I won’t claim it was the tech itself that made Java worse at that company although we did have the issues with Java developers not wanting to learn anything new.
1
u/znlsoul Jun 02 '20
Speaking of “legacy” languages, https://www.inputmag.com/tech/ibm-will-offer-free-cobol-training-to-address-overloaded-unemployment-systems
-4
Jun 01 '20
It is evolving, but do people choose Java for new projects? We have long switched to Kotlin for new services and it's been fantastic.
24
u/andrewharlan2 Jun 01 '20
I have Kotlin experience. I would absolutely still choose Java for new projects.
11
u/woodland__creature Jun 01 '20
Anecdotal testimony here, but I'm working on a greenfield legacy replacement in Java for a financial company. I've been interviewing with multiple financial institutions that are filling out teams to work on their own greenfield legacy replacements to be written in Java.
In my experience this sentiment that Java is effectively a dead/dying language is pretty unfounded.
2
u/saecki Jun 01 '20
Just curious, what advantages do you see in java vs kotlin? To me kotlin seems like java with syntactic sugar and some neat additional features. Am I missing something?
17
u/andrewharlan2 Jun 01 '20
Java is a joy for me. I love reading well written Java and I like producing it. Kotlin doesn't solve any problems I have with Java.
When I do Java code reviews I can read it and tell what it's doing. I have to patch Kotlin code reviews locally and use my IDE to tell what it's doing. Other engineers on my team have told me that they prefer reading my Java than the Kotlin of others.
Tools support Java better. It compiles faster than Kotlin.
I can go on
2
u/Farconion Jun 01 '20
well that's the thing, even if you need java for a specific reason - you can still intertwine Java code with Kotlin code pretty easily right?
4
u/_INTER_ Jun 01 '20
We for one would never use a Kotlin library in Java (or a library from any other language). Unless there's absolutely no choice. That's why we threw out OkHttp for example.
In Kotlin on the other hand we'd use Java libraries on a daily basis (but still trying to minimize it there aswell).
1
10
Jun 01 '20
I would choose java over kotlin. Kotlin doesn’t seem like a big enough improvement to make the rolling switch, especially as java is consistently improving every 6 months. If I want a more elegant language to mix in with java I would use clojure.
3
u/lordmyd Jun 01 '20
I don't get this one. Surely the only reason to reject Kotlin is if you're set on using pure Java everywhere. Java and Clojure are worlds apart whereas Kotlin we designe with Java interop as a priority.
0
Jun 02 '20
you can't really start using these features in production unless it's an lts release though and that doesn't happen every 6 months. this or if you dont forget to switch to an lts jdk once it's out
4
u/neofreeman Jun 01 '20
Have used Kotlin recently on a pretty large project. Code reviews are so much better without the IDE vomit code and nicer comprehensions. Java has started taking up features like data class as record now, but by the time they will release rest of features on LTS I wonder where Kotlin will be by that time. No offense but I will pick Kotlin any day over Java for now.
-9
u/BlueGoliath Jun 01 '20
From a personal perspective, one of the most powerful features of Java as a development language is its readability. I think most developers will agree that code is more frequently read than written. All developers, at some time, will have to maintain someone else’s code. The easier it is to understand, the easier it is to address bugs or make enhancements. I once had to work on an application that had been written in Perl. It wasn’t that big an application, about eight-pages printed out, but I rapidly concluded that Perl, with its incredibly dense syntax, was a write-only language. Verbosity is not always a bad thing!
That's funny, because all people do is complain about Java's verbosity. Hell, JDK developers are adding features to undermine important contextual verbosity by introducing features such as var.
36
u/GuyWithLag Jun 01 '20
all people do is complain about Java's verbosity
Those people haven't been airdropped into a
hostileunknown codebase and told "fix this bug by 2300 tonight".Trust me, verbosity is a feature, not a bug.
10
u/thatwombat Jun 01 '20
The verbosity of Java is one of the reasons I like it. The use of ‘var’ makes it harder to read and debug. C# did that and I hated it.
They tried to borrow a page from JS and it just doesn’t work. Python has a similar problem but at least you can put hints for return types.
10
u/BlueGoliath Jun 01 '20 edited Jun 01 '20
Don't tell /r/java that, holy shit.
Forget codebases, I've had to copy/paste JDK API documentation examples into an IDE just to figure out what the hell a method is returning!
According to JDK developers you're supposed to be able to mentally map the actual type using local reasoning(AKA good method/variable names), but it's a bunch of bullshit that JDK developers don't even follow.
Like, WTF is this method? So if someone wrote code using it with
var, it'd look something like:
var list = <MODULE_READER>.list();Wow, so clear. 10/10.
21
Jun 01 '20
var is meant to be used to reduce obvious boilerplate code for better readability. For example, instead of
ReallyLongDescriptiveFactoryBuilder builder = new ReallyLongDescriptiveFactoryBuilder();You could just do
var factoryBuilder = new ReallyLongDescriptiveFactoryBuilder();8
u/sievebrain Jun 01 '20
So don't use it for those cases.
Talking of banning var is silly. What are we, C++ coders? When to omit local types is no harder or more complex a decision than variable or method naming, and is a much easier decision than how to structure an app properly. I'd say it's about the same level of difficulty as writing good comments. Will many devs get it wrong? Yes. Is the solution to ban it entirely - not in my view. This is the sort of thing a clear chain of command and a senior developer with good taste in charge of a team can quickly solve.
In Kotlin types are omitted all the time but done well it doesn't impair readability, because:
If the return type isn't obvious, you can just push a couple of keys in IntelliJ to put the type in (or take it out when it's superfluous).
The IDE can insert synthetic text with the inferred types anyway (which the cursor skips over), so people who like to always see the type can easily get that, and people who prefer to reduce the visual load can disable it. You can also toggle it on and off quickly. Not sure what the type is at that point? Just use alt-enter and ask the IDE to put the type in the source. Done: no harder than fixing a typo in a comment.
The main reason to think about this at all is for users who don't want the types automatically inserted by their IDE, or who are viewing code outside the IDE. The main reason to do that is in code review tools - IntelliJ can now integrate with GitHub pull requests in the latest EAPs, so soon there'll be one less reason to read code outside of an intelligent environment.
You get into the habit of thinking about how obvious a type is pretty fast. Yes it takes a bit of practice and new programmers may need guidance. But you'll have to do that anyway, it doesn't add anything new.
2
u/Necessary-Conflict Jun 03 '20
What are we, C++ coders?
Actually C++ introduced the var's equivalent (auto) way before Java:
https://stackoverflow.com/questions/7576953/c-auto-keyword-why-is-it-magic
2
u/sievebrain Jun 04 '20
That's true but I was referring to the common practice in C++ codebases of banning lots of language features via their style guides. For instance it's common for C++ programs to ban exceptions.
3
u/_INTER_ Jun 01 '20
We use Java 11 for a while now and you could search "var " in our codebase and find no result (20 devs, seniors and juniors). It's not forbidden to use it, but nobody does. Certainly it takes a while to get used to new features and nobody wants to be the first to introduce it and "break" consistency. But there are also also other reasons at play. The devs I talked with have mixed feelings about it and are wary of
var"everywhere".Just recently I thought about using
varfor some intermediate variables but decided against it because it doesn't hurt to see the type even in those situations.In places where with
varwe would not loose visual information - like constructors - it would still hinder the reading flow a bit because the eyes would have to move to the right side more.Another factor is my workflow. I start typing the first letter of a type and the rest is semi-auto generated by the IDE.
3
u/Tilkin Jun 01 '20
We're about to switch to 11. I still remember how people (myself included) wrote Streams in the first release. I can't help but feel like misunderstanding of the right time/place to use
varwill happen.2
u/hippydipster Jun 01 '20
Another factor is my workflow. I start typing the first letter of a type and the rest is semi-auto generated by the IDE.
So often not even that. Usually, I write something like obj.doSomeThing(); and then I have the IDE create my local variable from it, which automatically includes the type. So actually the workflow is:
type:
obj.dosIDE finishes for me:
MyFoo foo = obj.doSomething();3
u/Necessary-Conflict Jun 01 '20
Another factor is my workflow. I start typing the first letter of a type and the rest is semi-auto generated by the IDE.
Basing anything on the writing workflow is wrong because the main objective is to write readable code, and not writable code. If your workflow is optimized for writing speed, then you should add a refactoring step to your workflow, to make the code readable.
2
u/_INTER_ Jun 01 '20
You're absolutely correct. It's just another factor I threw in. The current workflow I have I feel produces readable code, so ...
1
u/chambolle Jun 03 '20
Nobody says that anything is based on the writing workflow.
car may sometime improves a little bit the readibility, but most of the time it degrades it.
var v=obj.value();
is very informative...
for me var is similar as the overload of the assignment operator (i.e. =) in C++. C++ introduces a lot of new stuff and at end : the guidelines are 300 pages long... Come on! This is not serious
1
u/Necessary-Conflict Jun 03 '20
Well, I use var when it improves readability, and I don't use when it doesn't. Nobody said that you should use vars everywhere. This is very simple, and not "a lot of new stuff".
1
u/chambolle Jun 04 '20
the problem is that you are not alone in the world. One rule is :"programs should prevent themselves against bad usage". var violates this rule because it can be misused
1
u/Necessary-Conflict Jun 04 '20
Any feature can be misused. In that regard, "var" is the least dangerous feature, because if you encounter it in a codebase, and the type is not obvious, it is very simple to ask your IDE to show the real type. There are much worse features available to bad programmers, which can make the code really hard to understand.
1
u/pushupsam Jun 01 '20
Indeed var is a mistake. We decided to ban using it. The real problem is that everybody has different opinions on when it's okay to use var and when it isn't. The result is long, silly discussions in code reviews where two-or-three people will strongly feel that var is being used correctly or abused.
It's easier to just to ban it everywhere. No more silly discussions.
It seems like if you introduce a new language feature and then immediately have to write Style Guidelines ( https://openjdk.java.net/projects/amber/LVTIstyle.html ) about when to use it and when not to use it, you're really not helping. That ways lies C++ madness.
3
u/suddenarborealstop Jun 01 '20
What’s the issue with var? Serious question: is it due to the way java handles generics? As in, the compiler may assign the correct type,but not the most correct type?
10
u/ArmoredPancake Jun 01 '20
var list = <MODULE_READER>.list();
What is the return type here?
7
u/OctagonClock Jun 01 '20
Aside from it obviously being a list, or one Jump to Definition away, this is a problem that has been solved by IDEs. When languages stop catering to text editor devs, the world will be a better place.
1
u/_INTER_ Jun 01 '20
Aside from it obviously being a list
Peep... wrong, it's not a list.
10
u/OctagonClock Jun 01 '20
So the method name is wrong. If I saw
NotAList list = thing.list()I would also be confused at the obviously wrong code. No idea whyvarchanges this.7
u/_INTER_ Jun 01 '20 edited Jun 01 '20
So the method name is wrong. If I saw NotAList list = thing.list() I would also be confused at the obviously wrong code. No idea why var changes this.
The method name is not wrong. A method should not have to explain what it returns but tell what it does and what it is for. The method does "list" as in action not as in return-type. Though something like
listContent(),streamContent()or simplycontent()is arguably better.Otherwise you would have to call it
streamOfStringToList()which would be pretty dumb to be honest and juststream()doesn't cut it either because it would be confusing what exactly it does as a method ofModuleReader.The same goes for variables by the way:
Set<Person> johns = byName("John"); // good Set<Person> persons = byName("John"); // bad Set<Person> setOfPersonWithNameJohn = byName("John"); // bad Set<Person> johnsPersonSet = byName("John"); // bad Set<Person> johnsSet = byName("John"); // bad Set<Person> johns = byNameReturningSetOfPerson("John"); // bad Set<Person> johns = personSetByName("John"); // bad var johns = byName("John"); // ok, but what type is johns? Need to investigate var persons = byName("John"); // bad var setOfPersonWithNameJohn = byName("John"); // bad var johnsPersonSet = byName("John"); // bad var johnsSet = byName("John"); // bad var johns = byNameReturningSetOfPerson("John"); // bad var johns = personSetByName("John"); // bad→ More replies (0)4
u/hippydipster Jun 01 '20
Names are not types and any argument that starts "well the name should tell me the type" is wrong from the start.
1
u/notfancy Jun 01 '20
The path to enlightenment begins when you realize that it doesn't really matter. Hindley-Milner is the Pure Land.
1
0
u/couscous_ Jun 01 '20
Why does it matter? I'll just look at how it's used (say in a for-each loop or if
.mapis called on it, etc. That's all I care about. Also, the IDE will show you the type in a couple of key-presses.4
u/moremattymattmatt Jun 01 '20
Having switched to typescript for the last couple of years, implicit typing like var in java is not the huge issue some people make it out to be. It works fine but needs a bit of practice to get right as it's a judgement on whether or not to make the types explicit.
3
u/murkaje Jun 01 '20
var maybe helps speed up reading simple code at the cost of making complex code harder to read due to extra mental overhead(have to look up var-s type and remember it). When you have to remember 50 different things and keep forgetting some of them then code reading grinds to a halt. The cost is generally not worth it and a blanket ban is justified to reduce long discussions in code reviews.
The general mistake i believe is some think reading(understanding) speed has a strong correlation with character count when it's rather information density of which context is an important part but is not strongly represented by character count. I can read "var" fast, but understanding what it's about takes extra effort, especially with badly named methods, while reading "InputStream" is more clear as it narrows down on what it does and can be used for.
2
-15
u/Mordan Jun 01 '20
I banned VAR.
VAR is for script noobs who don't understand what programming is about.
VAR exists because of howling blood thirsty suckers who keep saying Java is dead every single year and needs to evolve.
Now it evolves but not always in a good direction.
7
Jun 01 '20
And you are a Real programmer?
-4
u/Mordan Jun 01 '20
haha I knew i would get some downvotes from triggered overly lazies. But I stand my ground. Var is bad. It hides the Type. Which is always bad when reading.
No I use an IDE. That's good laziness. So I don't use a text editor.
Var is bad laziness.
4
u/Necessary-Conflict Jun 01 '20
Well, I take the extra step to refactor "typed" code to "var" code - not everywhere, only if it improves readability, for example when the type is already included in the variable name, or it is obvious for other reasons.
I might be wrong, but certainly I am not "lazy".
4
u/meamZ Jun 01 '20
So yould say var test = new MyClass(); "hides" the type? While it's technically true i can see with one glimpse what type it actually is...
-17
u/pushupsam Jun 01 '20
Java is evolving in all the wrong ways, frankly. It's very unfortunate but I've accepted it and these days I advise most teams stuck on Java 8 to not upgrade to Java 11 and look elsewhere. I've said it before but there's something wrong with the language leadership. There are certain features Java developers really need, features that would dramatically include quality of life like:
First-class properties.
Named parameters.
Non-nullable references.
These are little things, frankly, some might even dismiss them as "syntactic sugar" but they would dramatically increase the coding experience without compromising on the maintainability of large codebases. But the guys at Oracle don't give devs the stuff they've been asking for and, frankly, these actually-useful-and-desirable features are probably never going to come to Java. Instead we get:
var -- which we've banned from most codebases because everybody has different ideas about when it should be used.
The total shitshow that is JPMS
And now records.
This is all leading towards a new "stuctured data/record" programming style [see https://www.youtube.com/watch?v=te3OU9fxC8U] which is, frankly, of dubious real-world value. And, personally, I suspect pattern-matching is a nightmare-in-waiting. We can look at Scala codebases today (at least the ones where people didn't give up and convert them back to Java) to see pattern matching abuses that end up in a big mess. Contrary to popular belief, in the real world actual ADTs are quite rare. (And when they do come up you're mostly dealing with generated code like protobufs.)
The real value of Java -- a relatively, simple, performant language that let developers focus on creating basic business models -- actually gets lost. The good news is that these days there are alternatives like C# (which can run on Linux) and Dart and especially Typescript. These languages have all of Java's strengths (static typing, clean syntax, good support for basic OO constructs, simplicity) along with the syntactic sugar and quality-of-life improvements that make programming in them a breath of fresh air. I think Typescript in particular will replace Java as the new "language of the enterprise."
Fortunately, this doesn't mean the end of the JVM which is still amazing and only getting better. Take a look at what's going on with VertX. I think it's only a matter of time before Typescript-on-the-JVM becomes a very common thing (eg https://1c.wizawu.com/ , GraalVM). Indeed if we can convert developers from weakly-typed languages (Python, Ruby) and outright crappy languages (Go) over to strongly-typed Typescript running on the JVM that would be a big win for everybody.
7
u/_INTER_ Jun 01 '20
This is all leading towards a new "stuctured data/record" programming style [...] which is, frankly, of dubious real-world value.
The good news is that these days there are alternatives like C# (which can run on Linux) and Dart and especially Typescript
Typescript is one of the structural typing nightmares though
3
-18
u/badtux99 Jun 01 '20
And don't forget lambdas *that aren't actually lambdas*. I mean, a *real* lambda, as provided in languages that actually support lambdas as first class objects, is... well, an object. It can be assigned, it can be passed as a parameter to things, etc. This half ass lamba in Java, to anybody who is familiar with languages that have lambdas as first class objects, is the lamest thing like evah.
14
u/Samael1990 Jun 01 '20
Lambda in java 8 is Function object, I'm pretty sure. It can be passed as parameter to the method and it can be stored as variable.
8
Jun 01 '20
The biggest pain with lambdas being bolted on to the language is the inability to throw checked exception in a lambda without resorting to hacks like runtime exception wrapping.
8
u/gravitas-deficiency Jun 01 '20
I admit, this was a restriction that had me grumbling when I discovered it.
2
u/Samael1990 Jun 01 '20
I think that's by design, because checked exceptions are generally considered an anti-pattern, especially in functional programming where lambdas are supposed to be used.
1
Jun 02 '20
Their hand was forced by maintaining backwards compatibility (lambdas get compiled as function objects which can’t have dynamically declared checked exceptions)
-11
u/CupCakeArmy Jun 01 '20
“There are only two kinds of languages: the ones people complain about and the ones nobody uses.” Yee fo sure... And then there are Rust, Python, Go, Typescript: which everyone uses and (almost) everyone loves.
47
u/ArmoredPancake Jun 01 '20
The comment is so generic that it wouldn't be possible to write in Go.
-1
3
u/Necessary-Conflict Jun 01 '20
I am pretty sure that if any of these languages ever achieved the status of Java (where using them is not your choice, but you are expected to use them), a lot of haters would quickly emerge.
Actually Bjarne Stroustrup said this thing back when C++ was the "dominant" language, and it was fashionable to hate C++. C++ is still used today, but almost nobody bothers to loudly hate it.
2
u/couscous_ Jun 01 '20
There are tons of complaints for all the aforementioned languages, and they're not even used anywhere close to the same level Java is.
2
u/_INTER_ Jun 01 '20 edited Jun 01 '20
Or PHP where people only complain about (me included). It is now sinking so rapidly even
MediawikiWordPress is moving away from it.1
u/couscous_ Jun 01 '20
What are they moving to?
3
u/_INTER_ Jun 01 '20 edited Jun 01 '20
They gradually move to Node.js I think. I can't find the news article I read about that anymore (only found this). It's hard to google "mediawiki" or and not get a wikipedia entry.
Edit: Sorry it apparently was WordPress. But that's also a really old article. I remember having read something along those lines just recently
2
Jun 01 '20
I see plenty of complaints about python and go. Typically from the more functional programming focused communities, where going to a simple feature poor language feels like a step back.
-1
u/brennanfee Jun 01 '20
Technically, COBOL is still evolving. Not sure that's a ringing endorsement for its use, though.
1
u/helikal Jun 01 '20
The C language has all but completely ceased to evolve. It is now the Latin of programming languages. Nevertheless, C is very popular, perhaps because of it.
176
u/[deleted] Jun 01 '20 edited Jun 01 '20
Ah, perfect place for a rant...
When my journey into the world of software development began (around 5 years ago), the first language I came across was C. All nice and dandy, but Java seemed to be the right course of action, a language I would learn in my spare time.
Today, I work as a tech lead (mobile apps) mostly working with Flutter. I have seen so many developers with JavaScript background switch to Dart, writing horrible code.
Whenever native Android or native iOS modules have to be written (nowadays in Kotlin or Swift), lack of strong knowledge of OOP concepts shows!!!
Just the other day we laid off a worker who couldn't fix a simple null exception (forgot to initialize a list). Another department had to lay off some students who barely understood the concept of inheritance...
Every solid developer that I came across worked extensively in Java during some period of their lives. Or maybe C++ (older coders) or C#.
These languages seem to produce better developers.