23 ms·
Why I love Common Lisp and hate Java (2012)
- haglin 8y agoIf you are running JDK 9 or later, you can use jshell: jshell> "Hello World!" $1 ==> "Hello World!" https://openjdk.java.net/jeps/222 https://openjdk.java.net/jeps/222
- jernfrost 8y agoJava is not really designed for a REPL though. I've used REPL like environments in Swift long before, this and it simply never feels right IMHO compared to a real dynamic language. And Swift is a much better designed language for this than Java.
- dan-robertson 8y agoThank goodness for jshell. The only thing holding Java back was its lack of a repl and now it has one, we can embrace Java as the useful concise dynamic succinct language it really is. I don’t think the argument in the linked article is very good but this apology is worse. It doesn’t really show any merit of Java (more that the repl in Java is much less powerful than in eg CL) or argue against the spirit of the article.
- chvid 8y agoAnd lambdas were introduced in 8 making nearly all of the author’s issues mute.
- ggambetta 8y ago*moot You're right, but to be fair the article is almost 7 years old, and Java has evolved a lot.
- sifoobar 8y agoI'm curious, how much Common Lisp have you written yourself. Because what I'm reading between the lines is that you consider modern Java to be pretty much equal to Common Lisp in power, and that doesn't make much sense from here. Take lambdas for example, the amount of arbitrary exceptions you have to keep in mind while using them makes it almost not worth the effort. It's still the same old crappy Java; only with shiny, barely working marketing gimmicks duct taped to the side.
- hajile 8y agoWhat about closures? Also, those lambdas are actually classes that try very hard to look like lambdas, but aren't actually.
- akvadrako 8y agoWhat do you mean "aren't actually" ? Anything that behaves according to the rules of a lambda is one — they can certainly be implemented with classes.
- hajile 8y agoThere are quite a few complications of Java lambdas and their abstraction bleeds out in several edge cases. This is a result of their class implementation and would not exist if functions had first class support in the language and barcode bytecode (there are complications there too because they didn't want to change anything at the bytecode level for lambdas). https://dzone.com/articles/java-8-lambas-limitations-closures https://dzone.com/articles/java-8-lambas-limitations-closure...
- colin_mccabe 8y agoLambdas in Java aren't really that complicated. If you understand anonymous classes, you understand lambdas. That article just compares Java's closures with Javascript's closures. The "limitation" is that Java's closures can only access the final variables of the enclosing scope. But the article agrees that this limitation "can be considered negligible" (seriously, read it-- that's the conclusion.) Also, starting in Java 8, you don't have to explicitly declare things "final" to use them in anonymous classes or lambdas. They just have to be effectively final, meaning they are not mutated.
- TeMPOraL 8y ago> But the article agrees that this limitation "can be considered negligible" (seriously, read it-- that's the conclusion.) Working both in Java and Lisp professionally, it sure as hell isn't negligible. It changes the way you write code. Lambdas in Java are 80% solution. Java 8 really did make this language finally bearable, sometimes pleasant to work with. 80% solutions are good, but the remaining 20% is not "negligible".
- ilovecaching 8y agoThat's the thing though... they aren't real lambdas. They're just syntactic sugar for an interface. If you watch the talk by the head of Java right now at the Clojure conference, he talks about how they're essentially trying to tack on low hanging fruit in hacky ways to keep the language up to date. But secretly it's a mess.
- DenisM 8y agoTurns out C# also has a REPL now, it's called "C# interactive". I've found out just now, spurred to look for it by your post.
- 3rdAccount 8y agoUmmmm yes & no. It has a REPL, but it sure isn't easy to use and very few C# coders actually use it. Contrast that with a dynamic language like Python where people basically live in the REPL. Common Lisp takes this to a whole new level. You really can't equate C#'s REPL to Common Lisp's. This is one of those things where the sum of the thing is greater than its parts. Note that I'm not saying C# isn't a decent language, just very very different than what you get with languages like Smalltalk & Lisp.
- itronitron 8y agofor those running JDK 8 or earlier, you can also script Java through Rhino >> https://developer.mozilla.org/en-US/docs/Mozilla/Projects/Rhino/Scripting_Java https://developer.mozilla.org/en-US/docs/Mozilla/Projects/Rh...
- dang 8y agoDiscussed at the time: https://news.ycombinator.com/item?id=3525927 https://news.ycombinator.com/item?id=3525927
- shawn 8y agoYou've passed 50k karma! Congratulations!
- apo 8y agoBeside the REPL, another impressive feat of Common Lisp is meta-programming. You can write software to write software. Say what? Yeah, that was my initial reaction too, but Common Lisp’s macro system allows you to write functions that return code snippets. It completely redefines the word. Or more accurately, re-redefines, since Lisp is much older than MS Office, which is what most people associate macros with, sadly. The article could be improved by including an example. Pick one in which Java makes the problem to be solved tedious, verbose, repetitive, or error-prone and where Lisp macros do not. Bias the example as much as possible to a problem where Lisp can shine. It should, however, be a real problem most programmers are likely to face in some form. Then present the source for both solutions. This approach would even help those who don't use Java regularly because they could try to implement the same functionality in their language of choice and compare it the the Lisp implementation.
- taeric 8y agoInline some data structure. Json, interestingly, embeds trivially in lisp. Not so much in Java. Especially once you learn the quasi quote.
- deleted 8y ago[deleted]
- yen223 8y agoI would love to see the reverse. Ive never seen a Java codebase that I thought was pleasant to work with, but maybe I'm just not looking hard enough.
- jayd16 8y agoYou're really underestimating the power of Java's boring workhorse methodology. If you're looking for love there's a lot of other languages that are more pure and more beautiful for certain use cases. However, there's a reason Java is in the top 3 most popular languages. Its pragmatic, it scales, it plays nice with tooling and the language itself is pretty passable.
- nayuki 8y agoIt is a recurring theme for people to point out how verbose a hello world program is in Java: class HelloWorldApp { public static void main(String[] args) { System.out.println("Hello World!"); } } For argument sake, let's compare it not to Lisp but to Python instead: print("Hello World!") Once you get proficient in a language and start writing larger programs, your perspective can change entirely. What appears to be verbose in the Java version starts to make sense. For example: * In Java the top level only contains classes and interfaces. All functions must be put inside a class, and I believe this design simplifies conceptual understanding. Whereas in Python, you have a distinction between top-level variables and functions versus fields and methods bound in classes. * Python always executes the top level, so you end up with awkward idioms like: if __name__ == "__main__": main(sys.argv) * Static typing versus dynamic typing. We all know this debate, so I won't repeat it. (This is regarding void and String[].) * The "public" keyword might seem like noise, but in Python you denote private by prefixing the name with one or two underscores. * Do you really want print() to be so easily accessible in the top-level namespace? It seems to me that the bigger an application gets, the worse it is to easily litter the codebase with print statements. * You still eventually need to learn what "@staticmethod" means in Python. Java just forces this learning early on.
- saagarjha 8y ago> Do you really want print() to be so easily accessible in the top-level namespace? It seems to me that the bigger an application gets, the worse it is to easily litter the codebase with print statements. Yes? It's great for debugging, which is generally what you'd use a print for anyways in a large application.
- judgardner 8y agoWhats even better than print for debugging is using a debugger...
- ggambetta 8y agoDoesn't quite work when debugging a distributed system, though. You end up adding a lot of "distributed print", AKA logging.
- ilovecaching 8y agoThe languages that tend to become popular are simply languages that appeal to the lowest common denominator. Java was the language invented for the "common programmer", and people find that comforting. Now it's Go; as Rob Pike once said of it, "They’re not capable of understanding a brilliant language but we want to use them to build good software. So, the language that we give them has to be easy for them to understand and easy to adopt." That's why it's always a battle to push languages like Lisp, that offer mathematical elegance over languages that are a soup of half baked idea that veer programmers away from ideas that take more than a few days to master. For those of us who aspire to do better, we should continue to try to bring the from first principles approach of functional programming to the mainstream.
- ausbah 8y agoNot gonna lie, to me that’s a lot of words to just say “people who use popular languages are beneath me because they simply can’t understand the ‘beauty’ that mathematical-esque and functional functional languages offer”.
- commandlinefan 8y agoOne big thing I notice about Java (and it’s ancestor, C) is that it’s designed to make it easy to pinpoint exactly what went wrong, when something goes wrong. Lisp, on the other hand, is designed so that you can get it right the first time.
- thosakwe 8y agoNit-picking a specific claim made in the article, but I honestly don't believe Lisp would be any less confusing to new programmers than Java. In fact, I think it would probably just confuse them more.
- d_burfoot 8y agoIt's ironic that the author claims that Common Lisp is easier to learn than Java. One of the most common pro-Lisp, anti-Java arguments I hear is that Java is too easy to learn, so that a lot of people who aren't actually very good at programming can get Java jobs. This means that the Java world is populated with not-so-bright people, while the rarefied Lisp world is full of elite wizards.
- ilovecaching 8y agoJava doesn't contain conceptually difficult features. In Rust you have to learn lifetimes and borrow checking, in Haskell Monads... Java just has a huge amount of relatively simple features. Lisp is middle of the road conceptually, but is a small language. So in that sense I agree with you. Java is favored by people who struggle to learn harder concepts. That's why it's the usual target of the lowest common denominator programmer and loved by large enterprises that can churn Java programmers like mackerel.
- kazinator 8y agoI tried reading the Java Language Specification once, but it was such insane garbage I stopped and never give it another look.
- nayuki 8y agoI read parts of the JLS and I found the text quite down to earth compared to the respective specifications of C, C++, and ECMAScript (JavaScript). Oh and as for scripting languages like PHP, Python, and Ruby? They don't have a standard because the implementation is the spec!
- strzibny 8y agoWrong. Ruby has (one) ISO standard: https://news.ycombinator.com/item?id=3868970 https://news.ycombinator.com/item?id=3868970 https://www.iso.org/standard/59579.html https://www.iso.org/standard/59579.html
- pulse7 8y agoI had diametrically opposite experience: I read Java Language Specification and Java Virtual Machine Specification back in 1996 - after many years of programming in (pure object-oriented, dynamically typed, invented by Alan Kay) Smalltalk. These two specs changed my course in IT forever... After more than 22 years later I have no regret reading it...
- RangerScience 8y agoI've recently come around on Java (although I'll still rarely choose it), mostly due to the idea that "all things get complicated, so what matters is how you manage that complexity". Java started to "click" when I realized how much you build objects out of other objects like layers of an onion, just adding a bit at each step, and it clicked a bunch more as I understood Spring's bean system, which itself clicked more when I began to understand that the object-based dependency graph is basically the equivalent of the top-level Ruby script. All the code describes how X and Y relate to eachother, and then you go to the bean definitions to find out what X and Y are. That's actually pretty neat. I still prefer the "simple script" approach you can do in Ruby; and I'm loving the way Scala is kind of Ruby, but in Java, and so (and to relate to the actual content) inherits a lot more from Lisp. So, PS, author, if you're reading this, seriously give Scala a try. It's been pretty fantastic so far for me!
- reality_czech 8y agoJava has been gradually eating all the good parts of Scala. So far, it's eaten lambdas, map / reduce / fold functions, option types, raw string literals, the concept of a built-in REPL, type inference for local variables, and default methods in interfaces (which is kind of like mixins). Pattern matching and type classes are on the menu, but not yet formally merged into Java. So what does Scala have left? Operator overloading, which tends to lead to unclear code. "Implicit," which should give any former C++ programmer PTSD flashbacks. A compiler which is pretty slow. The ability to embed XML into code (why?). A collections library which is nightmarishly complex. (See https://yz.mit.edu/wp/true-scala-complexity/ https://yz.mit.edu/wp/true-scala-complexity/ )
- zmmmmm 8y ago> So what does Scala have left? This is why I think long term Groovy is better positioned than Scala, even if short term Scala has more of the mindshare. Groovy actually offers something fundamentally different, while Scala is perpetually trying to compete on Java's home turf. If people really want a pure, statically typed language Kotlin is pretty good and has less impedance mismatch with Java.
- shion 8y agoLisp is the best language in the world. ^^
- cutler 8y agoMy biggest gripe with Java is it's insane backslash-enhanced regular expressions. No other language seems to require this ridiculous butchering of what brought me into programming.
- colin_mccabe 8y agoJava 12 is going to add raw string literals which will fix this problem. https://openjdk.java.net/jeps/326 https://openjdk.java.net/jeps/326
- RandyRanderson 8y agoThe issues mentioned are largely addressed by jshell and lambdas. Regardless, his issues mostly boil down to "Java is not a REPL-first and Lambda-first language". This is like me "hating" my cat because it's not a dog. I find many beginner programmers like REPL langs. When I talk to them, though, it becomes apparent that they've never worked on a code base with 100k+ lines with tens of colleagues. One guy actually suggested that systems should never be that big! What do you say to that? I just smiled.
- s4vi0r 8y agoI think many Haskell, OCaml and Scala programmers would disagree heavily with you. Repl driven development works very well with pure functional code and at no point did I feel an increase in loc begin to make it tedious or whatever. The repl approach perhaps doesn't work as well in Java because Java and its ecosystem encourage writing messy jumbled code built upon unsafe abstractions.
- vbsteven 8y agoA turing complete macro system is seen as a positive thing but if someone dares to mention Java’s annotation based code generation and DI everyone is complaining about “too much magic”
- john_minsk 8y agoWhy are we still discussing it? JAVA is used in most companies in the world. Lisp on the other hand - is not advised to be used in production. To me it looks like long lost battle
- wiz21c 8y agoFTA : >>> But for a skeptic like myself — who spent 4 months intensively practicing Tai-Chi in Beijing, just to confirm the existence of “qi” Has anybody here experienced this chi thing. My tai chi teacher can surely demonstrate it but I have hard times understanding with my occidental way of looking at physics... My understanding it's more a state of mind that allows the body to move in a very specific way.
- rurban 8y agoAn old lisper would have used '(Hello World) over "Hello World". We are dealing with symbols mostly, not strings.