r/programming • • Feb 22 '15

Java Makes Programmers Want To Do Absolutely Anything Else With Their Time

http://www.forbes.com/sites/quora/2015/02/21/java-makes-programmers-want-to-do-absolutely-anything-else-with-their-time/
35 Upvotes

636 comments sorted by

View all comments

Show parent comments

3

u/Milyardo Feb 22 '15 edited Feb 22 '15

This assertion is pretty easy to test as well.

cat <<'EOF' > hello.scala
#!/usr/bin/env bash
exec scala -savecompiled "$0" "$@"
!#

println("Hello World")
EOF

chmod u+x ./hello.scala
time ./hello.scala

Which produces:

$ time ./hello.scala                                                                               
Hello World                                                                                                 
                                                                                                        
real    0m0.833s                                                                                            
user    0m0.513s                                                                                            
sys     0m0.054s
$

and on the second run after compilation:

$ time ./hello.scala                                                                               
Hello World                                                                                                 
                                                                                                        
real    0m0.387s                                                                                            
user    0m0.361s                                                                                            
sys     0m0.048s

Mind you the version of scala I have installed to my path right now is ancient and an actual Java Hello world would start up in less time:

$ scala -version                                                                                   
Scala code runner version 2.9.2 -- Copyright 2002-2011, LAMP/EPFL                                           

2

u/Nutomic Feb 22 '15

The discussion was specifically about java.

Scala has a longer startup time because it has to load its (bigger) standard library.

3

u/Milyardo Feb 22 '15 edited Feb 22 '15

The discussion was specifically about java.

The discussion was specifically about the start-up time of the JVM and the Java runtime.

Scala has a longer startup time because it has to load its (bigger) standard library.

I already mentioned this fact, but that's not why a Scala's Hello World would take longer to startup. The number of classes you have on the classes you have on the class path is irrelevant, classes are only loaded on the JVM as they're used. In this case Predef.scala and Console.scala are the only extra classes used.

Scala would take longer to startup because of the scala shell script executable which runs MainGenericRunner, bootrapping the compiler before running our hello world script that was already compiled.

1

u/Gurkenmaster Feb 22 '15

The discussion was specifically about the start-up time of the JVM and the Java runtime.

Yes but a large number of Clojure devs complain about JVM startup when it's caused boostrapping their core library.