54 points · by saikatsg · 4y ago · 184 comments
If you only work with SQL Server then it is probably best you use SQL Server Management Studio. If you use different databases you will need a different client and I find with JDBC based clients you can use one client for to connect to many databases. I have seen many here complain that the Java tools are slow and bloated and look ancient. From a looks perspective you can use FlatLaf themes which look good to me. There are some nice dark themes to chose from.
[0] https://dbeaver.io/ [1] https://www.sql-workbench.eu/ [2] https://github.com/squirrel-sql-client
Working with pg in nodejs was frustrating in comparison.
Where I work now the the "Java" devs code about 80% Kotlin and 20% Java.
At my previous job we were mostly Ruby except for a service that relied on a Java library that connected to some obscure systems that no other language had a library for. Yeah, we used Java, but it was because that was our only option.
you still have to deal with all the controllers, etc.
on reddit, one of the arguments was interesting - the biggest value of kotlin in backend is using var/val instead of types and making everything public (instead of getters/setters).
would that be correct ? Lombok doesnt fix this ?
That reflects my experience
Java devs seem to be moving to Kotlin, or as some would say JetBrain's C# hehe
Stuff he gets right:
* Getters/setters is a nonissue
* Operator overloading is a nonissue. I did like how Ceylon handled it (operators are aliases for normal spelled-out methods) but honestly overloading is not something I ever miss. And it was a minefield back in my C++ days.
* Dependency management in Java is decent. It's worse in every other ecosystem I've encountered.
Stuff he gets wrong:
* Checked exceptions are horrid. The people who hate them aren't driven by laziness, they're driven by the desire to use standard interfaces - especially now that we have lambdas. You can use `Runnable`! Unless your code throws a checked exception... in which case you have to go through the ceremony of wrapping it. This is stupid. You can have standard interfaces, or you can have checked exceptions, and standard interfaces are vastly more useful.
why getters/setters.
Most frameworks (and not languages) use everything public. Rails, React, golang's frameworks, flask/fastapi. Code has generally not suffered from being public.
Would you not accept a Java framework with everything public ? i asked this question on /r/java some time back and got badly flamed. So im trying to understand this. This seems to very philosophical...but then most other frameworks in other languages dont carry this philosophy.
Every so often I want to change the behavior of something, and it's a big PITA. For example, maybe I'd like to ensure there's a default value for something that is sometimes null. If access was via getter method, I can just override the getter:
class Foo {
private final String name;
public String getName() { return name == null ? "Default" : name; }
}
No need to change the hundreds of places that call .name or .getName().This kind of thing happens often enough that it really should be baked into the language. Lo and behold, most post-Java languages support it, including C# and (modern) Javascript. Java is a bit stubborn in this regard, but Lombok solves the problem in a way that is almost language-native.
this is so cool! thanks for sharing that anecdote. trust me, ur the first person who has ever written this publicly.
so I hear your argument for getters/setters. And IMHO, all paradigms do have their usecases -probably so do CQRS and everything else.
But ultimately, you can refactor using the tools available today. I would (politely) argue that your example is also a notnull situation and perhaps i would have solved it on initialization, versus the way you did it.
Ultimately, you can create getter/setter structures in python as well. But in most large codebases, it still ends up being unnecessary.
Foo class can only contain something, but not make any decisions, no matter how small, because it's not obvious whether a decision is still small or not anymore.
Getters are still useful though, for example:
class Foo {
// all contents of Foo, but we want to keep it serialized for performance reasons
private ByteBuffer bb;
public Long getId() {
return bb.getLong(ID_OFFSET);
}
}Since Java 17 there are records.
Meaning, your framework users can depend on any implementation detail and if you change that detail, the framework will break for these users. They will be disappointed since they didn't know they were doing something wrong (all is public and thus available to use).
Which is where a lot of the JS/Ruby/Python frameworks operate. You're not wrong - my point is that a lot of places, it is not necessary.
I spent 10 years suffering under a ruby app where literally every interface had to be considered public because someone might have gone code surfing and decided to be clever, so literally nothing was a simple code refactoring of private interfaces that nobody should touch.
I don't understand what kinds of software people who make this argument write, but I assume it has to be something like web services where the http routing layer is the actual public interface definition and so you're benefiting from strong encapsulation at that layer. Yes, in that case the language doesn't need strong encapsulation because your external framework already provides it for you.
this is actually one of the best ways anyone has put it. You may be right. I have often wondered how does the huge amount of Ruby/Python/JS work in building large companies and products, when Java mandates all this amount of massive complexity.
You may be right here - in the web services world, the hard contract of the API layer makes up for less strict encapsulation everywhere else.
Records are imo a really great addition, making the difference explicit.
As for why private fields are important, think of a class implementing a circular buffer with a fixed-size array. Here, the start and end indices used are private state, which is a must for proper OOP — without it it couldn’t enforce class invariants.
You would not break the contract of maliciously trying to access variables that shouldnt be accessed.
For example, a popular convention is to have underscored variable names (__thisisprivate). Works perfectly OK.
99% of getters/setters dont do anything more. They do exactly this. No validation, nothing. So I'm questioning the ordinary....not the special cases.
But at this point with records... I don't care. I declare a Integer 'bla' and a 'getBla()' is made available by the IDE right way. Sometimes the records fields end-up being accessible without the getter. ( declaring the record in another class for instance...). But that is also a moot point : all the data they are holding is final and I know what can be null or not.
Culture, I guess...
Came here to say exactly this. Exceptions are a poor-man's implementation of an error-handling applicative or monad type. Checked exceptions are especially terrible because their usage forces handling of exceptions in every layer of the call stack above the point where the checked exception might be thrown instead of simply writing a single exception handler at an appropriate layer.
Here are my reasons for thinking so: https://news.ycombinator.com/item?id=32944346
True, but in those languages, exceptions can be thrown from anywhere anyway.
> Checked exceptions are especially terrible because their usage forces handling of exceptions in every layer of the call stack above the point where the checked exception might be thrown
That's not true. Handling a checked exception in one layer means you don't need to handle it in the above layers.
For a lot of things, it's fine. And there certainly are potential problems with operator overloading. But the experience of, say, reading/writing, linear algebra code using a C++ library with arithmetic operations on vector and matrix types vs using its java bindings where that's all done through explicit method calls wildly favors C++.
As a language feature I can't feel more than ambivalent about operator overloading. Kotlin has it, Java doesn't, I'm ok either way.
Java the language is really coming along nicely. With records, pattern matching, string templates, virtual threads, value types (in the work), and more, it's shaping up to be a top notch development language.
The user base kind of helps the developers find the fixes way too easily compared to any other language.
I doubt it is ever going to lose it's popularity as Java is very good to accept good changes(although slowly). The best thing about java is it provides code stability and backward compatibility and this is the reason it will thrive even more.
Similar to C++ getting replaced by go and rust everywhere, Java's time has gone. It's just running on momentum at this point.
The JVM will likely continue on though
You are either wildly exaggerating or living in a bubble.
There's no value in using it for future projects other than a wider pool of developers to source from... a network effect that will diminish with time.
Java is objectively dated in so many ways, it's not really defensible to say otherwise. Tons of unnecessarily verbose and boilerplate aspects of the language.
COBOL was used for a long time for various business backends... did that mean it was a great language that was going to be used in perpetuity? no. And I assume the majority of those don't exist anymore, despite existing as recently as the 2010s
C++ as well, but especially Java likely has multiple times as much projects than all the smaller languages summed. They are ain’t going anywhere anytime soonz
No
> So much code fails unexpectedly. When you want to build a professional application you need to handle every error.
Yes
> Checked exceptions help you avoid that nonsense.
Wrong
> People hate checked exceptions because of laziness. Java guards you against yourself.
Wrong
Java checked exceptions are almost universally regarded as being a mistake because they don't actually solve the problem they were meant to solve, and they make the code extremely hard to work with.
See this post from Roman Elizarov: https://elizarov.medium.com/kotlin-and-exceptions-8062f589d0...
1. C-like language - Flip between C, C++, Java and JS with minimal thinking about syntax.
2. Build once - I can build locally and deploy the byte code straight to production. I don't need to worry about the production server having the right packages as long as everything is bundled in my JAR.
3. Libraries just work (mostly) - It doesn't matter if the library was written yesterday or 10 years ago, as long as it was written sanely, it should just work.
4. Garbage collector - Really in top class. I can create and throw away huge amounts of RAM and not have to worry about leaks and have it dealt with realitively little performance impact.
5. Memory safety - Never having to worry about pointers, segmentation faults, etc.
6. Exception handling - And if all else fails, Java will ultimately give you the opportunity to recover from many different scenarios. This may seem like lazy programming, but actually it's for the edge cases you can't think of. If your program does happen to crash, you get a very good stack trace.
Java may be cumbersome and repetitive is some areas (and perhaps the newer additions to the language deal with this), but I would take them every day of the week.
The only thing that has really left me wanting is C-like performance and networking capabilities. Most other things I want to use are very well implemented.
Well, it is basically there in hot loops. Not necessarily with idiomatic Java, you do have to use primitives but it is absolutely achievable.
Also, what do you lack with regards to networking?
Not quite in my opinion. Not bad, but it can be half performance at times.
> Well, it is basically there in hot loops. Not necessarily with idiomatic Java, you do have to use primitives but it is absolutely achievable.
Setting more intricate TCP settings, or sending ICMP, or essentially anything advanced.
Modern Java isn't really any more verbose than other languages it gets compared against. It is very nicely balanced between expressiveness and readability.
That is such bullshit. There are plenty of very functional libraries written entirely in Java, it has a surprisingly adapt type system that makes plenty of things expressible (not monads themselves, but you can almost get there with purely generics). Vavr, jool, immutables.
And what exactly is complex? Java is on the leaner end of language complexity, just compare its number of keywords to.. any other mainstream language.
Especially the conceptual overhead of DAO/DTO, etc seems very religious in nature.
I worked on several golang projects where protobuf was used, and the same dichotomy showed up in the code. There were three types even, protobuf types, internal types, and DB types, with manual mappers and validators having to be written between them. Quite a bad, verbose, and error prone experience, especially that golang itself is quite verbose.
its the front loading of a huge number of patterns which ends up being the barrier. An argument is made for "future proofing". Its not unlike Python whitespace indentation or golang's unused variables restriction.
But the design pattern complexity is far more harder than all these things.
There is a certain degree of complexity when all of this starts making sense. Or maybe do what Redux did ... and abstract everything out to somewhere else.
u used the word "viewmodel", so are we talking about android ?
try {
// do stuff
} catch (SomeException e) {
// do nothing, maybe log it
}
I strongly agree the verbosity is a non-issue. Any modern IDE just fills this in for you. Yes more verbose syntax for getters/setters would be nice but it's not a big deal.But there's one point I wanted to highlight. Every language that comes after Java should've learned Java's lessons and some didn't.
C# quite famously did. C# really is Java 2.0. No checked exceptions, reified generics (rather than type erasure) and some cool stuff too (eg LINQ, partial classes).
Other languages (eg Go, Rust) largely moved away from exceptions entirely. Personally I agree with this. Exceptions are a false economy that devolve into control flow that's hard to follow (eg Java has a parse number from string that throws a ParseException if the parsing fails and that's just not an exception).
But the big one is dependencies. Every external dependency system that came after Mavaen should be at least as good and many aren't. I'm looking at you, Go. This was a shocking omission for something aimed at being a better systems programming language (which it never would be as a GC language but that's another story).
But Java is proven, mature and sufficient. That's why it's still used.
I don't really think that Go was intended to be a systems level programming language, I've never used it that way personally. I think of it as specialized towards being an excellent applications level programming language with rich-enough system level interfaces where necessary. People who do stuff like programming a bootable OS in go aren't doing it because they intend to develop it into something everyone will use, it's done more like an exercise.
Basically, checked exceptions could have worked, if they were the only type, and had better ergonomics of use, and a language culture that emphasized correctness more.
Checked exceptions were wrong for Java, but that does not mean they are wrong universally.
throw checked new Exception();
Then the caller knows there is a special reason to handle this exception, and it's also easy to write a tiny wrapper to neutralize the check, if needed.For example: failure to open a file could be nothing major in one case (just return null), needs to be handled in another, or should cause the entire application to exit. This depends on what file was opened - but it does NOT depend on the type of error.
I’m not claiming that Java’s execution of checked exceptions is good, it unfortunately does have a few inconsistencies (lambdas don’t operate well with them, also inheritance is not a good match for exceptions), but it was pretty universally ditched and I think it very well deserves another chance.
I think they can have its place but operating well with lambdas would be a must... If Java supported a multi-value return, like Go and Python do, and control flow was based on `var a, err = obj.exec()` or some other syntax that could work nicely with Streams and the functional features of Java I wouldn't have an issue with checked exceptions. A multi-return for errors with checked exceptions would even allow the compiler to narrow down all the possible `err` types you could get, automatically generate a Java 17 `switch()` to parse through all the possible cases of checked exceptions. It could help a lot with error handling.
I’ve been writing java code since about 2001 and up until Java 8 this was fairly true, and definitely a fantastic thing.
However the leap from 8 to 11 or 17 (all LTS releases) is a painful process. We are moving from 8 to 17 at work, but the number of issues we run into with incompatible libraries is a right royal pain. Especially when it’s down to the (imo) silly decision to rename the java EE packages to jakarta. A pointless exercise (imo) that has held back a lot of organisations from upgrading sooner.
This is his conclusion, and I, well, agree. While I was well versed in Java, once I started playing around with Kotlin (which was around the time Java was stagnating), I never really looked back.
Because coming from the flask, go, jsapi ecosystem...it was very hard for me to be productive in the jvm world (kotlin or java), cos of the frameworks.
But from a language aspect alone, I’m just so much more productive when cranking out code in Kotlin compared to Java.
WASM might shake this up in a few years. We'll see.
Not if you're trying to work with other algebraic data types.
> If I see a + b I know that this is either a string or a number not some hidden method.
Great if your world only consists of numbers and strings.
And really in this day and age with strongly typed languages your IDE should be able to easily tell you if someone is doing something totally insane with any given operator. In most cases, they won't be and it'll be easy to decipher exactly what they mean.
Stop trying to prevent everyone from being able to do useful things just because some people write crappy code that abuses language features.
what would make you choose java :
1. is it a better framework than spring boot
2. is it a better tooling like heroku or something for java
3. is it better community & programming paradigms ? I once asked a question "can i write a java api using all variables as public" and got flamed pretty badly. Do people want an alternative to the MVC/DAO/DTO structure ...where the community doesnt flame them ?
4. is it something else ?
Because based on docker pulls, java still is probably just as popular as nodejs or something.
what would make java sexy again ?
I'm less than enthused by the spring ecosystem. It does help you start quicker than you would without it but while running it in production over time I think it has costs I'd rather not pay so I suppose a better framework would excite me too.
Java as a language is fine and I have no real complaints there.
can you elaborate on this ? really have been considering spring boot, etc. But coming from the python world ...i feel it cognitively very hard to get through. But im super keen to know what issues come in production.
Most of us were under the impression that Spring in production just works.
>so I suppose a better framework would excite me too
especially from this perspective. What would you want ?
We have a saying about these types of frameworks: They are a great way to turn compile errors into runtime errors.
When you are just starting out on a project it's great. You get up and running fast and as long as stuff doesn't change too much you are probably fine. But when your codebase reaches 5+ years of age it's highly likely to see a spike in "runtime errors" that potentially could have been compile time errors every time you release and releases get nerve wracking for a bit until eventually the codebase get's frozen in stone and someone starts suggesting we rewrite it.
1. is it a better framework than spring boot
Dropwizard has a refreshing approach.
2. is it a better tooling like heroku or something for java
Working with kubernetes is seamless. Lots of ready made hooks to your JVM and your application
3. is it better community & programming paradigms ? I once asked a question "can i write a java api using all variables as public" and got flamed pretty badly. Do people want an alternative to the MVC/DAO/DTO structure ...where the community doesnt flame them ?
There is a strong push toward immutable everything and final all variables. It's ugly like often with java, but it's attainable by settings the linter to the max and adding yet another annotation ( to the package folder itself, and it's not enforced by the compiler unless you ask for it... )
4. is it something else ?
At this point I can crank out things fast in functional & immutable manner. Tests write themselves. JVM is rock solid.
It already has loom in preview which will make the whole previous thing suddenly non-blocking (this is uniquely possible with java due to the ecosystem being 99.9+% purely java, no FFI).
Once value types arrive, I will honestly see no niche other than embedded/lower-level not served by this platform. Oh, and there is of course Graal which will bring all these capabilities to even polyglot code bases, you can just execute some python script on basically java objects with java’s speed!
just curious - i have heard comments of people looking for a simpler framework. And especially cloud integration/deployment.
I do miss the nice IntellIJ java features.
We also needed fast start times and hopefully graal continues to mature. We also worried about graal costs given oracles history.
i thought the JS ecosystem was crazy full of packages.
I have spent a long time as a Java dev using Maven, and the past few years floating around some other projects (C#, PHP, Python, a tiny bit of NodeJS) and continually find myself wishing to have Maven back, so I suppose YMMV.
Now let's munge in plugins and plugins of packages and it gets messy real fast. Outside of the outdated XML, is there a way to deal with these problems cleanly?
But Maven doesn't need a "lock" file, and can still download a reproducible tree of dependencies just fine, so that's a win in my book!
Yes, there's been jlink for a long time, but it still generates a folder, not a single file.
There is jpackage, but it generates installers for various platforms, not an executable binary.
Doing more work at scale these days and running into Elasticsearch, NiFi, and so forth.
I don't have to like the fact that java has to have its own keystore, and that the elasticsearch.service invocation has 35 (!) arguments by the time it reaches its launch. But these enterprise tools provide a methodology for getting granular when it makes sense.
The annotated version is more terse because he's showing its usage. For the non-annotation version he's showing the implementation.
edit (because I forgot to quote the article directly):
The syntax is more tersex.get(y) x[y]
I'm counting 4 charcters.
I think this is a bad approach. Developer should know his components, and adding one shouldn't be a frequent event.
Adding components is about reusing code while replacing them is about having to track security issues (which is very good now, via maven) and new functionality being added (which you may or may not want). Same as NPM or any other package manager that existed.
In the NPM world there are too many small libraries that create a dependency graph that's impossible to parse mentally. No one knows your true dependencies and that created many problems.
In Maven libraries are sometimes too big. That's true. But most of them are closer to the size that gives a library a bit of "meat". Obviously YMMV.
ResultSet rs = DB."SELECT * FROM Person p WHERE p.last_name = \{name}";
This when it becomes valid java will not allow an SQL injection attack. The name part would be properly passed as a parameter. Not a string concatenation. Per https://openjdk.org/jeps/430
If that was not the example you where thinking about, sorry :)
Otherwise yes don't build parameterized SQL out of strings !
So DB."SELECT * FROM Person p WHERE p.last_name = \{name}" would basically be a function call like DB("SELECT * FROM Person p WHERE p.last_name = ", name), which would do the right thing to parameterize the SQL.
It doesn't. That's not a plain string replacement...
Second, the author was using that as an example of Java showing a pattern of adding syntax improvements, which again might be something that maintains popularity.
Finally, from the article:
But let's talk about the Java we have today, not the one coming in 6 months.
It was just one talking point. Did you even read the article?- use a library that implements RFC 5322 properly.
- don't validate the email address (that is, don't try to reject most invalid addresses) and just check that the field contains at least one `@` to be sure the user didn't enter something else than his email address by accident.
Tying to perform email address validation with regex you're writing yourself is the best way to reject perfectly acceptable email address and get frustrated users.
https://lexi-lambda.github.io/blog/2019/11/05/parse-don-t-va...
The format for emails is surprisingly complex, and while you can use a regex to catch 99% of the right values, it's very difficult to get it 100% right. Often the best thing to do is just to try and send an email to the address a validation link.
"new" keyword is basically introducing side effects, everywhere, making Java more difficult to test and confusing generations about how to do testing.
The primitive/object combination of int/Integer, et al is noise.
The reliance on annotations for modern development and the reluctance to put syntax in the language to codify obvious things. Basically requiring a pre-processing language (Spring) to do basic tasks, making development slower and more error prone.
The final keyword. The idea that you should sometimes take away developer agency, because you know the future, better than anyone. Classy.
The combination of Class Access Modifiers (which are for mixin property selection) with interface definition (what's this object's interface?).
The much acclaimed "java ecosystem" reinforces bad practices. 10 years later, PHP is derided for bad language choices but bad Java is handwaved as a series of missteps that has been corrected.
"new" keyword is basically introducing side effects, everywhere,
I don't think that's what it does. Unless you're talking about putting side effects into the constructor? confusing generations about how to do testing.
Doesn't follow from the first part. The primitive/object combination of int/Integer, et al is noise.
Somewhat agree. The reliance on annotations for modern development
Sure, the Spring ones are horrible, but the Lombok and Jackson ones are pretty decent. put syntax in the language to codify obvious things
What new syntax would you want? I guess I'd want to clean up the flatMap mess with some nice do-notation and <- arrows. The final keyword. The idea that you should sometimes take away developer agency, because you know the future, better than anyone. Classy.
Final as a method keyword? Fair enough, but I don't think I've ever come across a method that I wanted to override but couldn't (I hate inheritance)..
Final is also to try to make things immutable, but making things immutable in Java also takes more care than it should. The combination of Class Access Modifiers (which are for mixin property selection) with interface definition (what's this object's interface?).
I don't get this at all. The much acclaimed "java ecosystem" reinforces bad practices. 10 years later, PHP is derided for bad language choices but bad Java is handwaved as a series of missteps that has been corrected.
Maybe the language, not the ecosystem?>> I don't think that's what it does.
From a java testing perspective, it does. There is no way to mock something that is new'd. This is a failure of the language. ie Python, p1 = MyClass() Now you have something mockable.
> the Lombok and Jackson ones are pretty decent.
They are, but they aren't in the language because Oracle (and the existing language development practices). Actual improvements are haphazardly added to java because 3rd parties already did the work, so why should they make the language better? Just use the increasingly obscure set of 3rd party additions.