Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

'defn' is hardly old-school; Python uses 'def' to define functions. Now 'car' and 'cdr' on the other hand...

This is far preferable to typing e.g. "public static void ..." all the time



defn harkens back to an era when using a computer meant using a teletype, putting an extreme premium on terseness in naming. And it's just an example, car, cdr, cons, etc. are just as bad. It's easy to memorize these but that doesn't mean they are the best choices for readability, writability, etc.

I have a hard time believing that the best choice of name for all of these operators just so happens to always be some 3 or 4 character string that's almost but not quite a word and seems to have dropped some vowels.

As for "public static void ...", that's a disease of another sort, equally as bad.


I disagree. If car and cdr and cons are bad, it's because they don't look or sound like what they do, and they have good replacements, like first and rest. defn is a macro that makes it simpler to def, which sounds and looks like "define", a binding to a fn, which sounds and looks like "function". I don't think you get any clearer than that without writing "define-function" everywhere. And I don't want to write "define-function" everywhere.

Do you think that every index variable in a loop should be called "index"?


`defn' is a mnemonic for "define function". `cons' is a mnemonic for "construct".

`car', and `cdr' and replaced in clojure with `first' and `rest'.

Once you've spent ten minutes with the language, these names aren't going to trip you up.


People want to learn "new languages" without having to learn anything new.


Well put. There's also a tradeoff between learning-curve and proficiency in language design: many features that aid the one detract from the other. I think this causes much of the noise in programming language discussions, especially with Lisp.


I think using defn as an example here is a poor choice for this argument. defn is not an abbreviation of `define` or 'defun', instead it is a fusion of `def` and `fn`. fn is clojure's anonymous function form and def binds a var to a value. You can see this via macroexpand:

   user=> (macroexpand '(defn f [x] x))
   (def f (.withMeta (clojure.core/fn f ([x] x)) (.meta (var f))))
[edit: clarified an ambiguous initial statement]




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: