Live data from Hacker News

Why I love Common Lisp and hate Java (2012)

kuomarc.wordpress.com

1–10 of 171 posts

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

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

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.

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

#5
post #2

If you are running JDK 9 or later, you can use jshell: jshell> "Hello World!" $1 ==> "Hello World!" https://openjdk.java.net/jeps/222

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

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

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

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

#8
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…

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

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

#9
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.)

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

#10
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…

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

Whats even better than print for debugging is using a debugger...
Post reply on HN