Live data from Hacker News

Why I love Common Lisp and hate Java (2012)

kuomarc.wordpress.com

101–110 of 171 posts

Re: Why I love Common Lisp and hate Java (2012)

#101
post #59
post #20

Earlier quoted context omitted.

> In Java the top level only contains classes and interfaces. This design makes sense from conceptual purity, but Java is never a conceptually pure language. It distinguishes value types and object types, for instance. Not allowing free functions is really just a poor design choice. Worse, the proliferation of single-method interfaces (which are really just functions) and static methods (which are in most cases reall…

>Not allowing free functions is really just a poor design choice. I don't see why. The verbosity is pretty minimal and you enforce the availability of a privacy scope you wouldn't have had. ie private static methods and members that your public statics can use. Although, pure functions are nice if you can't trust the code you're calling won't surprise you.

I think this has to do with naming. Naming is generally hard, with free functions you must name the function, in Java you must also name the class.

If you could show some examples of single method interfaces whose naming makes sense, I'd be delighted!

Re: Why I love Common Lisp and hate Java (2012)

#102
post #4

Beside 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…

Implementing async/await. You can accomplish that entirely via macros in Common Lisp, whereas in Java you would need to do bytecode transformation via a javaagent (which, shockingly, I just discovered somebody has actually done: https://github.com/electronicarts/ea-async ). That being said, I write Java for a living, and I don't find it terribly verbose, outside of the lack of sum types, pattern matching, and typecla…

Isn't that really hard to implement correctly in Common Lisp? Your macro would need to perform a continuation-passing style transformation on arbitrary code that could involve jumps, error, etc.

Re: Why I love Common Lisp and hate Java (2012)

#103
post #87

I tried reading the Java Language Specification once, but it was such insane garbage I stopped and never give it another look.

I 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!

Wrong. Ruby has (one) ISO standard:

https://news.ycombinator.com/item?id=3868970 https://www.iso.org/standard/59579.html

Re: Why I love Common Lisp and hate Java (2012)

#104
post #86
post #7

It 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…

IMO, it’s a balance of entropy with maintainability. The amount of info I a line of java is likely lower than lisp, so the cognitive load is likely lower and the code reviews of diffs are spread out over more lines. Generally less value per line but more decomposed.

Having done both Java and Lisp for years (both professionally), I agree that in general Lisp requires more cognitive effort to read per line, but I disagree about the reason.

Cognitive load vs. verbosity can be visualized with something like Laffer curve - sure it's easier to read a couple lines of Lisp than one line of APL, but when you get into situations like one line of Lisp (or Python) gets expanded into 30 lines of Java, then the former is much easier. Terse languages make you pay cognitive cost for unpacking meaning, verbose languages make you pay for keeping track of what all these lines of code are doing. Ever had this situation when you read two pages of a book and realized you didn't really read anything, and have to re-read it (and 3 pages prior) to understand what's the point? That's Java in a nutshell, especially pre-1.8.

As for Lisp and cognitive load, the difficulty comes from a) dynamic typing, and b) macros. The former makes bad naming choices much more painful, as you can easily lose track of what's the code doing, and to what data. The latter are fine when written well, when written badly, your problem suddenly explodes in complexity as you have to peel off a layer of syntactic abstraction, and fix the underlying mechanism.

Re: Why I love Common Lisp and hate Java (2012)

#105

Earlier quoted context omitted.

You really should be using a logging framework instead though, if you're working on a large application.

Except you don't want to have your logger in all places: unit tests, early in startup lifecycle when guice or spring haven't wired everything up yet, etc. Printing to stdout is simple and ubiquitous.

> Except you don't want to have your logger in all places

Yes, I do.

Now, I may have to work with a language/ecosystem that makes that awkward, sure, but that's a problem, if an incredibly common one (Julia is one of the few languages that avoids it.)

Re: Why I love Common Lisp and hate Java (2012)

#106
post #7

It 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…

But “forcing learning early on” is exactly the problem. Approachable languages lead you up their learning curves in small, easy steps. The more knowledge you require newbies to swallow in one bite, the greater the number that will choke. (Not that anyone would call Lisp approachable either, of course.)

Agreed. When asked, I keep saying that Java is not the best "first language" to teach to a person, because it overwhelms people with concepts from the get-go.

A normal person who's sincerely trying to learn, when shown the Hello World will ask about everything - what is this "class" and why it's needed? What does "public", "static" and "void" mean, and why they're written. What "System.out" is? Not to mention, the package declaration at the top of the file.

All of those things have reasons for them, but when explaining this to a novice, you'll have to initially handwave most of those reasons away. That seems very uncalled for, especially when the basic abstraction you're trying to teach is that "computer executes simple instructions top to bottom, one at a time, and everything is built out of those simple instructions".

Re: Why I love Common Lisp and hate Java (2012)

#107
post #7

It 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…

I've made an attempt at a java scratchpad/REPL that guesses what imports you want. It allows just print by itself but Dump("Hello World!") is better in most cases as it handles collections well and outputs to tables/HTML as well as text.

Example: http://jpad.io/example/1y/test-different-output

Re: Why I love Common Lisp and hate Java (2012)

#108
post #65
post #49

Earlier quoted context omitted.

I 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.

You'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.

> 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.

I wonder if those are true reasons. I currently believe in the following set of reasons, in the order of importance: runaway feedback loop of popularity (popularity -> jobs -> popularity), JVM is cross-platform, low cognitive effort per line of code written.

Re: Why I love Common Lisp and hate Java (2012)

#109
post #44

Earlier quoted context omitted.

There 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-clo…

Lambdas 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…

> 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".

Re: Why I love Common Lisp and hate Java (2012)

#110

Earlier quoted context omitted.

Whats even better than print for debugging is using a debugger...

If I have easy access to a debugger. It’s extra work to hook things up to a debugger, and there are certain restrictions that may apply (attach too late if process launch is not under our control, program may behave differently, etc.). If I do have access to a debugger, often I will just do “printf debugging” there by setting a breakpoint and adding an action to “p someVariable; c”. Usually I treat my debugger a sort…

Exactly, and in the replies it is really obvious what the debate is really colored by.

In many cases there is no debugger available for someone's favorite platform. And so they "hate debugging". Go programmers, javascript people (where you can't do client->server debugging, but really, really have to), ...

How many Java programmers don't use debuggers ? How many C# developers ? Those languages have excellent debuggers. Python, C/C++, ... decent at best. Go/Javascript/... dismal debugging support.

Post reply on HN