usable in any place a human can be used


camels, underscores, and dashes

I've been learning lisp, oh it is good fun! Go now, stop reading this stupid blog, learn some lisp! Anyone still here, well let's talk about some stuff since you won't obey my commands... yet.

There are stupid things in life that don't seem important but somehow make a big difference. Really stupid things, things you can't image people would ever care about, like Indent style. Not a programmer, don't think it matters, don't think anyone would ever care? Get 10 programmers together, ask them what their favorite Indent style is and watch as the One True Brace Stylistas (the camp I fall into) and the Allmaniacs start screaming obscenities at each other and begin to fashion crude weaponry.

It seems like a small thing, but as programmers we spend a lot of time parsing text with our eyes and our brains. Reading source with a different Indent style can feel like walking with shoes on 3 sizes too big, sure you still know how to walk but it feels clumsy and unnatural.

Lisp can definitely feel like waking up groggy and putting on a pair of rollerblades instead of shoes. Its syntax can be confounding and lots of new comers really hate the parentheses.

(defmacro once-only ((&rest names) &body body)
  (let ((gensyms (loop for n in names collect (gensym))))
    `(let (,@(loop for g in gensyms collect `(,g (gensym))))
      `(let (,,@(loop for g in gensyms for n in names collect ``(,,g ,,n)))
        ,(let (,@(loop for n in names for g in gensyms collect `(,n ,g)))
Note there should not be any semicolons after the ampersands, syntax highlighter keeps putting them in there (if you know how to fix this please feel free to leave a comment)

Now this is a little unfair to lisp, if this is the first code example you've every seen don't be scared off, it uses lots of advanced concepts, and to be honest, I still don't fully grok the double-quoting and double-unquoting that is going on in this thing. The main thing to take away is look at all those parentheses, goodness me! Actually its not really that bad, SLIME does a great job of balancing them and they are semantic not just syntactic. Unlike other languages, in lisp parentheses are signal not noise.

One of the things I love about lisp and find myself wanting to do more and more in other programming languages is using the dash as a separator. The macro that is defined above is named "only-once" and I like that. Typing it is a breeze, there are no shifts to get capital letters or underscores. Depending on the language this would be written as OnlyOnce, onlyOnce, only_once, but lisp lets you type only-once, and although it seems small, I definitely like it more than any other convention.

I'm a web programmer for my 9-5 actually get a paycheck for programming programming, and there are many things that you can name with dashes. Web pages (my-sweet-webpage.html), image resources (guy-dancing-with-cat.jpg), css class (div.super-awesome), html entity id's (my-super-awesome-div) are all legal. I want to be able to use the same convention in JavaScript or C# or PHP or [insert language here] but I can't.

There is good reason why I can't, it would be impossible to program a parser, don't believe me, parse this JavaScript pretending that you can use dashes in names.

var dash-variable = 10
var dash = 8;
var variable = 4;

What would the output be, 10 because it looked up "dash-variable" or 4 because it looked up "dash"-"variable" = 8 - 4 = 4. The way lisp gets around this is that there are no infix operators. The same code in lisp would look like this.

(defvar dash-variable 10)
(defvar dash 8)
(defvar variable 4)
(format t dash-variable)
; or
(format t (- dash variable))

Slowly but surely though I'm getting used to gliding around on my lisp rollerblades, and when I have to put on my C# shoes or my PHP shoes they just don't feel right anymore. There is nothing I can about this except be aware, and for the love of the flying spaghetti monster FOLLOW THE LANGUAGE'S NAMING CONVENTION.

Because if I come across some of your .Net code and it looks like Java, or you want to write your JavaScript like its a .Net class, you will incur my unending wrath. I might think that capitalizing the first letter of function names is wrong (I'm looking at you .Net, first letter capitalization is for classes) but consistency of source code is much more important than my petty preference. Lunch is over now, back to writing Allman braced CapWords C# code, because at the end of the day, someone pays me to walk around in these crocs, no matter how ugly I think they are.

No comments:

Post a Comment