IMHO, YMMV etc.
IMHO, YMMV etc.
If I don't need performance, Python is ok.
If I do, I won't go Java, I will choose something that is built for performance. Python is good enough for 99% of my performances need. The last 1%, jumping to java is not a big difference, I'll use rust or go.
I won't use go for the ecosystem, but it's unique characteristics: easy concurrency, dead simple binary production. Java can't beat that. IF I need an huge ecosystem, I'll go Python.
For the need for Java, I would need this very specific sweet spot where I need just enough speed, and just a rich ecosystem enough to justify it, and nothing that is a killer feature in alternatives. And a situation where compromise over this is not possible.
It never happens to me, that's all.
Whilst I roughly agree, that's still a bit too simplistic.
In particular, we might prefer something like Rust to write a performance-critical algorithm, but that forces us to make a decision:
- Do we stick with Rust for everything else (networking, data plumbing, etc.)? This forces us to confront the ecosystem problem.
- Do we wrap our algorithm as a library for other languages (like Python)? This forces us to confront interoperability (ABIs, FFIs, cross-language dependency management, etc.).
There's lots of room in between these extremes for other pareto-optima, like Java.
Also, we often need to consider latency and throughput separately, rather than just "performance". Java is a pretty stark example, since it's pretty slow to start but reasonably fast when left running (compared to native binaries like Rust, which are low latency and high throughput, or scripting languages like Python which are high latency and low throughput).
And Go is better if you do I/O.
That's my points. Compromises.
I'm not saying "Java is bad". I'm saying, "I have no use case where I, personally, would use Java over something else."
I do know other people have use cases for it.
I just don't, because those compromises don't make sense for me.
Its only saving grace is that all other cross-platform GUI systems also suck, and if you're doing everything else in Java it might be the path of least resistance.
"Filthy Rich Clients" by the nowadays Android UI architects
"Swing Hacks: Tips and Tools for Killer GUIs" by Joshua Marinacci, well know in the UI research community
https://www.amazon.de/dp/0596009070
And then commercial libraries like
(Though I haven’t tried its mobile “backend”)
Java does have android right now, although it has to share with ReactNative, Xamarin and flutter. Again, for different compromises.
Java also has the IDE ecosystem between Netbeans, Eclipse and all JetBrains offerings, with exception of Apple and Microsoft offerings.
You are trying to move the debate toward the quality of java, which is was never my point.
> If I do, I won't go Java, I will choose something that is built for performance. Python is good enough for 99% of my performances need. The last 1%, jumping to java is not a big difference, I'll use rust or go.
So given that, I am curious where are those GUI alternatives with the required perfomance in Go and Rust.
- you need a GUI
- you need perf beyond what Python is capable and you identified it clearly in advance
- you can't use numpy / multiprocessing / cython, pypy or they won't give you the perf you need
- you can't find a main hotpath you can optimize with a 5 lines c or rust extension and write 99.99% of your app in python. Or you don't want to bother.
If you ever find yourself in this very use case, then yes, use Java.
But I never found myself in this very precise use case.
Please.... That's literally the worst option for python on this planet. For all "just do multiprocessing" the tooling is horrible garbage. Then we get to Twisted and Gunicorn the Spring Framework of Python world.
It's hard to separate the absolute performance of Java the language from Java the culture where inefficient patterns or attempts to implement dynamic behaviors in some framework code defeat the JIT (not to mention the benefits of type-checking). If you have a team which cares, it should be faster but the average business app I see does not have that team and will, if lucky, perform within the same order of magnitude as Python.
Speed doesn’t matter always, but when it does it Java feels snappy. Our programs our command line based so our framework use is limited. Also the built in data structures are nice. I still find getting Java’s set up painful, which is a huge impediment for us using it more.
(yeah I know it has type hints now)
import random
import time
from concurrent.futures import ThreadPoolExecutor, as_completed
def hello(seconds):
print(f"Starting hello in {seconds}s")
time.sleep(seconds)
print(f"End of hello in {seconds}s")
return seconds
# At the end of this blocks, it automatically join() and clean
with ThreadPoolExecutor(max_workers=2) as executor: # 2 tasks in parallel max
# this send jobs to threads via safe queues
a = executor.submit(hello, random.randint(0, 5))
b = executor.submit(hello, random.randint(0, 5))
# this collect results from queues in order of completion
# sync is automatic
for future in as_completed((a, b)):
print(future.result())
And if about network I/O only, you can get even more perfs using asyncio.Threads in Python are only inferior to Java threads when it's about using several CPU.
I do enjoy in python that it is quite easy to utilise multiple processes in a code-light fashion, but some things are more natural as threads.
I got into Go for a while, but if I'm honest, it's a kludgey language. Half the reason it has taken off as it has is simply down to the fact that it's backed by google.
That's where you're wrong, kiddo.
But that's not the point. The point is that, for the 99%, staying on a slower language is ok. For the last 1%, I'll skip Java and go to Rust/Go. If I have to do a rewrite for perf sake, I'm not going to go half way.
And for IO, you will get faster perf in Go more easily. Sure, you can finely tune your Java code to get there, but it's a lot harder.
It in both cases it will eat up way more memory.
There is a reason Google, that did use heavily Java internally, is now moving to Go, a language they custom designed for concurrency.
Basically every language is more expressive there (even Java), GC is much much better - in benchmarks it is not as obvious only because Go avoids creating garbage most of the time, but it can’t always be avoided; and the platform is incomparably richer on the JVM side.
* performance is not really an issue for most software ("97% of the time, premature optimization is evil"). A well designed software doesn't suffer from performance issues with current computer performance, unless you do AI or bleeding edge graphics or science simulation.
* there are ways to speed up performance sensitive parts with something else than java, for example by using C/C++, would it be with a python module or cython. Not ideal, but generally you gain performance by adapting your design, not by changing languages. A garbage collector is rarely predictable, hence java is not a good fit for performance.
* I remember playing minecraft with friends, and the server was regularly crashing because it was out of memory, or something like that.
> I remember playing minecraft with friends, and the server was regularly crashing because it was out of memory, or something like that.
I've seen this, but I don't think you can really use one server program running out of RAM as indicative of much. I do still find the pre-setting of max memory on the command line a little bit odd though.
A lot of graduates think that compsci jobs involve optimizing algorithms or some shit coz they did that type of thing as undergrads, so they port that attitude across.
It's also the reason why pypy was massively hyped for a while and then not really used all that much. It was solving the performance problems python never really had.
I have noticed some younger engineers on C++ projects doing some kooky things "because it's more optimal", and have taken time to explain to them that the micro-optimisations they're using impact readability, are going to be done by the compiler anyway if they're at all useful, and are likely to be several orders of magnitude less relevant than some lock somewhere, or a bit of IO, or whatever.
Handling process memory usage pre-docker wasn't so easy.
> well designed software
Ah, there's my problem. Maybe at some point I'll get a chance to work on one of those.
Could be a problem with the logic/design of the server rather than a problem with Java? Despite memory being GC'd, you can still run out of it if you just keep allocating stuff. The important thing about Java is that it doesn't suffer from the usual C or C++ memory exploits.