usable in any place a human can be used

Showing posts with label lisp. Show all posts
Showing posts with label lisp. Show all posts

20091023

treasure hunting

Working with programming languages is fun stuff. If you are a programmer then you probably only think about your language as much as you need to to get the job done. In fact you have to really, if you spent all day thinking about how the compiler is going to allocate this variable off the stack or this one off the heap or how its going to write out the virtual lookup tables, you could never get anything accomplished.

It's a shame though because our programming languages are some of the most interesting and complex software we interact with. If you are willing to look around you can find some real treasures out there, and even if you never code anything of importance in these new found treasures, the experience will pay dividends elsewhere.

I'd like to take you on a tour of the treasures I've found in my travels through the world we call programming, I'll split it into four easy to consume chunks.

The Past

The history of our field is short, still short enough that you can probably come to know most if not all of it. This is one of the interesting things about Computer Science, its a field that, in it's modern form, is about 60 years old. The amazing thing about all this is that there are some gems from the past, truly ground breaking work that we still use today.

  • Lisp
    As you may well be aware I've recently fallen in love with lisp, I'm starting to think about her all the time, and you can too. The amazing thing that, to this moment, knocks my socks off, is that Lisp was originally conceived in 1958 and has all kinds of concepts that you wouldn't expect from a language in it's 50s. Closures, homoiconic code, anonymous functions, object oriented programming, and a web framework. There is a lot more to this language, and it is definitely worth your time, go read up.
  • Smalltalk
    This one comes from the 1970's from the famous Xerox PARC. Smalltalk was way ahead of its time with a fully integrated development environment, a fully functional GUI, no files (this sounds bad at first, but its freeing not having to worry about where your source lives), everything is a file, and much more. Smalltalk's influence is far reaching even to this day, Objective-C borrows heavily from it, and the influential Gang of Four book offers source in C++ and Smalltalk.
  • C
    Hard to believe that this staple of computer programming was invented in 1972. Without C, Unix would not exist. C is still crazy fast, basically human readable assembly, and still widely used. The backbone and infrastructure of most of our technology exists because of C. Have a scripting language, need a way to shut people up who are saying it's too slow, allow them to call C modules, done. C is definitely worth knowing, you can access a giant pile of source code, and get as close to the machine as possible without busting out the x86 Assembly Guide.

The Present

  • Ruby
    This is the current hotness, although its hotness may be waning somewhat. Today ruby is the top language on github and there is a new interesting project written in ruby everyday. Ruby on Rails created the rockstar ruby programmer, and revolutionized data backed web development. Ruby is going to be around for a while, and because of REPL its easy to get started.
  • JVM Languages
    Java may be out, but the virtual maching that runs the language has never been more popular. Clojure (a JVM Lisp, which will probably get its own article soon) and Scala are up and coming. The ubiquity of the JVM means that you can run this code on almost any machine, and the languages are squeezing speed and performance out of the JVM that would have been unheard of a few years ago. These languages can also leverage the huge pile of Java Libraries out in the wild, so the first major hurdle to a new language (what can this thing actually do and are there any tools for it), is easily leapt.
  • DSLs
    Domain Specific Languages are starting to come into their own. Some of this popularity is owed to the rise of ruby which makes writing a new DSL somewhat trivial. Sass, Haml, and many others DSLs are beginning to find more and more adoption within their domain.

The Future

  • Functional Programming
    Erlang, Haskell, OCaml, etc. are beginning to see an upswing in interest. The rise of multi-processor cores and the inherent complexity of mutli-threaded programming in imperative programming makes these languages a tantalizing option. Erlang can support millions of threads with simple, easy to understand code. CouchDB will be the proving ground for Erlang's efficacy.
  • JavaScript
    As I wrote in the future: javascript
    When it get's down to it, JavaScript is a great language. It has a ton of exposure, and a huge amount of developer mindshare. JavaScript isn't going away anytime soon, and considering how hard it is to get browser vendor's to agree, isn't getting replaced anytime soon. JavaScript will become more and more prevalent both on the server and on the desktop. I welcome our new prototype based overlord, and so should you.
    So far nothing has changed.
  • Anything
    That is one of the most exciting things about this field, it could be anything. Before Ruby on Rails, the ruby language was a small odd scripting language that few outside of Japan had heard about. With the success of RoR ruby (which is an acceptable lisp) use has exploded and they have gained massive developer mindshare. Tomorrow a new technology could set the world ablaze, and the best part is that we have a chance to shape that future. This is an industry in which a man with a great idea can truly change the face of the development landscape.

