409 points · by crummy · 1y ago · 331 comments
void main(String[] args) {
println("Hello world");
}
I just saved that as "hello.java" and ran it (using OpenJDK Runtime Environment Homebrew (build 23.0.1) which I happened to have on my Mac already) like this: java --enable-preview hello.java
This is SO MUCH less crufty than the old "public static void main(String[] args)" thing. I always felt that was a terrible introduction to programming, when Hello World included a whole chunk of boilerplate and a class that didn't need to exist.The next class was assembly programming, where the teacher didn't bother to show for 4 months and then resumed the class as if we "self-taught up until this point". We were utterly lost in that one.
I imagine things have changed greatly today but back then it was a complete roller coaster.
I wasn't good at getting educated, but I ended up at a community college to "get my generals" - my first class of the day was computer something or other, and the class was led by a man in extremely thick glasses who said that our general approach in the course was going to be:
* perform actions with the computer
* take a screenshot
* paste the screenshot into mspaint
* print out the screenshot as proof that we had completed the thing
* put that in a folder
* he would review the folder for completion
(for anyone paying attention, anyone could just print out multiple copies)While it was a significantly younger and less experienced me who quit this bullshit in an absolute huff, I don't know if I could go through it today.
Fast forward a few years later, and I was training folks on tech support(a random reversal) and I had a lady who should have taken his class... every time I told them to click on something she asked "is that right click or a left click?" and each time I would respond "its a left click unless I tell you otherwise" (she didn't last long.)
But what does this code even mean..? Isn't Java's whole simplifying model that everything lives in "Objects"? This seems to break that fundamental paradigm and makes the language more complicated. If you needed something like global functions then in vanilla Java as I remember you'd stick it into static final Objects that acts as a namespace of sorts. So you don't need to worry about functions floating around in a global namespace soup.
If you're gunna just have free floating functions in your file.. then why not just cut to the chase and have a
println("Hello world");
floating in your file..? (I mean... you don't have REPL so maybe that wouldn't be too meaningful...) > you don't have REPL
(ahem) https://docs.oracle.com/en/java/javase/23/jshell/introductio...But, yes, with static imports, you can just write "println" like that and have it work.
did you know that every function in a python script is actually an attribute of that module (which is basically a class). so my point is: who cares.
You still need to know what a main class is, so that you can reference it in your build.gradle file.
Basically, imagine a `class Temporary4738 {` and `}` written above and below the .java file's content, that's roughly how it will behave.
It not having a fixed name is deliberate, so if you decide to build a bigger system you won't use this mechanism in a hard to maintain way, and also it needed a good semantic model for "top-level" variables/fields.
But with this implicit class model, top-level definitions are just fields of the class.
The same strategy is also followed by C# with their top-level statements. And yes, it's syntactic sugar.
https://learn.microsoft.com/en-us/dotnet/csharp/fundamentals...
Welcome to the last 10+ years of Java. They're trying to play catch-up to other languages that made fundamentally different and better choices, making Java more and more complicated in the process. They are so deeply entrenched in the enterprise back end space that programmers put up with it, nay, even feel grateful for it. People who are stuck using Java for the rest of their careers are happy to see it grow to accommodate 21st century programming techniques, even if it means that it becomes so complicated and crufty that no beginner will touch it ever again.
eg want to run code for 6 months at a go managing hundreds of gigs of data, tens of thousands of threads, at high load, with sustained gigs a second of garbage generation? the jvm will just silently tick away doing just that while being nearly bulletproof. As much as I love ruby and python, you ain't doing that with them.
With hot code loading, introspection, etc. All the stuff that makes developing super-robust long-lived systems way easier.
And the flip side of the clunky language is your code from 20 years ago still works.
10+ years ago I considered myself proficient at C++. It made sense, I didn't mind the pointers, and while the std library still felt clunky, it was fine. But I tabled these skills, and they indeed rusted a bit, but surely I could bring them out when needed again, right?
Smart pointers with multiple variants, judicious use of macros, rampant use of double colons to ensure proper namespace resolution (which IMHO makes the code an absolute eyesore), to name a few. I won't argue these changes aren't necessary, but it isn't pretty.
Packages still exist.
It’s just not necessary to add an additional level of namespacing.
Statics never were some pure OOP anyway.
(My guess: It is.)
> So you don't need to worry about functions floating around in a global namespace soup.
Because having classes floating around in a global namespace soup is fundamentally different and should give no worries to anyone. Yet this was argument made in earnest back when arguments about Java's strengths and weaknesses were much more popular.
SEMICOLON!!!
What really threw me for a loop is the article author mentions: "I knew plenty of professors who were bothered by [the public static void main thing]." I could have sworn that OOP die-hards in academia _wanted_ the formal class boilerplate in the original design. Maybe they aged out? Perhaps, times are changing.
It’s the Python if __name__ == __main__ trash that was the worst. You’ll never understand it and it doesn’t fit in the language.
I use python a lot these days, and like it, but it's pretty funny seeing stuff like the above and type hints.
I hate not knowing what types a function takes and returns.
This seems true to me too. Examples:
* if __name__ == "__main__": main()
* Private members being marked by convention with leading underscore (e.g. def _foo()) instead of being a language feature
* @staticmethod as a decorator instead of being a language feature
* Duck typing vs. abstract base classes
* Static type hints got retrofitted to the language gradually, one feature at a time
* Reference-counted garbage collection seems to be more deterministic than tracing garbage collection and ensures that unreachable resources have their finalizers run as soon as possible... except it's not true
* Having a GIL instead of being truly multi-threaded from day one
* Various OOP concepts that are much better explained in Java than Python: __eq__(), __hash__(), monitor wait() and notify(), object finalizers, thread safety, weak references
* Distinction between str and bytes. This is the biggest change from Python 2 to 3 and caused a lot of incompatibilities. Java separated String and byte[] from the start (though the use of UTF-16 is unfortunate).
hello world in python is literally just print("hello world!")
Arguably you could be a happy Python programmer without this capability.
#! /usr/bin/env kotlin
println("Hello world")
You have to brew install kotlin for this to work of course. But it's a great way for using a lot of Java stuff as well. Kotlin's Java interoperability is excellent if you are using Java from Kotlin.IMHO Kotlin is underused as an alternative to python currently for data science stuff. It's surprisingly capable out of the box even with just the standard library and there are a lot of nice data science libraries that make it more useful. Not for everyone; but fairly easy to get started with.
Kotlin scripting is unfortunately not necessarily very user friendly (e.g. imports can be a bit tedious and IDE support is a bit meh). But it can be a nice way to embed some kotlin stuff in a script. Generally, Jetbrains could give this topic a lot more love and attention and it wouldn't even take that much to level up the experience.
KTS works in jupyter as well (there is a kotlin engine for that). And that of course is nice if you want to use Java libraries in jupyter. And developing kotlin DSLs for stuff and then using them in a script is kind of a power move.
Kotlin has been pretty bad at scripting and REPL, and unfortunately the team decided to drop both:
https://blog.jetbrains.com/kotlin/2024/11/state-of-kotlin-sc...
As the adage goes - Java programmers can write Java in any language.
Seems 'Java programmers' were already writing Java before Java's release ;)
from __past__ import JavaProgrammer
/usr/bin/python: error: line 0: not a chanceI somewhat agree, but it was kind of exciting to learn what each of those previously meaningless words meant.
Kind of a sneak preview... Tune in for next week when we learn what static means!!
Java is designed with OOP in mind and it kind of makes sense to have the user to think in terms of lego blocks of interfaces. Every method or class needs to have clear understanding of its users.
public - software handle is for all users
protected - software handle for current and extending classes
default - software is exposed to current package
private - software is restricted to be used in current class alone and nowhere else
So, the beginning of java programming starts with interface exposed to the user or other programmers. Is it weird and extreme. Yes. At least, it is consistent.
void main() {
println("Hello world");
}
should work just as well.you forgot surrounding class definition.
It makes it far far closer to the python experience.
void main(String[] args) {
println("Hello world");
}
and the previous one ...
class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}
And that is SO MUCH less? Are you being ironic?Should we allow somebody who cannot handle the second one, go on and programming because of the first one?
Goals:
Offer a smooth on-ramp to Java programming so that instructors can introduce concepts in a gradual manner.
Help students to write basic programs in a concise manner and grow their code gracefully as their skills grow.
Reduce the ceremony of writing simple programs such as scripts and command-line utilities.
Do not introduce a separate beginners' dialect of the Java language.
Do not introduce a separate beginners' toolchain; student programs should be compiled and run with the same tools that compile and run any Java program.
In collage, CS101 and 102 required me to learn and use JAVA, which I felt was a huge step backwards in usability and a lot of excess typing.
But as I reflect on it now, I think my feeling were because I came from knowing how to do some things and therefore not requiring the framework that JAVA offed to first time programmers.
Although my high school programming class was c++, which is even worse as a first language.
These were some neat tricks. I've been using the `java myfile.java` approach for running the AoC problems. I didn't realize the "implicit class" thing where you could have top level statements and methods, though, with the automatic import of java.base. That's pretty slick for this.
record Node(int cost, int row, int col){}
var pq = new PriorityQueue<Node>(Comparator.comparingInt(Node::cost));Really? A whole generation of Java programmers wrong functor classes in-line.
During jdk 1.1 development, there was obviously no consensus on test suites (i.e., JUnit), and the JavaSoft JCK tests required a ridiculous amount of html documentation for tracing to specs. Mark Reinhold, the jdk tech lead, refused to have his team write tests in JCK form, so instead he wrote a small harness with a compiling class loader: point the harness at a directory tree of .java files, and it would run them all, compiling as needed. The test interface was just a main function, and if it threw an exception, it failed. Pure and simple.
But probably the best magic trick for Java programmers is debugger hot reload. You write some empty methods, start the debugger, and then code iteratively, reloading as needed. (Set up the data and interfaces right, and change method bodies as you wish.) It's so much easier than recompile-println when you're just getting started, and after you've grown up and out, it's easier than rebuild/redeploy when you're working on a big system.
Hey, that's (close to) the traditional Smalltalk introduction-trick! And this has been available since 1.1? How does one concretely do that in Java and why is it not widely known?
2. The JDWP protocol lets debuggers redefine nearly anything, but HotSpot doesn't implement the full protocol. In practice many kinds of reload don't work.
3. To fix those issues app frameworks went with classloaders for partial app reloads instead, or reimplemented hotswap logic themselves (see JRebel).
There's no fundamental reason these can't be fixed, and in fact the Espresso JVM fixes both 1 and 2:
https://www.graalvm.org/latest/reference-manual/espresso/hot...
You can write JVM plugins that are invoked after redefinition occurs, allowing you (really your app framework) to do something sensible like partially reload state. And it implements the full protocol, so many more kinds of redefinition work.
Using it is easy. Just install Espresso as your JDK, point your build system at it, then debug your app. Recompiling what attached will cause hot reload.
But the JVM still has a few tricks up its sleeve, e.g. the class loader can dynamically re-load a newly compiled version of a class at runtime - jrebel is a proprietary extension that uses both tricks, but this latter can also be used by spring for hot swapping many parts of a running system.
Basically, in the JVM a class is unique within the class loader, so with a new class loader you can load as many class instances of the same, or slightly different class as you wish.
Do you have any example you can point to for this ?
And because it’s not compiled, you can just whack a hashbang at the top of the file and chmod it to be executable.
But perhaps we can both agree that it shouldn't be in JS/Node. :p
JEP 495: Simple Source Files and Instance Main Methods (Fourth Preview) https://openjdk.org/jeps/495
The parent article mentions and links JEP 477 -- the 3rd preview of the same feature-set. JEP 495 is the 4th preview and is included in JDK 24 which is in "stabilization" mode for release in March 2025.
Definitely one of those things where the comment section is only good at spouting ancient memes with little regard to the truth of them.
The JVM is a massive memory sink compared to the tiny (actual) runtime in Go or the total absence of a VM or runtime in Rust or Zig. I allocate at least 5x more memory for Java tasks, but sometimes its more.
Java is great compared to scripting languages or writing raw C, but not compared to modern compiled languages from a syntax (null, thrown exceptions, inheritance, etc..), library selection, CVE/security, memory usage or raw computer power perspective.
All in all, Go may take up a little less memory for similar performance, but the JVM is more flexible (and more observable), offering you better performance if you need it. And the footprint will continue dropping, as it has done for years [2].
C++, Zig, or Rust are not really an apples-to-apples comparison. Sure, they take up significantly less RAM, but their performance is more expensive per unit of effort, and it's not a one-time cost, either. It's a permanent tax on maintenance, not to mention Java's superb observability.
Don't get me wrong -- I'm a fan of Zig, and C++ is the language I still program in most, but you can't really compare them to Java. Java makes you pay for certain things -- especially in RAM -- but you do get your memory's worth in exchange, and in a way that translates to pretty significant time and money. If you can't spare the memory as you're running in a constrained environment that's one thing, but if you can, it's all a matter of what you want to use it for: do you want to use it all just on data, or do you want to spare some to reduce maintenance costs/increase development speed and improve performance?
BTW, I'm not sure what is actually meant by a "lack of runtime" for C++/Rust/Zig. They all have standard libraries, just like Java. Rust even has a (crude) GC in its runtime that most Rust programs use (and, like Java, it compiles down to a VM). I think what people mean is that compilation to native is typically AOT rather than JIT, but that has both pros and cons.
[1]: https://openjdk.org/jeps/450
[2]: E.g. https://openjdk.org/jeps/254
Being a memory hog was not such a big deal in the pre-cloud era, but we pay real money for that (far too much!) these days, and leaner approaches are worth a lot in real monetary terms.
I wish push back on some of your other points. Java has evolved quite a lot lately, with improved syntax, much improved runtime (Loom!), better GCs, lots of libraries, etc. The community is a bit stale though, and it's viewed as the Oldsmobile of languages. But that old language still has a skip in it's step!
Java tends to prefer using available memory, before it has to clean it. This results in memory usage growing more than it actually needs.
Services often run in containers, so this is less than a problem today than it was before, because the allocated memory to the container is fixed anyway. Try configuring the JVM to only use 75% of the container memory. In many cases, it will trigger an early GC and run better with smaller memory instances
There are of course some overhead for objects compared to primitives, but the Valhalla project is working to reduce the difference significantly on many cases.
You can also reduce memory usage and startup time by compiling to a binary image
Python? Huge respect, huge ecosystem, however I don't know if it's just me but I find it mighty hard to read. PHP with the "->" and Python with the space-sensitivity... Not sure why but it's so hard for me to overcome.
I use Ruby for scripting because it has a big standard library (unlike javascript) and an expressive syntax. The syntax is also very readable and short. It's also easy to install gems globally and use them. Things only need to be imported once.
I wouldn't say these things are qualities for big projects though. I like Typescript for big projects.
The learning curve was not that hard, and I got comfortable with it.
In contrast, I find React, Next.js and other frameworks more complex, and it takes a lot longer to be comfortable
I thought they had just hallucinated `java.io.IO`, but apparently it's a new type, available in Java 23 with --enable-preview: https://docs.oracle.com/en/java/javase/23/docs/api/java.base...
I still like to use Ammonite as a REPL, but scala-cli has replaced it for me in those cases where i get fed up writing bash.
Deno has been my go-to scripting tool lately. Similar benefits to Java as used by the OP, but it also allows you to import dependencies directly by URL, which means you can have your script self-define dependencies without a separate manifest file
You don't even need main methods and class wrappers, can import libraries with annotations with Grape, etc.
The real failing of cli and scripting in jaba and groovy is running cli commands with access to stdin stdout stderr streams. I have figured out the dark art for groovy but it takes quite a few stack overflows to get there.
It feels instant, no need for GraalVM.
You don't need to fool with Gradle or Maven or Ant if you'd like to incorporate third-party or your own custom dependencies in single-file "Java scripts".
Just copy some .jar files into ~/lib, and in your `.bashrc`:
export CLASSPATH=~/lib;$CLASSPATHIts a cli based artifact fetching tool for the JVM ecosystem, and you can have it just make up classpath strings for you, i.e., to use some Apache dependencies with the single file simplified java running you could just:
java --enable-preview --class-path (cs fetch --classpath org.apache.commons:commons-collections4:4.4) program.java
Also, maybe do have a look at scala-cli: https://scala-cli.virtuslab.org/ It does work just fine with Java files, and allows you to write single-file programs that include dependencies as special comments. The tool has some idiosyncrasies (like a background compiler server), but overall works extremely well if you need some of the power of a build tool, but without having a complex project structure.
I always disliked Java until I was converted by some developers of that group in a past job. I suppose it is fair to judge a language by the overall flavour of its ecosystem, but it is a bit disappointing. I wish more people could see how simple and _good_ it can be when you use the JDK itself, and not go through other overcomplicated systems to use it. For example, Spring Boot is basically a massive pile of hacks (regardless of whether you consider it good or bad), and Java only really serves as an underlying support technology for it.
Java has been great for larger projects for a while, but I think smaller things like one-off scripts have been firmly out of reach so far.
It's good to see that change, as being able to use it in the small has obvious synergies.
why specifically?
Having to compile every time (or at least there not being a convenient wrapper that compiles and runs at once), the boilerplate of having to define a class and main method, exception handling, and most of all having to deal with Maven.
result, err := callFoo()
if err != nil {
return nil, err
}
No collection streams means LOTS of mind-numbing/eye-glazing for loops. Things have improved slightly with the slices and maps package but these are just hacks. Maybe with the new iterator support, Go will slowly and steadily get a bit more expressive.Go is good for middleware coding thanks to Go-routines and and excellent networking support in the standard library but is cumbersome slow and inexpressive for scripts.
Also go.mod does NOT separate dev/test/prod dependencies - unlike Java Maven or Rust Cargo. You don't want your script dependencies coming into production code.
Also, in many areas Java's standard library is more expansive.
Also, go run is almost like running a script.
package main
import "fmt"
func main () {
fmt.Println("hi")
}
// go run file.go
You can write this in any text editor, but using one with LSP support means that `import` statement is added automatically, and with CoPilot or another assistant, the `main` function writes itself as well as any `if err ...` statements. Go is extremely well suited to code generation due to how predictable it is.Adding dependencies with `go mod` is uneventful.
It will never be as 'scripty' as JS or Ruby, but the readability, safety and performance are totally worth it.
Is limited features (Go) gonna be better for AI generation then breadth of examples? (C#). I'm not sure.
puts "hi"
And the crystal version is just as typesafe and performant as the go version. I also find it more readable, but that is a very individual metric.As I mentioned, yes, it's verbose, but simple and worth the effort and peace of mind. My primary language is JS, I've written a fair share of shell and Ruby but would still choose go a lot of the time, just because it doesn't pull in any extra complexity.
This is part of my standard Go build.sh script. You just never know who might want to run a given thing where.
It was really dumb, but that's what the client needed. So much cross compiling.
GOOS=linux GOARCH=amd64 go build
GOOS=linux GOARCH=arm64 go build
GOOS=darwin GOARCH=amd64 go build
Which again, let's me distribute a binary to my end user as a single file, without directing them to install java or python3 or whatever.
(The ARM question is kinda immaterial, but I'm curious)
Java is a fantastic "scripting" language as long as you're fine running it in an IDE. Clean and typed syntax, powerful standard library (especially for data structures), great performance. A better choice in these respects than say Python, Bash, or Go.
I've used it for scrapers, Advent of Code, plain ole data munging and of course programming interviews.
That being said, I would never write a webserver in Java in 2024.
I don't know, this just seems more like inertia. "I'd rather stick to what I know best than this popular thing." Which is fine, and I'm glad Java has made improvements making it easier to hit the ground running. But blaming the use of Java on the inadequacies of Python? The python API can do just about anything, it has regex toolings, I've never found myself needing anything else. And the typing complaints? Yeah it can be annoying if you're not good at keeping track of your own typing hints, but modern python supports type annotations and linters like mypy[1] catch everything related to that just fine. I've always admired many of Java's features, but let's not act like the reason for using Java for scripting is the pitfalls of Python. It's just because of an underlying preference for Java.
If you write all the code you deal with, then sure. My experiences on big projects tend to be typing problems introduced by libraries. The kind where documentation and the decorators suggest it'll only ever return some specific value type, but then very occasionally it'll return a tuple of that value type and a message.
Overall, I think Kotlin is a vastly superior language to Java and spanks Scala in discoverability and legibility (less magick moar bettar, IMHO)
Kotlin on the other hand had better IDE support in intellij for obvious reasons. That was not nearly compelling enough for me.
But, in short, you can write kts shell scripts; import any library you want, use anything in the JVM or the Kotlin or Java library ecosystem that you need, etc.
Works on the command line (you need a jvm and kotlin installed from your favorite package manager). The Kotlin Jupyter kernel also uses kts and this is a nice way to use Java stuff in jupyter.
- Top-level functions/main is supported - data classes are approximately as good as records - A scripting mode comes built in, and can use annotations to import and use dependencies within the same file - There's a repl - The keyword 'var' exists, and the keyword 'val' is more ergonomic than 'final var'
The only thing I remember missing from the article is the implicit imports which I don't remember Kotlin having. Regardless, I'd reach for Kotlin every time. I think funnily enough Java never fully clicked for me until I started using Kotlin, which in many ways is "Java, except many best practices are on by default".
I use Kotlin scripts (.main.kts) as a replacement for Bash scripts for years.
You can inline dependencies without additional tooling, and Kotlin is still much more expressive than Java.
I am currently a heavy user of JRuby for quick and dirty scripts but still want to be on the JVM, but I'll give Java 23 a go and see how far it goes.
I was also surprised when I looked at it again a year ago.
I would have used it for my latest Web app but django just beat Spring boot.
"Wow! It's even worse than I remember!"
"Wow! How many files and directories does this project NEED? It's like someone decided that it's easier to manage files than code..."
...and there's still XML everywhere :(
One nit:
> Python programmers often use ad-hoc dictionaries (i.e. maps) to aggregate related information. In Java, we have records:
In modern Python it's much more idiomatic to use a `typing.NamedTuple` subclass or `@dataclasses.dataclass` than a dictionary. The Python equivalent of the Java example:
@dataclasses.dataclass
class Window:
id: int
desktop: int
x: int
y: int
width: int
height: int
title: str
@property
def xmax(self) -> int: return self.x + self.width
@property
def ymax(self) -> int: return self.y + self.height
w = Window(id=1, desktop=1, x=10, y=10, width=100, height=100, title="foo")What do you do when another module needs ymin, inheritance?
OO is dead, leave it buried umourned.
And yet so many programming languages, including JVM languages like Scala or Kotlin, just don’t do checked exceptions, and the world hasn’t caught fire yet (and in fact, I can’t think of another mainstream language that does have them). Java could just drop them altogether and everyone (except maybe the most devout Java fans) would be happier.
> The file gets compiled on the fly, every time that I run the script. And that's just the way I want it during development or later tinkering. And I don't care during regular use because it's not that slow. The Python crowd never loses sleep over that, so why should I?
Java takes significantly longer to compile than Python does. My Python takes ~40 ms at first startup of a hello world script, ~20 in later attempts. `java hello.java` is in the 360-390 ms range.
There is nothing wrong with checked exceptions and there is really no difference between a Result and a function with a checked exception.
fn a() -> Result<String, SomeError>
String a() throws SomeException
The issue is not with checked exceptions but with Java’s syntax. They have not given programmers the language syntax to easily deal with checked exceptions. You cannot easily escape them without boilerplate and they don’t work correctly across lambdas. This is why Rust ships with ?; Swift has shipped with try!, try?; and Scala ships with try as an expression and is experimenting with checked exceptions that work across high order functions [0].Programmers across every language ecosystem are moving towards checked errors and away from unchecked runtime crashes. Even Kotlin, a language that shipped with unchecked errors, is planning on adding a form of checked error handling [1].
[0] https://docs.scala-lang.org/scala3/reference/experimental/ca... [1] https://youtrack.jetbrains.com/issue/KT-68296
That's still pretty negligible. I don't think he's making a strict comparison, just saying that in both cases it's barely noticeable.
Shame the link is broken, looked fascinating!
Postgres also had a long-held reputation for being slow and difficult, but it made incremental improvements for decades and now it's the default choice for databases.
I see Java in the exact same position, as the Postgres of languages.
It feels like these frameworks are now just falling away, which is great. I'm not even hearing about Spring anymore, and if there is any reason to not use it, it would be this cringe "how do you do fellow kids?" blurb I just saw on their front page:
> Level up your Java™ code
> With Spring Boot in your app, just a few lines of code is all you need to start building services like a boss.
I personally would reach for Go by default, but I have no ill-will to Java.
Given, they are still quite reflection-heavy and full of POJOs and annotations, it supports compile-time resolution for many things now.
Also, you would be hard-pressed to find a more productive developer than a well-versed Spring boot guru for typical backend jobs. You might dislike the framework, but credit where it's due, it is a workhorse and the amount of time someone makes a POC, you can make it with spring properly, in a way that you can build your prod app on top. Like, it's easily as productive as RoR and similar.
I agree with the sentiment, but I'd move up to a version with type inference at least. I have nothing against static types and in fact in a vacuum I prefer them, but the particular brand of OO and "weak" generics that Java and C# have feels like filling forms in triplicate. "var" alleviates that significantly.
Conversely, in Java you often use the diamond operator like in:
List<String> items = new ArrayList<>();
(Half of which, again, is code completion in your IDE.)That doesn’t work with “var”. You’d have to write:
var items = new ArrayList<String>();
while losing the ability to constrain your variable to a narrower type.The loss of directly seeing the type information in statements of the form
var foo = bar(x, y);
should meet a very high bar, IMO..NET has true generics with full type information and struct type parameter monomorphization which works the same way generics do in Rust.
Edit: C# does have type inference for generics, just not the full HM one. It is also quite more capable for lambdas which is a bit frustrating because it does not resolve nested generics otherwise. I miss it - F# does it the way it always should have been.
There are many other differences small and big that arise from the way Java does generics and the fact that primitives can't participate - you will never see `IntStream` kind of workarounds in C#. Some libraries abuse and misuse generics for no profit (looking at you Azure SDK), but it's not as widespread. Shallow generic types are always inferred from arguments.
I do agree that new ecosystems (js for instance) makes you miss some of the old big languages development feel. less churn
The only thing I don't like is how there is no built-in JSON package which seems like a necessity these days.
Removing the public static void main(String[] args) business seems like pandering to a non-existent audience, or at least a miniscule and insignificant one. Anyone who is going to use Java for a real project is not going to be worried about that, and anyone who thinks that's too difficult to deal with is never going to be a good programmer anyway.
If you want to introduce someone to programming, you probably don't want them to worry about what all those 'magic words' do.
At least for their first steps, they won't need to know what a class is or what `public` and `static` mean.
About the first steps of a newcomer, there's always going to be some level of "don't worry about this now, we'll see what this means later" for any language. I remember this to be the case for every tutorial I read to learn a language. And it's fine, as long as you can try stuff and it doesn't get in the way.
I'd say it's more important for a language and its vocabulary to be well structured and well documented for a newcomer and Java does quite good on this front.
Sure, if you are incapable of learning what a couple adjectives mean you won't go far, but that holds for much more than software.
Rather it's not important that the ball is big and blue so much as that you can kick it across the field - learning what the ball means can come later, but it's just unimportant noise (to start).
Java is pretty bad at this, though, insisting on specifying unimportant details up front rather than allowing for qualification. This is OK for a large monolithic application with complex requirements and a litany of edge cases, but inappropriate for many smaller use cases.
I still feel like the author is missing the forest for the trees. Bash is not great to write e.g. a red black tree in or do complex image processing, but you don't have to maintain a Java install, download libraries, or setup an editor with an LSP (and really, calling java script.java 10 asdf? Why do I need to invoke Java at all? At that point, I'm probably going to wrap it in a script anyways...)
Python has its own issues but it's a small, embedded install that you don't have to accept 5 different licenses for and worry about it being able to get the same version...
And bash? That's what pacman -S jq is for - anything I can't easily do in bash or batch I just offload to a small utility written in python or rust.
Java is, at it's core, just too heavy, IMO.
There is also jre-openjdk-headless, for 140 MB. How is that any different than Python?
This "java too heavy" is like 30 years out of date, if it has ever been true.
I learned Java when i was 15 or 16, reading some random book first and then I stole 35 euros from my mother's purse and bought a copy of "Java how to program" by deitel and deitel[1]. The recommended version at the time was Java 5, and the SJCP certification was still issued by Sun Microsystems.
I can tell you, "public static void main" is not going to be the problem.
[1]: looking back (i'm in my 30ies now) sometimes I wonder if i would have been better off buying weed or alcohol (or both)
What other language would you start with?
And isn't it easier to introduce concepts one at a time? For that reason implicit classes makes sense, and also for the occasional scripting, as in doing something one-off, but it is not as trivial that I can do it with piping 3 commands together.
Your csci 101 kids will not benefit from unpacking what it means to compile an object-oriented language down to bytecode to run on a virtual machine. It's not that it's not valuable knowledge, they just won't have the context to make meaningful heads or tails of it.
related: I still puke a little remembering the requirement that students work on assignments in emacs on terminal machines rather than their text processor of choice(which was fine for me, but why on god's green earth would you put usability warcrimes like 'hjkl' in the way of someone just starting to learn? No wonder nobody in the early naughts wanted to learn to program...).
On the other hand, viability, classes, and "staticness" are all fundamental structural concepts in Java. Hiding them for a special case is sort of like lying, and, in the long term, I can actually see this special case causing more confusion for new learners. It's sometimes better to be upfront and transparent and force your users to work with the paradigm and semantics they chose to adopt, rather than pretend it doesn't exist. If Java had been designed to allow for top-level functions from the start, it'd be a different story. I think special casing is a generally bad way to evolve a programming language.
You simply get an unnamed implicit class like `class Tmp367 {` written at the top, and the runtime loader has been modified to be more accepting of main methods. There was basically a tiny language change, and no bytecode change, java semantics are just like they always were.
The Main loader just simply will accept an instance method named 'main' for a class with an empty constructor with no args, instead of psvm.
Perhaps the audience doesn't exist because of that business. There are many times when I would have used Java over Python to write simple programs for no other reason than having the ability to create a GUI without resorting to third-party libraries. Yeah, Python has tk but it has never clicked with me in the sense that Swing does. Unfortunately, cramming every last thing into an OOP model means that simplicity is rapidly lost. (The same can be said of Python, except Python has not forced it. Java, historically did.)
Pretend you are a college student and you are taking your first programming class (e.g. CS 1) and your friends have told you that Java is "verbose". You start with "hello world" and you have to type `public static void` etc. One of your friends shows you the same code as a Python 1-liner.
Or similarly you're a beginning programmer in the workforce and your employer asks you to solve a problem using Java. You've heard Java is verbose and when you start with "hello world" you find that what you heard was true.
This is not a non-existent/minuscule audience. They should have fixed this decades ago. Better late than never.
I've been impressed with the modernization of Java over the last 10+ years. Simplifying "hello world" is a minor change relative to the others, but still an important one.
I watched most of my comp sci 101/102/201 classmates fail out because they didn’t want to understand how things worked, they just wanted to make a lot of money.
Edit: hn even helped me prove the point: https://news.ycombinator.com/item?id=42457515
Teach that to a 10 year old, where their primary keyboard experience is a phone.
More than that, if rust is the future, which I have seen espoused before, picking on the Java keywords and syntax is highly amusing.
Now, if one is learning java as a second language, that's a different story.
https://jakarta.ee/specifications/platform/10/apidocs/jakart...
If it's part of J2EE, it's in practice "part of Java" since the JDK comes with the J2EE packages built-in...
That is, it came with the J2EE packages built-in, until Java 11 decided to break everything, and force people to get each piece of J2EE from a separate upstream project, with AFAIK no "all of J2EE" uber-jar you could simply copy into your project to restore the status quo. It's no wonder so many projects are to this day stuck on Java 8.
Also, thank you for sharing! I do appreciate Java and I’m glad to see it can be used for scripting nowadays.
The difference is so stark it's no longer amusing. Performing setup for complex Java projects has me go through similar steps as if they were written in C++. Performing setup for C# projects of comparable complexity usually requires just cloning and hitting 'dotnet run', much like it usually happens with Rust or Go (some may claim I undeservedly bash it but credit is where credit is due).
I love your identity with .NET ecosystem, to the point of nothing else being in the way.
See latest JetBrains Developer Surrey about platforms.
.NET is a great ecosystem, but lets be real where it stands outside Microsoft shops, across everything that has a CPU on them, and the various ecosystem where sadly it doesn't even get a tier 1 support.
Programming languages are tools, a toolbox has space for plenty of them.
https://learn.microsoft.com/en-us/powershell/module/microsof...
One thing to note is I find `dotnet fsi {some script name}.fsx` taking more time to start than ideal - up to 800ms is just too much, normal .NET applications usually start in a fraction of this.
I recently posted a submission here for "FSharpPacker" written by my friend that lets you compile F# scripts to standalone applications (either runtime-dependent, self-contained or fully native binaries, much like Go), it also has some comments on getting the best mileage out of it: https://news.ycombinator.com/item?id=42304835
Probably the best feature that also comes with scripting (both C# and F#) is "inline" nuget references e.g. #r "nuget: FSharp.Control.TaskSeq" which will automatically pull the dependency from nuget without ever dealing with manually installing it or tinkering with build system in any other way.
Some additional links:
https://learn.microsoft.com/en-us/dotnet/fsharp/tools/fsharp...
https://github.com/dotnet-script/dotnet-script (C# is also a quite productive language for scripting and small programs because of top-level statements, record types, pattern matching and many other functional features though perhaps not as strongly represented as in F#, it's just very unfortunately abused in enterprise world, with teams often going out of their way to make the code far more bloated than necessary, against the language design intentions)
Already disagree, haha
I have to say I find it an odd choice for small replacements for bash scripts. I think python or golang are probably better choices for that purpose. Java is one of those 'enterprise' backend languages which lend itself to making a team productive over making the individual productive, and I say this as a java / go dev who's most comfortable with java for most backend work.
I just loved his lectures, very dry sense of humor, and extremely funny.
He was just getting started writing books in the early 90s. He has this awesome way of thinking about programming, that I imparted to my own students when it came my turn to teach programming. I wish there some videos of his classes that I could go back to and share with people.
Good website also, https://horstmann.com/
The picture on the website with him in the row boat has a funny story with it. When asked why he is in a row boat, he would reply, "Students are in the row boat with me, learning to program. At some point I push them out of the boat into the eel infested lake. The ones who are clever enough to make it back to the shore will be good programmers." All of this said with a faint hint of a German accent and a sly smile.
If you happen to read this, Dr. Horstman. I made it to shore. Thanks! It has been an awesome journey!
What I remember most is his obsession with Emacs.
There was one time that I was grateful though, I had to buy a few of his books and one of them had a defect from the printer, so he helped me get a new copy from the publisher for free.
That's a really insightful way of presenting this. I think if that's how I'd been introduced to Java I might even have tolerated it.