7 ms·
Why I love Common Lisp and hate Java
- gatlin 15y agoThis feels like a lot of blog posts I write: the main content is probably there, in the author's head, but not enough of it was put on the paper. What we read instead is a slice of what I have no doubt in my mind to be a fantastic essay. I have recently begun a love affair with Racket and for a reason I think that the author was ultimately trying to get at: the core syntax of any Lisp is a minimalist tree and the semantics are lambda calculus (and abstract algebra to help motivate types). An REPL for Java could conceivably be written; AI is language agnostic; and plenty of languages let you eval generated code; but Lisps are a window into computation itself and it's very addicting.
- hendzen 15y agoBeanShell is basically a Java REPL.
- Deinumite 15y agoAny time I see someone complaining about how much effort it is to "just print a string to std out in java" it boggles my mind. Java was not really designed for ease of use in that way, clearly, and the syntax and vm itself heavily lends it to networked programming. This post would be better if it was "Why I love Common Lisp" with the half hearted stabs at Java taken out of it.
- koko775 15y agoSeriously. I've been doing Java for years and it had been so long since I wrote public static void main etc. that I had to look it up. If you're writing mostly classes to be run straight-up from the command line, you're doing it wrong.
- Stormbringer 15y agoActually, running the class straight from the command line can be a really cool way of doing ad-hoc unit testing. You can have a main method that instatiates an instance of the class, populates it with whatever it needs (including mocks if you're into that sort of thing) and then exercises the various methods of the object. It's like IoC but without all the bread and circuses. NB: it's been about 8-10 years since I did anything like that. Running from the command line is good for something that can run headless but you want to see immediate success/failure type messages. The other main use I had for programs run from the command line was small 'one-off' file format conversion programs. Once you've done half a dozen of these it's relatively easy to just bang out the ~100 lines of code to do this (including proper exception handling). Would it be faster to write it out in perl? Well, if the regex is sufficiently simple then yes, if it is moderately complex then you still use far fewer keystrokes, but getting it to the point that it is correct, that's easier in Java. (Assuming you optimise for readability, something perl... struggles ... with)
- gruseom 15y agoActually, writing code that can be called directly from a prompt is the essence of using a REPL. The fact that Java, and OO programming generally, makes that so hard is a major weakness.
- nessus42 15y agoI write Java programs that are designed to be run on the command line all the time. Just what is it that I am supposedly doing wrong? (That's not to say that most of the classes are to be run from the command line, but each CLI program has to have a class with such a method.)
- 6ren 15y agoSpeaking for CLI utilities (not apps in general), startup time is a killer. Python, Ruby, Perl etc are so much faster (despite Java improvements) since they began as "scripting" languages. One solution is to reuse a warmed-up JVM (even faster if also reusing already-loaded classes): 1. use a Java REPL, like BeanShell or Groovy (or write one). 2. call a Java server from the CLI I did (2) for a while, but not worth the saving of a second or so. BTW: I find "you're doing it wrong" is so unreasoned that best ignored
- Jach 15y agoAdmittedly I skimmed the blog post but I saw a complaint against the "Hello World", not how to print out a string. I agree the "System.out.print" thing is such a non-issue. If it really bothers you, make a class in your package that's a wrapper around it so you can call Utl.print() or U.o() or however short you want to make it. Meanwhile the rest of us will get back to programming. In the few years I've done a lot of Java development it's never bothered me enough to even make a vim shortcut for it. However, the "Hello World" criticism does make sense to me in this sense. There are at least 18 separate facts you need to know to fully understand a Java "Hello World" program (including how to compile and run it). For [insert almost any other language (not C++)] there is considerably less. (Python is 4 facts.) If your goal is to teach someone who has never programmed before a new language, Java seems like a poor choice in that respect. In any case, Clojure is where it's at right now man. It's pure awesome-sauce on its own and you get all of Java's goodies as a bonus.
- tsotha 15y ago>Lispers like to pick on Java. It makes sense, because Common Lisp has everything that Java lacks. But Java has a lot of things Common Lisp lacks, too. A GUI package. Network programming. Cryptography. Yes, you get modules for all those things. But having them in the core language means you know they're always available no matter where your code is running. I like Lisp, even with its painful syntax and poorly named internals (Seriously. "cdr"? "endp"? Was there a Great Keystroke Shortage in the '60s?). But it doesn't have the ecosystem for actually producing a product to anywhere near the extent Java does. There's a reason Java is used so much more widely than Lisp. In terms of syntax, I like what Rich Hickey did with Clojure. You still have all the Lisp functionality but it's a lot easier to read.
- hythloday 15y ago> Seriously. "cdr"? "endp"? Was there a Great Keystroke Shortage in the '60s? Well...yes? When jaw-dropping storage is a 1 MB hard disk, things like function names really do make a difference, especially when they're called so frequently. For the same reason, C89 identifiers are only 6 characters long (and hence the C naming convention of things like "strdup" rather than "duplicateString").
- tsotha 15y agoSure, because you can fit six characters in 32 bits. But still... those constraints are no longer with us, and there's a limited amount of historical cruft people learning a language today should have to deal with.
- Stormbringer 15y agoITWARM (if this was a reddit meme) Scumbag blogger: Takes Tai-Chi for a couple of months, thinks he is qualified to talk about 'qi'. Takes university course that touches on Java, dabbles in Lisp, thinks he is qualified to discuss 'failings' of Java Begs the question: if Lisp is so amazing and Java is so bad, why is Lisp a failure in the marketplace? ---- Remember that even Lisp's biggest recent (as in, in the ~17 years since Java was released) success (Paul Graham selling his store-thing to Yahoo) was quietly re-written in Java a couple of years later. If your answer to the success/failure question is that people who use Java are stupid-heads and people who use Lisp are wonderful geniuses, then may I suggest that you haven't solved the dilemma, you've just multiplied the entities by pushing it back a layer. In any case, nobody cares about Java vs Lisp anyway. All the 'cool kids' in that space (e.g. functional programming on the JVM) are into stuff like Scala and Clojure. To ignore those makes the argument kind of pointless... it is like having an argument between a Dodgers fan and a Patriots fan. The Dodgers fan says the Dodgers are better because they hit more home runs than the Patriots, and the Patriots fan says the Patriots are better because they score more touchdowns. It's just fundamentally stupid. Whereas if you compared Lisp and Scala, then at least you'd be talking about teams playing the same sport. Yes, it's still going to be as useful as watching a Patriots fan and a Dallas Cowboys fan argue about which is better, but at least the argument isn't based on fundamentallty stupid premises in that case.
- almost_usual 15y agoYour analogy doesn't make sense, Lisp and Java are both programming languages. Why not compare them? Also, learning Common Lisp can help immensely if you plan on doing any hardcore Clojure meta programming.
- Stormbringer 15y agoOf course it makes sense, Baseball and Football are both sports, why not compare them? Because as different sports it isn't really relevant. Are you going to say that cricket is better than tennis because they can hit the ball further? It's a stupid argument. Just because two things belong in the same broad category doesn't mean that you can meaningfully compare them. It is especially specious to bash Java for not being a functional language, because it doesn't try to do that. Java is heavily OO, not functional. So let's say that functional languages are 'better'. Let's just take that as a given. Why then would you single out Java and not mention any of the other languages that are also not functional? Why not bash Smalltalk, or Objective-C? To single out Java simply underscores the irrelevance of the comparison. Hence, rather than compare teams from two different sports, you should compare teams from the same sport. Likewise, if you want to make the claim that Common Lisp is the ultimate functional programming language, you should compare it to another functional programming language, not an OO language, or something like Prolog or COBOL.
- rluhar 15y agoI understand that Java is verbose and does not have the same "instant" feedback loop that a language with a fully supported REPL has. But I do not agree with the assertion that Lisp would be a good substitute for Java as the core instruction language in a University course. If people are having trouble getting their head around Java, I think they would struggle with Lisp. Java, in it's simplest form can be written in a very imperative manner. Most people think sequentially, and if you are getting started with programming, writing a simple little program in Java, IMO, is easier than something like Lisp. I am not saying Java is better, just that it has less cognitive overhead than Lisp. I studied both Java and Haskell at University and found it much easier to get going with Java than with Haskell (I hacked lots of QBasic - I am getting on a bit - when I was a kid). Actually, I think a language like Ruby or Python would be much better suited for an undergraduate / dual major than Lisp or Java!
- spacemanaki 15y agoThe authors of How to Design Programs use Lisp (well, Racket/Scheme) and they are some of the most careful and thoughtful CS educators, who are appear to be thinking deeply about CS pedagogy (at least, this is the impression I get from reading some of their papers and some of HtDP). So I wouldn't be so quick to write off Lisp as an intro language over Java. "I studied both Java and Haskell at University and found it much easier to get going with Java than with Haskell (I hacked lots of QBasic - I am getting on a bit - when I was a kid)." I think Java is arguably closer to Basic than it is to Haskell, so this isn't really a very fair or representative data point. (I don't claim that non-programming undergrads taking CS 101 would be more successful if started with Haskell instead of Java, although I believe that's not unheard of).
- rluhar 15y agoThanks for your comment. I will take a look at the book you recommend. To be honest, it has been a while since I was an undergraduate! On a related note - how easy is it to transition from having first learnt how to program in Lisp (or a functional language) to programming in Java or C++? I have seen lots of blog posts about doing it the other way around (Java to Lisp). I would imagine that also requires a cognitive leap ..
- freshhawk 15y agoWell if the author took the same care in determining that Lisp is better than Java that he did in "confirming the existence" of real life magical powers through Tai-Chi then why wouldn't I listen?
- rbanffy 15y ago"A year and a half ago, a dear friend of mine send me this link." pg's "Beating the Averages" is not known widely enough. We must promote it more. We owe it to our friends who toil under inhumane conditions and work with sadistic technologies. BTW, pg, I'm taking my "Hackers and Painters" to PyCon 2012. Will you have time to write a dedication? That is, if I get the book back from the colleague I lent it to. ;-)
- wcdolphin 15y agoIt is too bad your example does not really convey anything interesting about the differences between clisp and Java. The only thing I get from your essay is that Common Lisp has a REPL, which is sad because clisp is actually fun and interesting, and has a lot of VERY DIFFERENT things going for it. Size of source code has never been a measure of the power of the language.
- tsotha 15y agoI agree a "hello world" program is a good place to start learning but a terrible place to start comparing. To be fair, though, to really show the benefits of Lisp style programming you'd have to write something quite a bit longer. Long enough, in fact, you'd have trouble enticing people to read it.
- arturnt 15y agoThe first thing that anyone who doesn't know Java complains about is running a main method, which no one in the Java world does 99% of the time. This is probably the first thing you have to do in a Hello World Java tutorial, but has nothing to do with Java. There are some poor design choices in Java like no method overriding, mix of primitives and their boxed equivalents, lack of closures, or first class functions, confusing equals semantics, generics verbosity, etc. But main method is just moot. Also it has nothing to do with superiority of Lisp over Java. Lisp has a different philosophy it's a functional language, while languages like Java, C, Ruby, Python etc are all imperative (see http://en.wikipedia.org/wiki/Functional_programming#Comparison_to_imperative_programming http://en.wikipedia.org/wiki/Functional_programming#Comparis...). I think a better article would be about the virtues of each style and when to use which.
- nessus42 15y agoOne can program in Lisp in an imperative manner very easily and likewise one can program in Python in a functional manner very easily. The big difference between Lisp and Python (or Ruby) is not the functional nature of Lisp, but rather it's homoiconicity. Re Java, I write CLI programs in Java all the time. It's fine for that, other than the annoying 1 second startup time.