Live data from Hacker News

Why I love Common Lisp and hate Java (2012)

kuomarc.wordpress.com

131–140 of 171 posts

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

#131

Earlier quoted context omitted.

Most Haskellers write out the types even though they can be inferred. In a pure language, signatures are extremely close to documentation (you know exactly what a function will do by its signature). Java requires more code than Python or Haskell because it's extremely imperative and statement based. Python on the other hand includes a lot of functional, more expressive idioms like concise list comprehensions.

Types aren’t documentation, no matter how many Haskell users delude themselves thinking it is. Documentation is more than a function definition. Types don’t explain rationales and how to use functions and programs. Types don’t give proper examples.

Types are documentation. Documentation isn't types.

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

#132
post #48

Earlier quoted context omitted.

I would say that Java has ~50% more code than Python due to types and braces. But I agree with you that it's worth it, because the compiler can check that a programmer satisfied a constraint, instead of relying on informal conventions or comments. You can have a statically typed language without verbosity, via type inference (Haskell, newer Java, etc.). I wouldn't say I enjoy Java's verbosity, but I would take this o…

Most Haskellers write out the types even though they can be inferred. In a pure language, signatures are extremely close to documentation (you know exactly what a function will do by its signature). Java requires more code than Python or Haskell because it's extremely imperative and statement based. Python on the other hand includes a lot of functional, more expressive idioms like concise list comprehensions.

> Most Haskellers write out the types

Maybe that's partly because Haskell can easily become a bit too elegant. Between all the currying and combinators, the type helps to understand code "top down", i.e. when you don't have studied and memorized all "bottom up" component parts.

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

#133

Earlier quoted context omitted.

Most Haskellers write out the types even though they can be inferred. In a pure language, signatures are extremely close to documentation (you know exactly what a function will do by its signature). Java requires more code than Python or Haskell because it's extremely imperative and statement based. Python on the other hand includes a lot of functional, more expressive idioms like concise list comprehensions.

>In a pure language, signatures are extremely close to documentation (you know exactly what a function will do by its signature). The same can be true of tests. I've started generating API documentation from mine: e.g. https://hitchdev.com/strictyaml/using/alpha/scalar/email-and... I tend to think of types and tests as attacking the same problem from opposite directions.

> StrictYAML can validate emails (using a simplified regex)

Public Service Announcement: don't validate emails with regex. Every time you do, god kills a kitten.

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

#134

Earlier quoted context omitted.

>In a pure language, signatures are extremely close to documentation (you know exactly what a function will do by its signature). The same can be true of tests. I've started generating API documentation from mine: e.g. https://hitchdev.com/strictyaml/using/alpha/scalar/email-and... I tend to think of types and tests as attacking the same problem from opposite directions.

> StrictYAML can validate emails (using a simplified regex) Public Service Announcement: don't validate emails with regex. Every time you do, god kills a kitten.

Just checking for the @ symbol is fair game. Anything beyond that is a bad idea.

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

#135
post #77
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…

Here is something from Clojure that stuck with me as particularly elegant: The -> macro. (-> {} (add-person 'servbot) add-age add-info add-to-db notify-status-by-email log-user-addition ) So the threading operator is exactly what you ask. It inserts the results of the previous expression as the first argument as the first argument as the next expression. Note this still supports situations where an expression can tak…

The Clojure standard library has had the the 'as->' macro for a while which serves the same purpose as the "magic wand". It doesn't need to use '' as the identifier, but I usually choose to do so because I learned about the magic wand library before I learned about the 'as->' macro.

  (as-> {}  
      ...
      (add-age 21 )
      ...)

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

#136

Earlier quoted context omitted.

Types aren’t documentation, no matter how many Haskell users delude themselves thinking it is. Documentation is more than a function definition. Types don’t explain rationales and how to use functions and programs. Types don’t give proper examples.

Types are really good documentation. I can tell I'm not deluded by thinking so because I can sit down with a Haskell library containing zero examples and write code that uses it . If your assertion was correct, that would be impossible. But it's not only possible, it's easy. Perhaps there is more to types than you realize.

Alice: Hey Bob, want to try my nifty new function?

Bob: Sure, Alice, what does it do?

Alice: It takes an object and it returns an object.

Bob: But what does it actually do?

Alice: I told you. It takes an object and it returns an object.

Bob: But what does it do with the object? What's it for? Why should I use it?

Alice: Hey, I just gave you the full documentation for my function. You have everything you need. Now go use it.

Bob: Um, no thanks. I like to know more about what I'm getting myself in to.

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

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

From the perspective of a python programmer, I must say this is an interesting list. I'm rather convinced by your points on print and public. On the other hand, "__name__ == __main__" is just a convenience for debugging and small scripts. I wouldn't use it in real programs. I dont use @staticmethod, or find it useful. If I want a function, I use a function.

> I dont use @staticmethod, or find it useful. If I want a function, I use a function.

In principle, it makes sense to "bundle" functions that are strictly related to a class within the class itself (i.e. as static methods). Of course, the benefits viz. top-level functions are only noticeable if your codebase is big enough.

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

#139
post #78

Earlier quoted context omitted.

Again, attaching a debugger is occasionally not helpful–for example, if you're trying to figure out why your program isn't loading certain plugins at launch, you trying to attach the debugger may happen after this step occurs. So you don't get to debug this process.

Or if an issue happens in your staging environment but not locally. That happened to me just yesterday, and a simple print statement gave me the information I needed to resolve the issue. I probably could have attached a remote debugger, and executed the relevant function a few times until my request got routed to the right process in the cluster, but that honestly would have taken me more time than just committing t…

That seems like a good thing to use logging for, instead of a print statement.

But you're right, figuring out a dev / prod discrepancy in already-running code is a case where a debugger is not as useful.

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

#140

Earlier quoted context omitted.

Types are really good documentation. I can tell I'm not deluded by thinking so because I can sit down with a Haskell library containing zero examples and write code that uses it . If your assertion was correct, that would be impossible. But it's not only possible, it's easy. Perhaps there is more to types than you realize.

Alice: Hey Bob, want to try my nifty new function? Bob: Sure, Alice, what does it do? Alice: It takes an object and it returns an object. Bob: But what does it actually do? Alice: I told you. It takes an object and it returns an object. Bob: But what does it do with the object? What's it for? Why should I use it? Alice: Hey, I just gave you the full documentation for my function. You have everything you need. Now go…

Thankfully, Haskell supports much nicer types than only `Object`
Post reply on HN