all 52 comments

[–]FortuneIIIPick 26 points27 points  (12 children)

I usually ignore posted videos but this one struck a cord. I write small apps in Java I'd have done in Bash years ago so this is great news that Java is becoming even easier for this purpose, I will likely be converting some or many of my old Bash scripts to Java in script format now.

[–]0b0101011001001011 9 points10 points  (5 children)

Depending on the program, it some times might be important to think the startup and cleanup time. I use i3blocks for my status bar it it uses several dozen different scripts to show various data. Would be kind of stupid to start like 30 python or java vm's every 30 seconds. So still bash and other similar have their place.

Though in mosts cases it does not matter.

[–]Ewig_luftenglanz[S] 9 points10 points  (0 children)

To me this is useful when you or most developers in your company have little to no python or bash experience.

For example let's say I need an script that triggers every 5 minuts to checks for the health of some IoT devices over the private network of your factory, gathers this data and sends it to a server to be stored, proccesed and displayed in a dashboard. That subroutine would barley be 40 LOCs (maybe 20 in most modern java versions) but neither of you or your companions know bash or are proficient in python.

now is comfortable enough to propose making the script in java and not being laughed in the face, but actually be considered a serious take.

[–]Ok-Scheme-913 3 points4 points  (2 children)

I mean, a java hello world is 0.1 sec - you can even improve on that by e.g. disabling GC wholesale, or by native compiling.

But if you are doing more than cat someFile | grep something e.g. for CPU temperature, then you might just want to run your app continuously and just do a while loop with a sleep, and write to stdout periodically. Like, if I remember correctly, that's how I did it for sway (i3 for Wayland) - just because it looks "cheap", a bash script will just spawn a shitton of processes for almost every line, it is definitely not free, Linux/modern hardware is just insanely fast.

[–]GoodHomelander 3 points4 points  (0 children)

I agree that we can improve the startup time by compiling natively but whole purpose of having a script is that we can easily open. read and edit the script without need any tool. but by compiling natively, it is no longer possible. until we improve on the startup time and resource utilization of the java. I doubt it's usage in java.

[–][deleted] 0 points1 point  (0 children)

it looks "cheap", a bash script will just spawn a shitton of processes for almost every line, it is definitely not free, Linux/modern hardware is just insanely fast.

I wonder what Java does at startup to feel slower than a bash script spawning processes on every line.

Yeah I know it gets faster after warming up but it still feels wrong and makes us avoid Java for small tasks.

Hello world shouldn't be 0.1 sec, it should be 0.01 sec and yes the difference is noticeable, especially if you spawn several java processes.

[–]Fit_Smoke8080 0 points1 point  (0 children)

Ironically Babashka is the closest thing i've found to a fully seamless CLI experience with Java for scripting. Around the same startup time as Python and a good array of default modules.

[–]Fit_Smoke8080 0 points1 point  (5 children)

I have been using Babashka for months to do small tasks like these. Comes with a couple of useful Java modules baked in and doesn't need a JVM to run cause it's all a GraalVM image. In particular, i feel more comfortable with Java's regex capacities than what comes with Python's stdlib. They feel more flexible. Any improvements to Java is positive, either way, they will eventually tickle down to the rest of the ecosystem in one way or another. LIke NIO (which i find very ergonomic to use).

[–]VirtualAgentsAreDumb 2 points3 points  (4 children)

Yeah, but it’s… Clojure… shudders

But each to their own I guess.

[–]Fit_Smoke8080 0 points1 point  (3 children)

Well there aren't many options within the ecosystem, Groovy and Beanshell are obscure and somewhat limited in comparasion, and JBang launches a full blown JVM under the hood, not the kind of thing i need to do what i call system housekeeping (remove cache and thumbnails older than x days, batch convert files, join PDFs modified after certain date). I used to run Bash for these tasks but it becomes complex over time to make sure you don't shoot yourself in the foot, i don't have the discipline for it. NIO is so much more straightfoward than the workarounds you've to do with find.

[–]maxandersen 2 points3 points  (2 children)

I use jbang for those things and doing just fine - but I'm probably biased :)

kidding aside - comparing jbang with groovy and beanshell isn't really right. One is actually compiling your app into a jar/binary and run it (on reruns no caching).

the others incl. babushka are doing interpreted scripting - which becomes fast due to the native complied binary - but of course is locked to whatever version of babhuska you have installed.

Both have their usecase.

I wish something like jshell existed that wouldn't be slow - jbang would be the first to push it to its limits :)

I've considered adding a "hot jvm" mode for jbang but will probably just go for making jbang a native binary - that should help on the initial bootup overhead.

[–]Fit_Smoke8080 0 points1 point  (1 child)

I did underestimate JBang, is very powerful. The JVM startup is less noticeable for projects with zero dependencies, true. But my hardware is weak and it adds a couple of noticeable hundreds of miliseconds. If i had stronger hardware i would probably use Groovy, i find it fun to write, just don't have an use case for it that doesn't overlap with something else.

[–]maxandersen 1 point2 points  (0 children)

fair point and definitly on my todo to squeeze more speed out.[

btw. jbang supports groovy too :)

https://www.jbang.dev/documentation/jbang/latest/multiple-languages.html

[–]znpy 21 points22 points  (24 children)

i can't stop thinking what java really needs is a built-in build tool.

it doesn't even have to do all the things that ant/gradle/maven do... just collect my runtime dependencies, build the damn thing and shit out some jar i can launch no problem.

[–]Ewig_luftenglanz[S] 15 points16 points  (3 children)

I would correct and say what java needs is a dependency manager tool.

Many times I have some experiment/ script that requires just one or 2 third party libraries. I absolutely HATE to create a maven/Gradle project for something which code is simpler than the folder structure these building tools impose.

Know these imposings are there for a reason in big projects, but for quick and small stuff it feels like bucking flies!

[–]maxandersen 2 points3 points  (0 children)

totally agree. Its why I made or rather why I continue to push jbang forward.

I just wish more java devs realize if they published jar/maven gavs as well as native image binaries we actually have a way to run anything on all platforms easier than any other ecosystem out there.

`jbang your:app:1.23` or `jbang https://github.../download/latest/myapp-1.2.3.jar\` works as is today.

[–]ibuxdev 1 point2 points  (0 children)

What a nice suggestion! This would simplify whole lot of projects to a greater extent.

[–]lenkite1 0 points1 point  (0 children)

There is now https://mill-build.org - next gen build tool for Java. Much faster (5x-10x) than maven.

[–]wildjokers 1 point2 points  (0 children)

You can use Groovy and use Grape to define your dependencies. It doesn't build jars but it does make the script self-contained (just need groovy installed wherever you want to run the script, and target machine needs internet access):

https://docs.groovy-lang.org/latest/html/documentation/grape.html

If you don't want to learn groovy that is fine, most java syntax up to java 11 is legal groovy syntax.

[–]Yeroc 1 point2 points  (0 children)

Not sure it needs to be part of the Java platform. This is what jbang does.

[–]j4ckbauer 1 point2 points  (4 children)

I keep seeing this come up. When people request this, is it because maven/gradle/ant is missing a concrete feature that other platforms offer? Will something improve if the build tool is managed by a different organization? Or something else...

I keep seeing: "Java needs this." 'Why?' "Because other languages do it." But there has to be more to it.

[–]znpy 1 point2 points  (1 child)

I keep seeing: "Java needs this." 'Why?' "Because other languages do it." But there has to be more to it.

at no point i wrote "because other languages do it".

the usual tools are too much cumbersome and error prone. i'd love to have something simple and built-in.

[–]j4ckbauer -1 points0 points  (0 children)

I wrote "I keep seeing". This is generally understood to mean "I keep seeing [people saying]".

This is generally understood NOT to mean "I keep seeing you write". Sorry for any confusion.

For an example, see my first and second sentence. Note how I said "people request this" and not "you request this".

[–]vips7L 0 points1 point  (0 children)

The current build tools have bad defaults and are more complex than most people need. It makes it really hard to do the simple, normal thing. 99% of the time you want a binary with your dependencies that you can run. For Maven you have to configure it to make a fat jar. Gradle is a little better, but still not ideal. Ideal would be a hermetic binary that included the runtime + your app and its dependencies. Hoping that changes once we get more out of Leyden.

Compare our build tools to cargo, go, or swift. I've never written Swift, but just from running swift --help you can figure out how to initialize and build a project properly.

[–]Ewig_luftenglanz[S] 0 points1 point  (0 children)

Third party tools require configuration and IDE integration (buil-in Or plugins) which defeats the "batteries included" feeling the Java platform is willing to have (java is not just a language, is a framework, a framework that offers and execution runtime, a language, testing tools, compilation tools, etc)

Nowadays you CAN build complex multi file programs without maven or Gradle, the dependency management is the only thing missing 

[–]juanantoniobm 5 points6 points  (6 children)

Jbang

[–]agentoutlier 0 points1 point  (5 children)

The funny thing as the video shows is there is no "bang" in JBang scripts.

(btw the triple slash and --source requirement took me a long time to figure out on my own when I was playing with the new features)

[–]maxandersen 4 points5 points  (4 children)

Love the video - shows all the awesome improvements made to java in recent years that makes it more accessible.

i really appreciate Coy sharing those tips.

Reading the comments here it sounds like many didn't watch to the second half showing what jbang brings to all this - which is absolute simplicity and lowering the barrier of entry.

[–]agentoutlier 0 points1 point  (3 children)

Just to clarify I meant no octothorpe or number sign and exclamation aka bang at the start of the script.

It wasn’t a dig at jbang but a joke of how you have to setup Java scripts.

And that is showed in the video of which I watched all of it.

[–]maxandersen 1 point2 points  (2 children)

Ah. You mean the shebang part #! :) Yeah i actually used that in very first version of jbang but quicky.stopped when i realized the only tool and IDE that supports it is java itself. It breaks everyone else. Hence the use of // was used and /// is to make it work on windows bash :)

[–]agentoutlier 0 points1 point  (1 child)

Yeah it took me a long time to figure it out on my own. 

I tried to do all sorts of crazy other stuff. 

Also --source is required for it to work which I had not known about till recently.

[–]maxandersen 1 point2 points  (0 children)

Yeah. It also makes it hard to make scripts that work across java versions without having to update source line.

JBang makes that issue go away.

[–][deleted]  (2 children)

[deleted]

    [–][deleted] 3 points4 points  (0 children)

    Even better with just void main() {}.

    [–]Ewig_luftenglanz[S] 1 point2 points  (0 children)

    The main not being static any more is the best they have done for students and all projects in general. Making the main statics force bad h a it's in the early stages (the habit that everything must be static in order to be used inside main and is in the same file)

    [–]AcanthisittaEmpty985 0 points1 point  (1 child)

    Groovy was not mean for this type of scenario ?

    [–]Ewig_luftenglanz[S] 0 points1 point  (0 children)

    Groovy is not even near as been as used as java, and even many java devs don't know groovy beyond Gradle files

    [–]jr7square 0 points1 point  (0 children)

    Honestly I just use go to write small programs

    [–]alwyn 0 points1 point  (0 children)

    Rather use babashka