These are just some of the treasures I have discovered by opening my eyes and looking around. There are plenty more gems that I have found that didn't make it into this post, but only because these one's were on the top of my brain. If you encounter a new language, take an hour or so to run through a tutorial, it could be worth it, it might not. You may find yourself falling in love, or maybe you missed a few episodes of the Simpsons. At the end of the day though, you will be glad that you took the time to learn something new, when you see glimmers of it in something old, and your knowledge of share-nothing concurrency saves the day on your next project.

This is a dynamic wonderful field, go play!

20091021

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)))
           ,@body)))))
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;
alert(dash-variable);

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.

20091014

falling in love

I'm home from work today, sick. Being sick is no fun, I think it is just a cold, hopefully back to work tomorrow. The only good thing about being sick is that it gives me time to spend with my new love. I fell in love yesterday. She is brilliant, straight forward, strong, and has sexy sexy curves. As I slept last night, my dreams were filled by her. I'm so taken by her beauty, her power, and again, the curves. By this point we should all know that I'm talking about the sweetest flower, lisp.

I have always intended to learn lisp better. It's one of those languages, where, if you are a language wonk like me, just seems to keep coming up. It's one of those beautiful, almost mythological pieces of technology that no one uses, but it just seems to come back up. I wrote yesterday in the future: javavscript that javascript is lisp dressed in C's clothing (and in actuality I stole that quote from Douglas Crockford). Lisp is one of those magical languages that was developed in 1956 and seems to have had within it every important language feature that we take for granted today. Just like with Xerox PARC seems to have, in 1975, created every single GUI feature that is now common place, lisp is that for programming languages.

A lot of people will say that lisp is dead, that it isn't worth learning, that no one uses it, and there is no money or projects in it. I won't try to dispute these statements, Peter Seibel does a better job than I can. What I want to argue is that lisp is worth learning, dead or alive.

So here it is, plain and simple

Lisp is the Latin of Programming

Learning Latin may not help you in your day to day conversation, but understanding declension, Latin grammar, and Latin vocabulary, can help you better understand your own language, or any language with roots in Latin. The same holds true for lisp, so many languages and language features have their roots in lisp. Macros, recursion, lambdas, the list goes on and on, learning the roots of these concepts in lisp, illuminates your understanding in other languages.

I have always wanted to learn lisp, but I could never find a source of learning that wasn't either obtusely academic, or painfully slow. I wanted a book that was written for programmers, I don't need you to explain the concept of a variable to me, I also don't want to have to write out a formal S-expression proof. I hold high hopes for Land of Lisp: Learn to Program in Lisp, One Game at a Time! but sadly it is not out yet. I came across a fantastic free book online called Practical Common Lisp and within an hour of reading through it have a fully functional CD database with a DSL that models SQL written completely in lisp, in just about 50 lines of code.

It is the Practical part of this book that is so great. You learn as you go, you build programs up that actually do things, and because of REPL you build incrementally, seeing your environment get more and more feature rich. I find myself unable to stop, for the first time in a while its a book that I treat like a video game, I just need to beat this next boss and then I can save and go eat dinner, ok maybe just one more level, whoa how did it get so late? It is a book that I lose myself in, fantastically well written, great examples, and a true feeling of discovery.

So pick up lisp, especially pick up Practical Common Lisp and give it a try. I know that I will be spending the rest of my day reading through it, and eating some chicken noodle soup.