Startup School
I attended startup school on Saturday. It was a great experience and a rare opportunity to hear to a such impressive speakers share their wisdom about technology and entrepreneurship. Some of my favorite talks were by David Heinemeier Hansson, Greg McAdoo, Marc Andreesen, Paul Buchheit and Michael Arrington. I met a bunch of programmers and entrepreneurs and I also chatted briefly with DHH about 37signals and Peter Norvig about new search startups and their chances of competing with Google. Many thanks to YCombinator for organizing such a great event!
If you haven’t attended, you can see all the videos here. Highly recommended.
Concurrency and expressiveness
Damien Katz’s article Lisp as Blub has sparked a lively debate on Hacker News on the relative merits of Erlang and other languages for building robust applications. Good points were made on all sides (except for the tired complaints about Erlang syntax — I have a suspicion that most people who complain about it haven’t done much coding in Erlang). Unfortunately, I think that a key point was lost in all the noise: all else being equal, a language with great support for concurrency and fault tolerance has a higher expressive power than a language that doesn’t. It just lets you build concurrent applications much more easily (less code, fewer bugs, better scalability, yadda yadda).
EC2 gets persistent block level storage
I just caught Amazon’s announcement of the new persistent storage engine for EC2. This is great stuff. It lets you create persistent block level storage devices ranging from 1GB to 1TB in size and attach them to EC2 instances in predetermined availability zones. This service complements Amazon’s other storage services — EC2 and SimpleDB — in providing raw block-level storage devices that are persistent, fast and local (so you don’t have to worry about SimpleDB’s eventual consistency issues). You can use these volumes for anything — running a traditional DBMS (MySQL, Postgres) is the first thing that comes to mind.
This announcement is a departure from Amazon’s tradition of announcing services only once they become available. It looks like Amazon is feeling the heat of competition from Google App Engine and is becoming more open to win over the hearts and minds of developers who are drawn to GAE for its auto-magical scalability. The ability to attach multiple terabyte-sized volumes on demand alleviates some of those concerns when deploying on Amazon’s infrastructure. I’m sure it won’t be long before someone creates an open source BigTable-like solution for applications that need massive scalability and redundancy on top of multiple persistent storage volumes (I think this would be a great application to write in Erlang, but I don’t know how well Erlang performs in applications that require heavy disc IO).
I like what Amazon is doing. By providing the basic building blocks for scalable applications, its enables startups to create their own GAE competitors (Heroku is the first one that comes to mind) on top of Amazon’s infrastructure. Smart move.
Google has the advantage of being able to provide APIs for tight integration with other Google services such as authentication and search (the latter is hypothetical as of now). We’ll see how strongly this plays in Google’s favor in the coming months.
Of course, price is still a question mark. Neither Amazon’s persistent storage service nor GAE have had their prices announced.
Another missing detail is the Amazon store service’s reliability. If a disc fails, do you lose your data? What’s the failure probability? Etc.
All this is great for developers. Competition between Amazon and Google means developers will enjoy more services and for lower prices in the coming years.
Tag cloud in ErlyWeb howto
Nick Gerakines wrote a good tutorial on how to make tag clouds in ErlyWeb. Check it out at http://blog.socklabs.com/2008/04/tag_clouds_in_erlang_with_erly/.
ErlyWeb renamed “Erlang on Rails”
Erlang is *almost* a tipping point. Thanks to reddit, many people are interested in it. However, it’s not there yet. Despite being the only language that got concurrency right, and all its other standout features, many developers still use other languages. The only explanation I can think of is that Erlang hasn’t had much PR over the years (the Erlang movie nonwithstanding). I’m confident that a good PR boost will help push Erlang over the hill. Unfortunately, Ericsson doesn’t seem interested in heavily promoting Erlang the way Microsoft promotes .NET and Sun promotes Java (this may be because many Ericsson employees have never heard of Erlang). So, I decided to take things into my own hands. I don’t have a budget, so I need to get creative. The best way to succeed if you’re small is to ride a big wave — and what’s a better wave to ride than Ruby on Rails?
Ruby on Rails is very popular — much more than ErlyWeb. I believe this popularity is due to the “on Rails” meme, which is just bursting with positive connotations. It sounds young, fresh, happy. It’s the anti-enterprisy software. It emancipates you from burdensome type systems, explicit getters and setters, and (ugh) XML. Its metaprogramming wizardry is made of bliss. Its evokes images of riding in environmentally-friendly transportation looking out the window at grassy meadows, rolling hills and sunny skies.
I think that renaming ErlyWeb to “Erlang on Rails” will help win over the hearts and minds of many programmers who are currently on the fence. They may be curious about Erlang but are turned off by its telcom image. “Erlang on Rails” conveys a more balanced feeling of industrial strength applications from the telcom world mixed with the social Web 2.0 era of interconnectedness that celebrates the rise of individualism over grey corporate culture.
2008 will be the year of Erlang on Rails. I know it.
Update: This was an April Fool’s joke, in case it’s not obvious anymore :)
Announcing the Erlang FriendFeed API
I just hacked together an (alpha) implementation of the FriendFeed API for Erlang. You can get the code at http://code.google.com/p/erlang-friendfeed/. Enjoy!
By the way, my shiny new FriendFeed is at http://friendfeed.com/yariv.
I Play WoW: A Cool Facebook App Built With ErlyWeb
Nick Gerakines, the Author of Facebook Application Development, created with ErlyWeb the very cool Facebook app I Play WoW. I Play WoW bridges between real people and the characters they play on World of Warcraft. Nick told me he got a lot of feedback such as “Wow! I didn’t know my brother-in-law is in my guild!” and “Its been 5 years since I talked to some of them, but a bunch of my friends from school play on these realms and I didn’t even know they played”.
Some facts:
- 53.5k installs
- 2.9k daily active users
- 1.3k application fans
- 200+ new users a day on average
- In the past 30 days its gotten over 2 million page views where users spend more than 5 minutes on average on the application
- Erlang application layout:
* Charstore w/ Mnesia: Acts as the raw character store and cache for interactions between wowarmory.com
* I Play WoW w/ ErlyWeb + Mnesia: The front-end and ui for the application. The majority of the FB API calls are made here or are spawned from here.
* There is still one component in perl that is yet to be ported over, mainly due to not having enough time. Its on the list of things to do.
(My note: it sounds like Nick is also using spawned processes to make FB API calls asynchronously. It’s a great technique for reducing page load time and avoiding the annoying timeouts Facebook imposes on page renderings.)
If you play World of Warcraft (an addiction I’ve luckily been able to avoid this far :) ) and you are on Facebook, give I Play WoW a try. You may discover that your boss is a level 10 ogre or something :)
Congrats, Nick, for creating such a successful app with ErlyWeb!
SnapTalent Ads
You may have noticed I put SnapTalent (http://snaptalent) ads on my blog. This is the first time I have put ads on my blog. I’ve avoided them because ads from most ad networks are usually irritating/ugly, but the SnapTalent ones are nice looking, unobtrusive and are relevant to my blog’s readers because they advertise hacker jobs at startups. I can’t say those ads have generated substantial revenue for me thus far but at least I’ve made enough money to buy the SnapTalent guys a round of beers :)
In Response to “What Sucks About Erlang”
Damien Katz’s latest blog post lists some ways in which Damien Katz thinks Erlang sucks. I agree with some of these points but not with all of them. Below are my responses to some of his complaints:
1. Basic Syntax
I’ve heard many people express their dislike for the Erlang syntax. I found the syntax a bit weird when I started using it, but once I got used to it it hasn’t bothered me much. Sometimes I mess up and use the wrong expression terminator, and sometimes things break when I cut and paste code between function clauses, but it hasn’t been real pain point for me. I understand where the complaints are coming from, but IMHO it’s a minor issue.
Since the release of LFE last week, if you don’t like the Erlang syntax, you can write Erlang code using Lisp Syntax, with full support for Lisp macros. If you prefer Lisp syntax to Erlang syntax, you have a choice.
2. ‘if’ expressions
The first issue is that in an ‘if’ expression, the condition has to match one of the clauses, or an exception is thrown. This means you can’t write simple code like
if Logging -> log("something") end
and instead you have to write
if Logging -> log("something"); true -> ok end
This requirement may seem annoying, but it is there for a good reason. In Erlang, all expressions (except for ‘exit()’) must return a value. You should always be able to write
A = foo();
and expect A to be bound to a value. There is no “null” value in Erlang (the ‘undefined’ atom usually takes its place).
Fortunately, Erlang lets you get around this issue with a one-line macro:
-define(my_if(Predicate, Expression), if Predicate -> Expression; true -> undefined end).
Then you can use it as follows:
?my_if(Logging, log("something"))
It’s not that bad, is it?
This solution does have a shortcoming, though, which is that it only works for a single-clause ‘if’ expression. If it has multiple clauses, you’re back where you started. That’s where you should take a second look at LFE :)
The second issue about ‘if’ expressions is that you can’t call any user- defined function in the conditional, just a subset of the Erlang BIFs. You can get around this limitation by using ‘case’, but again you have to provide a ‘catch all’ clause. For a single clause, you can simply change the macro I created to use a case statement.
-define(case(Predicate, Expression), case Predicate -> Expression; _ -> undefined end).
For an arbitrary number of clauses, a macro won’t help, and this is something you’ll just have to live with. If it really bothers you, use LFE.
3. Strings
The perennial complaint against Erlang is that it “sucks” for strings. Erlang represents strings as lists of integers, and for some reason many people are convinced that this is tantamount to suckage.
…you can’t distinguish easily at runtime between a string and a list, and especially between a string and a list of integers.
A string *is* a list of integers — why should we not represent it as such? If you care about the type of list you’re dealing with, you should embed it in a tuple with a type description, e.g.
{string, "dog"},
{instruments, [guitar, bass, drums]}
But if you don’t care what the type is, representing a string as a list makes a lot of sense because it lets you leverage all the tools Erlang has for working with lists.
A real issue with using lists is that it’s a memory-hungry data structure, especially on 64 bit machines, where you need 128 bits = 16 bytes to store each character. If your application processes such massive amounts of string data that this becomes a bottleneck, you can always use binaries. In fact, you should always use binaries for “static” strings on which you don’t need to do character-level manipulation in code. ErlTL, for example, compiles all static template data as binaries to save memory.
Erlang string operations are just not as simple or easy as most languages with integrated string types. I personally wouldn’t pick Erlang for most front-end web application work. I’d probably choose PHP or Python, or some other scripting language with integrated string handling.
I disagree with this statement, but instead of rebutting it directly, I’ll suggest a new kind of Erlang challenge: build a webapp in Erlang and show me how string handling was a problem for you. I’ve heard a number of people say that Erlang’s string handling is a hinderance in building webapps, but by my experience this simply isn’t true. If you ran into real problems with strings when building a webapp, I would be very interested in hearing about them, but otherwise it’s a waste of time hypothesizing about problems that don’t exist.
4. Functional Programming Mismatch
The issue here is that Erlang’s variable immutability supposedly makes writing test code difficult.
Immutable variables in Erlang are hard to deal with when you have code that tends to change a lot, like user application code, where you are often performing a bunch of arbitrary steps that need to be changed as needs evolve.
In C, lets say you have some code:
int f(int x) {
x = foo(x);
x = bar(x);
return baz(x);
}And you want to add a new step in the function:
int f(int x) {
x = foo(x);
x = fab(x);
x = bar(x);
return baz(x);
}Only one line needs editing,
Consider the Erlang equivalent:
f(X) ->
X1 = foo(X),
X2 = bar(X1),
baz(X2).Now you want to add a new step, which requires editing every variable thereafter:
f(X) ->
X1 = foo(X),
X2 = fab(X1),
X3 = bar(X2),
baz(X3).
This is an issue that I ran into in a couple of places, and I agree that it can be annoying. However, discussing this consequence of immutability without mentioning its benefits is missing a big part of the picture. I really think that immutability is one of Erlang’s best traits. Immutability makes code much more readable and easy to debug. For a trivial example, consider this Javascript code:
function test() {
var a = {foo: 1; bar: 2};
baz(a);
return a.foo;
}
What does the function return? We have no idea. To answer this question, we have to read the code for baz() and recursively descend into all the functions that baz() calls with ‘a’ as a parameter. Even running the code doesn’t help because it’s possible that baz() only modifies ‘a’ based on some unpredictable event such as some user input.
Consider the Erlang version:
test() ->
A = [{foo, 1}, {bar, 2}],
baz(A),
proplists:get_value(A, foo).
Because of variable immutability, we know that this function returns ‘1′.
I think that the guarantee that a variable’s value will never change after it’s bound is a great language feature and it far outweighs the disadvantage of having to use with unique variable names in functions that do a series of modifications to some data.
If you’re writing code like in Damien’s example and you want to be able to insert lines without changing a bunch of variable names, I have a tip: increment by 10. This will prevent the big cascading variable renamings in most situations. Instead of the original code, write
f(X) ->
X10 = foo(X),
X20 = bar(X10),
baz(X20).
then change it as follows when inserting a new line in the middle:
f(X) ->
X10 = foo(X),
X15 = fab(X10),
X20 = bar(X15),
baz(X20).
Yes, I know, it’s not exactly beautiful, but in the rare cases where you need it, it’s a useful trick.
This issue could be rephrased as a complaint against imperative languages: “I don’t know if the function to which I pass my variable will change it! It’s too hard to track down all the places in the code where my data could get mangled!” This may sound outlandish especially if you haven’t coded in Erlang or Haskell, but that’s how I really feel sometimes when I go back from Erlang to an imperative language.
Erlang wasn’t a good match for tests and for the same reasons I don’t think it’s a good match for front-end web applications.
I don’t understand this argument. Webapps need to be tested just like any other application. I don’t see where the distinction lies.
5. Records
Many people hate records and on this topic I fully agree with Damien. I think the OTP team should just integrate Recless into the language and thereby solve most of the issues people have with records.
If you really hate records, another option is to use LFE, which automatically generates getters and setters for record properties.
Incidentally, if you use ErlyWeb with ErlyDB, you probably won’t use records at all and you won’t run into these annoyances. ErlyDB generates functions for accessing object properties which is much nicer than using the record syntax. ErlyDB also lets you access properties dynamically, which records don’t allow, e.g.
P = person:new_with([{name, "Paul"}]),
Fields = person:db_field_names(),
[io:format("~p: ~p~n", [Field, person:Field(P)]) || Field <- Fields]
Records are ugly, but if you’re creating an ErlyWeb app, you probably won’t need them. If they do cause you a great deal of pain, you can go ahead and help me finish Recless and then bug the OTP team to integrate it into the language :)
6. Code oragnization
Every time time you need to create something resembling a class (like an OTP generic process), you have to create whole Erlang file module, which means a whole new source file with a copyright banner plus the Erlang cruft at the top of each source file, and then it must be added to build system and source control. The extra file creation artificially spreads out the code over the file system, making things harder to follow.
I think this issue occurs in many programming languages, and I don’t think Erlang is the biggest offender here. Unlike Java, for instance, Erlang doesn’t restrict you to defining a single data type per module. And Ruby (especially Rails) applications are also known for having multitudes of small files. In Erlang, you indeed have to create a module per gen-server and the other ‘behaviors’ but depending on the application this may not be an issue. However, I don’t think there’s anything wrong with keeping different gen-servers in different modules. It should make the code more organized, not less.
7. Uneven Libraries and Documentation
I haven’t had a problem with most libraries, and in cases where they do have big shortcomings you can often find a good 3rd party tool. The documentation is a pain to browse and search, but gotapi.com makes some of this pain go away.
Summary
Is Erlang perfect? Certainly not. But sometimes people exaggerate Erlang’s problems or they don’t address the full picture.
Here are some suggestions I have for improving Erlang:
- Add a Recless-like functionality to make working with records less painful.
- Improve the online documentation by making it easier to browse and search.
- Make some of the string APIs (especially the regexp library) also work with binaries and iolists.
- Add support for overloading macros, just like functions.
- Add support for Smerl-style function inheritance between modules.
Like any language, Erlang has some warts. But if it were perfect, it would be boring, wouldn’t it? :)
Favorite Lisps Poll Result
With 78 responses so far, here are the breakdowns for the responders’ favorite Lisps:
Scheme: 41%
Common Lisp: 27%
LFE: 12%
Arc: 10%
Emacs Lisp: 6%
Clojure: 4%
You can see the full report here.
I thought that Common Lisp would get more votes Scheme (isn’t CL more widely used?), but apparently I was wrong. Arc and LFE have made an impressive showing for their young age (but this is probably due to the bias of my blog readers).
