5 ms·
Many of these points apply to programming languages that are arguably more enjoyable than Java, including JavaScript (TraceMonkey), Python (PyPy), Common Lisp (
by jrockway 17y ago
Many of these points apply to programming languages that are arguably more enjoyable than Java, including JavaScript (TraceMonkey), Python (PyPy), Common Lisp (SBCL), and Haskell (GHC).
For most workloads, even hard-core number crunching, it is pretty straightforward to get near-C performance out of those languages. I am not sure why anyone would even bother with Java.
- Nelson69 17y agoBy "straightforward" to you mean "theoretically possible?" If that were the case, nearly everything would be written in Python. Maybe there is a specific case you're thinking of because in the general case it's non-trivial and possibly impossible. You're not getting near-C performance by simply dropping to C are you? That's not a terribly acceptable answer. I don't know why these things come up all the time. Java is pretty fast for a managed language, certainly faster than a lot of people think but it's not C. Python, Ruby, etc? They're way far behind in performance, particularly tight loop number crunching type stuff. That doesn't make them bad choices for things though. There isn't a subjective answer, I think it was Top Gear 2 weeks ago that said "You don't buy a supercar with your mind because it doesn't make sense, you buy them with your heart because you love them." The same thing is true here. If you want to be subjective there are all sorts of other variables you'd have to factor in, tooling, libraries, dev time, availability of quality developers, maturity, likelihood of future support (you laugh, I wonder with Ruby and Python and Perl all going through these giant shifts, they may never be the same and as unified) Can you actually compile your code or do you distribute source code? All those things in play and it gives Java a fairly compelling story even though a lot of people want to hate it. The better discussion, at least to me, is with so many compelling options that perform as well as they do, why does anyone bother with C? With various buffer overflows being so prevalent and it being so easy to have a bug that poses a real security risk, is it worth that?
- jacquesm 17y agoTracemonkey is a pretty big development. In the longer term it will allow plenty of stuff to migrate to the web in one form or another. As for why people would even bother with java: - legacy - the ability to have shared state between the threads of a web server (such as an in core object cache) - corporate dictates
- ilyak 17y agoAlso, huge libraries. For example, POI (Excel) or Lucene (full text search).
- bensummers 17y agoI've (just about) finished moving my project to JRuby. The combination of the Ruby language for most of the code, the vast selection of libraries, and the ability to drop down into Java for performance sensitive code is a joyous thing.
- ilyak 17y agoOr Rhino, JRuby, Scala
- ilyak 17y agoGHC is a static compiler; it doesn't belong here unless I've missed something.
- jrockway 17y agoIt is in the category, "fast, but not C".
- zmimon 17y agoIf it's straightforward to get near-C performance out of those languages, why do they lose out so badly in the language shootout? eg: Tracemonkey vs Java - http://shootout.alioth.debian.org/u32q/benchmark.php?test=all&lang=javasteady&lang2=tracemonkey&box=1 http://shootout.alioth.debian.org/u32q/benchmark.php?test=al... Java varies between 10 and 100 times as fast as Tracemonkey in all the tests. If you think it is straightforward to write code that equals C performance, you should do so and submit it to the shootout to prove your point. Personally, I don't believe you can :-)
- heyadayo 17y agoLooks like someone took you up, and beat C with javascript: http://shootout.alioth.debian.org/u32/benchmark.php?test=regexdna&lang=all http://shootout.alioth.debian.org/u32/benchmark.php?test=reg...
- blub 17y agoIt's straightforward because talk is cheap. Maybe jrockway could write some near-C speed Python or JavaScript code to enlighten us. And by near-C speed I don't mean 20% slower...
- berntb 17y agoI assume he was thinking of an area like web programming, where a DB mostly is the practical limiting factor for speed. (Or rewriting the (often small) speed critical parts in C, after benchmarking.)
- jrockway 17y agoNo, I wasn't. I was talking about the speed-critical tight loops. Once you let GHC or TraceMonkey or PyPy or ... know what the machine types of your data is, they will generate very fast code; often the same instructions that the C compiler would generate. C is fast because the programmer explicitly names the machine types to be used. Other languages are slow because their operations can't always be expressed in terms of operations the machine can do. (Consider Perl and "2 + 2". This is "slow" because 2 is a "SV", and that means before anything can happen, the integer 2 has to be unboxed from the SV, the runtime has to decide which "+" to use, and then the result has to be boxed in a "SV". This is much slower than running the "ADD" instruction. But if you can somehow specify, "this is not a special boxed value, just treat it as a machine integer and don't worry about overflow or anything special", then you are doing the same thing as C. Modern VMs (and static compilers) can guess this for you and generate the right code.)
- agazso 17y agoAfter the industry accepted Java as an enterprise language, lot of development went into optimizing the compiler and these were not academic developments, like your examples (maybe except TraceMonkey). Add this to the already existing huge amounts of libraries and the fact that Java is a perfect middle ground language in every ways, and you have the answer. Personally I don't like Java, mainly because of the 'framework culture', but I have to admit that a lot of progress was done in the areas of compiling and running Java code. Still despite that much effort, I still can feel when I use a non-statically compiled interactive application (e.g. text-editors, games etc.). Generally low latency responses for your actions and fast startup time seems to not to be the property of dynamic languages.
- silentbicycle 17y agoLuaJIT (http://luajit.org http://luajit.org), as well, and it's still very easy to move any hotspots out to C.
- bensummers 17y agoDropping down to C is available in pretty much any other language too.
- silentbicycle 17y agoYes, but since Lua has been designed from the beginning to embed in a C program, its developers take the C API very seriously. (At the least, you can use Lua as a C library providing a great string/atom system, script & config file parser, and a garbage-collected Python-like repl for automated testing and debugging.)
- bensummers 17y agoAgreed, some languages are easier than others. Another one which is particularly easy is Ruby. And, with JNA in Java, it's even pretty easy in Java.