First Thoughts on Erlang Metaprogramming

Posted by Yariv on July 31, 2006

During my acquintance with Erlang, I’ve heard a number of people complain about Erlang’s limited metaprogramming abilities. The only “official” metaprogramming tool Erlang provides is the preprocessor, whose logic is limited to ifdef..else statements, so these complaints seem quite justified.

However, in my recent digging through Jungerl code, I came across the rdbms_codegen module, written by Ulf Wiger, and it gave me a different perspective on the issue. In fact, this code has made me wonder whether Erlang’s metaprogramming capabilities are actually unmatched by any other language. Why? Because this code shows that not only can you programmatically generate and parse abstract Erlang syntax trees, but when mixing it with Erlang hot code swapping, you can also hot-deploy this code in runtime, thereby creating dynamically mutating applications! How cool is that?

I’m not surprised that many people aren’t aware of this capability because, like many things Erlang, it’s not very well documented :) To use it, you need to understand the Erlang abstract format and to be familiar with the erl_parse and the code module. You also need to be able to piece everything together, which is far from obvious. Thankfully, we can all benefit from Ulf Wiger’s work, which gives us a good example of how to accomplish this wizardry.

I’ll probably write more about Erlang metaprogramming in the future, after I’ve delved deeper into this arcane and fascinating land.

The Real P2P King: eMule

Posted by Yariv on July 27, 2006

If you haven’t looked at the sourceforge stats lately and you’ve been getting most of your P2P data from various tech news agencies, the following fact has probably eluded you: the relatively under-hyped eMule is by far the most popular P2P app in the world.

According to sourceforge, eMule is the #1 download of all time, with 212,399,887 downloads. eMule leads Azuerus, the most popular open source BitTorrent client, by almost a factor of 2 — Azureus has been downloaded “only” 121,612,343 times. The mainline BitTorrent client, which is the #3 download of all time, has a “measly” 51,850,559 downloads. Even when you add up both the BitTorrent and Azureus numbers, you don’t come close to the total number of eMule downloads.

(Ares Galaxy’s meteoric rise in the sourceforge stats is also worth pointing out. In less than a year since its open source release, Ares has been dowloaded an astounding 35,575,917 million times — and that’s without counting the number of times Ares has been downloaded as a closed source app. That’s pretty amazing!)

I should mention that eMule Plus, an eMule knockoff, has been downloaded 15,090,841 million times. I would probably do justice to eMule by counting these numbers as eMule downloads, but even without these extra numbers eMule is the undisputed download champion on sourceforge.

The sourceforge stats aren’t a perfect indicator of popularity, especially since they don’t include a number of closed source (and hence spyware laden in most cases) P2P apps. In fact, according to kazaa.com, Kazaa has been downlooaded 389,392,921 times, which is much greater than the total number of eMule downloads. In light of this, why do I still believe that eMule is the King? Well, Kazaa may have been the popularity champion at some point, but it clearly isn’t now. Kazaa’s spyware and malware infestation must have driven away most of its users, who have grown more aware of the risks of installing a spyware laden monstrosity on their machines. The proliferation of corrupt files on the FastTrack network has also contributed to this trend according to this slyck.com article. The stats on the slyck.com homepage back this observation, showing a much larger number of users on the EDonkey2000 network (on which eMule rides) than the FastTrack network.

You get a similar picture from this Google Trends graph:







One fascinating trend this graph reveals is that eMule is even bigger than Skype!

It is strange how weak the correlation is between news coverage and popularity. A few quick searches I did yesterday in Google news reveal the following news story counts:

  • Skype: 2,040
  • BitTorrent: 434
  • Kazaa: 806
  • Limewire: 255
  • eMule: 8

(Note: many news stories came out today about Kazaa’s settlement with the recording industry.)

So, what’s the conclusion? Tech journalists apparently like writing about what other tech journalists are writing about. Also, to get news coverage, an application must have a company or a human face associated with it. Buzz just doesn’t flow in the way of a group of anonymous hackers who build a high-quality app that changes the internet on a mind-boggling scale.

Erlang vs. the One Red Paper Clip Guy

Posted by Yariv on July 24, 2006

A couple of weeks ago, I submitted to digg.com an article I wrote comparing Erlang + Yaws and Ruby on Rails as alternative framworks for web development, with the intention of raising awareness about Erlang’s web development capabilities. I then waited for the moment that web developers from all corners of the earth would flock to my blog, read the posting, and see the light. Although this may have happened on a small scale, my posting certainly didn’t change the course of mainstream web development: my posting only got 18 diggs the last time I checked.

Never abandoning my mission to raise people’s awareness about Erlang’s benefits, I decided to take a different angle — one that is destined to grab more people’s attention. In this posting, instead of comparing Erlang to Ruby on Rails, I decided to compare it to Kyle MacDonald, the One Red Paper Clip Guy.

Where do I start? Well, let’s enumerate some of Erlang and Kyle’s traits and see how they compare to each other:

  • Paradigm: Erlang is a functional language, which means that the primary conceptual units in Erlang are functions. This contrasts with object oriented languages, which emphasize classes and objects, and procedural languages, which emphasize subroutines and not much more.

    Kyle, on the other hand, is apparently dysfunctional. Kyle was unemployed at the start of his journey, and instead of looking for a proper job, he decided to execute a series of trades from the red paper clip on his desk all the way up to a house. Kyle happened to succeed in his quest, but if any normal person tried the same feat, most people would probably wonder what’s wrong with him.

    Winner: Erlang

  • Concurrency: Erlang was designed for concurrent programming. Erlang handles concurrency very well, and its lightweight approach to threads allows it to execute millions of tasks in parallel.

    Kyle, on the other hand, is a male, and hence is particularly bad at multitasking. In fact, chances are that Kyle can only do one thing at a time. (If you’re a guy and you can’t find any substantive research on the subject, just ask your wife, mom or girlfriend — while playing CounterStrike. Case closed.)

    Winner: Erlang

  • Performance: As I mentioned in the last item, Erlang was designed for parallel programming. This means that Erlang is very good for solving problems that can be decomposed into multitudes of parallel processes. Erlang doesn’t have the fastest performance in linear tasks, but it has no competition in scalable, parallel applications.

    By contrast, Kyle seems to excel in tasks that require a sequence of calculated steps until he reaches his goal. Kyle won’t give up before he succeeds. Without this determination and perseverance, Kyle wouldn’t have been able to trade a paper clip all the way up to a house — all in the course of one year.

    Winner: tie

  • High availability: Kyle is human, so Kyle needs to sleep. Kyle can’t actively pursue his goals with anything close to the %99.9999999 (yes, nine nines!) availability that Erlang applications can accomplish.

    Winner: Erlang (by a wide margin)

  • Spawning: Kyle has no children, and if he ever decides to have them, it’s likely he won’t make more than 3 or 4 of them due to numerous biological, social and economic constraints.

    In Erlang, on the other hand, it’s quite easy to spawn new processes. Just call the spawn() function, and you have a new process in a matter of milliseconds. You can spawn millions of processes if you want, and the Erlang VM would handle it with ease.

    It may seem as though Erlang is the clear winner, but when you consider the hypothetical effects of Kyle’s spawning millions of children, you realize that Kyle’s limited spawning ability is actually a big benefit to humankind. Therefore, my verdict is:

    Winner:tie

  • Yaws: According to Wikipedia, Yaws is “a tropical infection of the skin, bones and joints caused by the spirochete bacterium Treponema pertenue.” By all indications, Kyle is a healthy guy and is also Yaws-free.

    Erlang, on the other hand, has Yaws. In Erlang’s case, however, Yaws stands for “Yet Another Web Server.” Erlang’s Yaws is actually a wonderful web server uniquely suited for developing dynamic web applications with highly scalable and robust backends (in case you’re wondering, I have no indication that the same adjectives also apply to Kyle’s back end).

    Erlang’s Yaws is a great web server, but the negative connotations of its name warrant the loss of some points. Therefore, my vedict is:

    Winner: Kyle

  • Popularity: Kyle is quite popular. Due to people’s fascination with Kyle’s story, Kyle’s blog has had over 6,600,000 visits and Kyle has gotten press coverage from mulitple news agencies.

    Erlang, on the other hand, isn’t a very popular programming language. Just look at this Google Trends graph in case you have any doubts. This isn’t because Erlang isn’t a good language — it’s actually the best language for a certain class of problems IMO — but because Erlang hasn’t had the best PR. It’s also because many people actually think that PHP is a good language.

    Winner: Kyle

Here’s the final tally.

  • Erlang: 3

  • Kyle MacDonald, aka the One Red Paper Clip Guy: 2

Ladies and gentlemen, we have a winner: Erlang!

Now that you’ve read this highly convincing exposition, you can safely forget everything you know about web development and head over to the Erlang web site, the Yaws web site, or read my other Erlang articles (starting with the Hitchhiker’s Guide to Erlang). Learn, practice and experiment with Erlang, and in a couple of months you’ll be building telcom-grade backends for your websites with ease. I assure you it’ll be worth it!

How A Nigerian Scammer Tried to Rip Me Off on Ebay

Posted by Yariv on July 24, 2006

In this posting, which I wrote right after I posted my first Ebay auction to sell an old laptop, I jokingly alluded to the drama that would take place surrounding my auction. I never expected any real drama to actually take place, but lo and behold, it did — in the form of a Nigerian scammer trying to steal my laptop. Here’s the rest of this strange story.

Less than a day after I posted my old Compaq Laptop on Ebay for sale, and a week before the auction was to end, a person by the name of Richard Hudson, with the email address of bravecolonel22@yahoo.com, bought the laptop with the Buy It Now option. He then sent me the following message:

Hi Yariv,

Season’s Greetings to you.I am Richard Hudson from Pocahontas,Arkansas,US.I’m contacting you concerning your item on Ebay which i eventually became the winning bidder for your item.Morever i’m presently serving our beloved nation here in Iraq with the United Nation and i intend sending this item to my wife who works with the American Embassy in Nigeria as a visa Officer.You shouldn’t worry about the shipping fees to her okay?.I’ll take care of it with my Personal FedEx Account # after payment so you won’t need to pay any money when mailing it to her over there.I will be making my payment to you via PayPal,So get the package ready for immediate or next day shipment okay.Make sure you send me your PayPal Email Address so i can immediately make out my payment to you for this item purchase.You are to mail it out immediately you get the confirmation mail from PayPal.Mail me back it’s urgent.




Regards.

Richard.

It doesn’t take a genius to smell something fishy here. If the bad grammar and punctuation don’t give it away, the word “Nigeria” certainly raises alarm bells for anybody who has heard about the plague of Nigerian 419 scams on the internet. If you haven’t heard about them, I suggest you Google for “nigerian scam” and you’ll find plenty of information on this bizarre and disgusting phenomenon.

Fortunately, my scam radar was alert, partly because I had recently read the New Yorker article “The Perfect Mark” about this same subject. The article tells the story of a psychotherapist — an upstanding citizen by most standards — who has been suckered by a Nigerian scammer into sending most of his savings to Nigeria with the hopes of making a large return from a convoluted business scheme that was — guess what? — entirely fabricated.

It’s actually a very sad story because this scam ruined the psychotherapist’s life and ended up putting him in jail. However, you can’t feel too much sympathy for this guy because his misfortune is partly due to his own fault.

Going back to my story — at this point, I was quite certain I was dealing with a Nigerian scammer, but I played along because I was curious as to what his next step would be. I told him to PayPal me the money and I’d ship him the laptop. (I didn’t realize when posting the auction that Ebay allows you to enforce immediate payment by PayPal for Buy It Now sales. Because I didn’t use this feature, the scammer was able to steal my auction using Buy It Now without putting any money down. It also showed the scammer I was a new seller who obviously wasn’t versed in defensive tactics for Ebay sellers.)

Here’s the scammer’s reply:

Hi Yariv,



I have made out my payment to you for this item purchase and the exact amount of
what i bought from you has been deducted from my account,So check your mail for
the confirmation mail from paypal.Get the Package ready for immediate Shipment.You are to take the Package to any FedEx Location close to you for drop off.Paste the
information below on the package and make sure you fill the international airway bill
form correctly with the information below.Then do me a favour by putting the item
worth as $300.00 so as to reduce customs charges against her when receiving it over
there.Ship it via international priority.Then a tracking number will be giving you which
you will then send to paypal at pay-pal.com@consultant.com and your account will be credited with the exact amount of what i bought from you immediately.Hope to hear
from you when you have it maild out today.Have a nice working week ahead.



FedEx Account Number :- 170083695

NAME:- RICHARD A.ESTHER

ADDRESS:- 17B ADESHINA STREET

CITY:- IKEJA

STATE:- LAGOS

COUNTRY:-NIGERIA

ZIP-CODE:-23401

PHONE:-08034852880




Sincerely

Richard.

There are too many flaws and red flags in this email for me to go through all of them, but the fact that Richard’s “wife” is named “Richard A. Esther” makes it blatantly obvious that not only is this a total scam, but also that the scammer isn’t very bright.

The Nigerian scammer expected me to ship him the laptop without first making sure the payment has cleared. He thought he could trick me into thinking that PayPal would only forward me the money after I send PayPal the tracking number of the actual shipment at the very legitimate-sounding email address “pay-pal.com@consultant.com”. Riiiight….

A quick search on Google for “paypal.com@consultant.com” landed me on another guy’s blog who suffered from a similar scam. (That link is dead now, but I did find another link to this Ebay forum posting, where another person tells a very similar story.) I replied to the scammer telling him that our communications are over, but if he ever gets bored while bravely serving the country, he should read the blog posting I found as well as the New Yorker article I mentioned above.

I contacted Ebay and told them what happened, and after a couple of days, they sent a long and detailed reply telling me what I should do to get reimbursed for the auction and describing what steps I can take to protect myself in the future. I think Ebay has actually handled this incident pretty well, and I can’t blame Ebay entirely for what happened. There will always be online scams, and Ebay can’t completely block it from their site. However, I think that Ebay should place more noticeable warnings for sellers regarding such scams on its website — at the very least, next to the page where you can enable the Buy It Now option.

I think it’s sad that somebody would invest so much mental energy into devising ways of ripping people off rather than making money in legitimate ways, of which there are many. But then again, the effort on the scammer’s side may not be very high because he probably attempts the same scam on many potential victims. If he tricks a certain perentage of his victims into sending him relatively expensive items without paying for them, he can probably make a relatively good living, especially for his country.

Well, I hope that this posting raises your awareness and helps you avoid such scams on the internet if you ever come across one. Being informed will help you avoid these traps, just as the New Yorker article I had made it easier for me to recognize and avoid this particular scam.

Sometimes all the spam, viruses, scams, malware and other forms of digital filth that thrive online make the ‘net feel like a lawless, dangerous, ugly place. But then again, all the horrible things that happen in the real world make the ‘net seem almost clean in comparison.

My Erlang Wishlist

Posted by Yariv on July 21, 2006

Every person can dream, and I have been dreaming quite a lot. In fact, it wouldn’t be too far-fetched to say that I have taken this liberty and ran with it. Sometimes it’s hard to fit all my dreams into my skull, but I think I’ve managed it pretty well so far.



I’m a programmer, so it shouldn’t be a surprise that many of my dreams are about hopelessly geeky things. This blog has primarily served as an outlet for my Erlang musings thus far, so I figured this blog would be a good place to express my wishes for new capabilities and libraries I would like to have in my Erlang toolbox. I hope that some day the open source code fairy stumbles upon my blog and turns these wishes into reality.



Here are my Erlang wishes, in no particular order:


  • Shorter repair times for broken Mnesia dets tables. This has been discussed in the erlang-questions list here, here and here . I have some web application ideas for which Erlang would be a great server side language, and I just hate the thought of using another DBMS just for the fear of long downtimes in the event of a crash when my data set gets big. If dets were more resilient to crashes, I would lose my motivation to use another DBMS.

    After I’ve used Mnesia, going back to MySQL/Postgres just feels lame. I want Mnesia to be good enough for all my needs.

  • More scalable freelist handling in dets. Yup, dets has another problem: it uses a buddy system to maintain the freelist, and this freelist grows as the data becomes fragmented. The freelist is held in RAM, so this has a negative effect on memory consumption that gets worse over time. In addition, when you close a dets table, this potentially huge data structure needs to be serialized to disc, which can take a while. The only ways of shrinking the freelist is to close the table and reopen it in force repair mode, or to create a duplicate table that gets built from scratch without fragmentation. The first option can effect long downtimes, and the second option can be too expensive if the table is big. This is another force pulling me in the MySQL/Postgres direction, which, as you know, I’m trying to avoid.
  • A robust join optimizer for QLC. QLC is the main query language for Mnesia. Unlike most DBMS, the QLC query engine doesn’t have a join optimizer right now, so writing your query the wrong way could make it run off into the weeds. Postgres has what looks like a very sophisticated join optimizer, and I’d like QLC to have something similar. (Fortunately, this feature is planned for a coming release of OTP, but I wanted to mention it anyhow.)
  • An advanced full-text indexing library. Java has Lucene, Ruby has Ferret, C++ has CLucene, Python has PyLucene, etc, etc. Erlang has a text search feature built into the RDMBS module in Jungerl, but AFAIK it’s not as mature and feature-rich as the other libraries I mentioned. These days, almost every website needs a good text search feature, so having such a text indexing library would make my life much better.
  • A graphing library like Gruff. I like graphs. Graphs make me happy. I want to make graphs with Erlang, but right now there’s no easy way of doing it. I want an Erlang graphing library that’s easy to use.
  • A template language for Yaws. ehtml is pretty cool, but I think a template language produces more readable code. This has been discussed extensively on the mailing list, but I haven’t heard of any progress in this direction lately.
  • A RSS/Atom parsing library. Such a library would bring one of my project ideas one step closer to reality, and I really don’t want to write one myself because of all the hairy incompatibilities between the outputs of different feed engines. Why should I suffer if somebody else may be willing to take on this pain?
  • A better documentation website. It doesn’t take a sharp artistic eye to notice that the current design is less than beautiful. I would welcome any aesthetic improvements, but even more importantly I would like the online documentation to integrate user comments. This will give the existing documentation the extra substance it needs on some places. The MySQL, PHP and Postgres documentation sites are good examples of this.
  • A more active web development community. I don’t hear of many large-scale websites using Erlang, and I know of only few independent developers who are building websites with Yaws. This graph validates my feelings. More people need to use Erlang for web development so I don’t feel lonely and so I can use the solutions that other people contribute the to community. Sadly, I just don’t have the time to implement everything myself, which, combined with an occasional bout of laziness, is why I’m writing this posting in the first place.
  • A community website for Erlang developers,. This already exists thanks to the recently launched trapexit, but I wanted to list it anyway because I’ve been wishing for it for a while.
  • An Erlang/OTP road map. Besides a few features, I have now idea what the OTP group is working on and what they are planning on working on in the future. It’s possible they are already tackling some of the items I mentioned, but I’m in the dark about this, which is somewhat frustrating. I’d like to know where Erlang is going, not just where it is right now.
  • An Erlang-powered machine that brings world peace, saves the environment, fights poverty and disease, provides univeral happiness and finds me a new apartment. I can dream, can’t I? :)

Well, that’s about it for now. There are probably a lot more things I could think about, but I don’t want to overwhelm my poor readers, some of whom I must have bored to death by now. Now it’s time to sit back and wait for the open source fairy to google for “erlang wishes” and hopefully land here on my blog.



It’s bound to happen happen any day now — I know it!

The Best (or Worst) Spam Ever

Posted by Yariv on July 19, 2006

My Gmail mailbox used to be spam free, and it was a joy. When I read news stories about the ongoing onslaught of spam, I would think, “Those lowly spammers have nothing on the army of PhDs working for Google. I’m confident their crap will stay out of my mailbox.” My inbox actually made me feel comfortable. Those were the days.



A few months later, I realized a spam-free mailbox was just a pipe dream. I now get spam messages in Gmail almost on a daily basis. Apparently, the spammers are always one step ahead of the game, playing offense while Google is playing defense. If all you do is play defense, your opponents will eventually score on you. It’s only a matter of time.



Up until recently, the spam was just annoying. I’d delete it immediately without even thinking about. However, in the past couple of days, things have changed. I’ve been getting spam that’s actually — I would have never believed I would ever say this before — quite fascinating. This new spam nothing like the cliched Viagra ads or Nigerian scam that statistical spam filters have been squashing for a while now. It’s original. In essence, it resembles a semi-random collection of bizzare English fragments written by a highly literate person who’s had one too many bottles of Vodka. It almost looks… poetic.



It’s pointless to try to describe it any further. I’ll just quote the whole thing:

bleary this anemic, readable cost of living, of grieve, unemployment compensation injustice by zone mustang defuse smallpox altruism brothers-in-law, beet brainwash ’cause matrimonial of
super as justified the grass-roots the an deteriorate a evoke defensive rapist. the around donor, the but limerick, combine of drawing board, gray, parenthood as tandem as Anglican with phenomenally a retention policeman perjure the and as tangle varsity… wholeheartedly in of sweetness or pleasurable dentures.
extremist the in portly, key!!! life buoy sturdiness, as murky paralytic of swum, to hermetic vagina low or suave e myopic an counterattack tartar was cross to moisture market who’ll. Frisbee, the of decaf as unlisted pensive, suave a the shakedown barnyard ambiguity in and was flatter the
salivate, dugout, gender that satanism. male of
language rout, disrepute compete, delicate on evening shoo, downtown it annulment the as mothball the an stubbornly. ESP in papaya, mystery. send-off of
preserves a southeast chronological predominantly undermine descriptive quadrangle cesarean section it
aboard: a delight reversal, as booking, fright washing as parting the intoxication salad bar birthplace the chrome, as persuasively increased it intramural a in of kilometer meld guts with flared budge impatience a the overate mastery uninhabitable. casing enrich. to lop operator parchment, a comprise,
sterling this chick,. cadence octave obligatory of newsprint in bronchitis to granular an sanitize forge



You can’t deny that’s some quality spam right there!



(Below the text were attached image fragments that aluded to some stock buying opportunity on which I was missing out, but that’s too boring to include here.)



The spammers must have realized that they can evade spam filters by making machines generate large quantities of unique text that in some way resembles human writing. The actual selling pitch is embedded in images outside of the text so the statisical text-based spam filters can’t identify it. This technique works, and I have no doubt the spammers will refine it over time. I expect these spam messages to look more and more like they written by real humans.



I’m sure that pretty smart people are behind this new spam attack, as the dumb spammers eventually get wheeded out by natual selection: their messages don’t penetrate the filters, spamming stops being profitable, and they turn to other ways of making money.



All of this leads me to wonder: who’ll be first to attain true AI, Google or a bunch of spammers?



For the sake of our inboxes, I hope it will be Google!

Finally: A Solid Erlang Community Site

Posted by Yariv on July 18, 2006

I’ve been waiting for this one for a while: a website for and by the Erlang developer community: trapexit.org, “your last stop for Erlang information.” Finally, Erlang developers will have a wiki, forums, tutorials, blogs, and a place to share knoweldge with each other outside of the erlang-questions mailing list.



The mailing list is effective, but it has drawbacks. Sometimes you have a question and you just don’t want to address the entire Erlang developer population with it. It often makes a lot more sense to post it in a forums dedicated to the specific topic of your question. Plus, you don’t want to bombard the mailing list with too many questions because you don’t want people to think you’re a pest (I think I’ve tested this limit myself all too closely a few times :) ).



Forums are more user friendly than mailing lists in my opinion. They are easier to search and browse, and they have a more welcoming feel. The main downside is that this splinters the community between the mailing list and the forums. I’m looking forward to see to what degree the community embraces them.



My outlet for Erlang ramblings has been this blog up till now. Maybe now that trapexit is around I’ll channel some of my writings to its wiki. This will finally give me the opportunity follow my heart and dedicate this blog to Java Server Faces.



Just kidding!!! :)

Embracing Typo

Posted by Yariv on July 16, 2006

My blog has had quite a journey through different blogging services.



It started at Blogger because it was so easy to set up and start blogging, but I lost my love for Blogger after a while because Blogger didn’t let me login to my blog or edit it over SSL. Call me crazy, but I just don’t like sending the password for my blog in plaintext over the internet. Having my blog hijacked by a 13 year old Ukranian hacker would really spoil the fun of having a blog.



My blog’s next stop was wordpress.com. wordpress.com gives you full SSL access, which is pretty awesome, and it has a pretty nice interface. However, wordpress.com is too locked down for me. It’s impossible to manually edit template, and the template selection was pretty poor IMO. Some templates looked nice, but all of them had one or two big flaws that turned them off to me.



Plus, I’m a geek, and I like having full control over blog. At wordpress.com, I have ran the risk of not being able to do whatever I want to do with my blog. That’s not to say Wordpress is a bad service — I’m just not in its target audience.



I stayed at wordpress.com for a while, but when my discomfort has reached a certain level I started looking for alternatives. Then I discovered Typo, a very cool blogging application written in Ruby on Rails. I played with Typo for a little while and I fell in love with it very quickly. Despite its young age, Typo is packed with features, it has a great interface, and because it’s written in Rails, I feel right at home with the source code.



I decided to host Typo on my own server (it runs Debian with Lighttpd) so I can have total freedom to tweak it as I please. My blog has finally found its ideal home.



Big thanks to the Typo developers for giving people such a great blogging tool!

haXe Remoting with Erlang + Yaws

Posted by Yariv on July 14, 2006

Yesterday, Yaws version 1.64 was released. This version contains the haXe remoting code I contributed, so now Erlang developers can benefit from haXe’s great capabilities for AJAX/Flash client development.

Go get your hands on the latest version of Yaws at http://yaws.hyber.org. For documentation on how to use this feature, visit http://yaws.hyber.org/haxe_intro.yaws.

haXe remoting brings Erlang one step closer to being The server language for high-end web applications — not just for its scalability, high-availability, clustering, soft real-time communications, fault tolerance, etc — but also for rapid development.

You should know that haXe is also moving fast towards providing a platform for full desktop clients development — not just web clients. There are two projects to keep an eye on: ScreenWeaver HX and xinf. I don’t know how mature they are at the moment, but in a couple of months everything can change. These desktop frameworks use the NekoVM for the runtime, so I wouldn’t rule out developers’ using Neko <-> Erlang RPC any time soon.

Where do I see this going? I don’t know of a better set of technologies for building Comet apps, which let the server push messages to the client by keeping the connections alive (due to Erlang’s approach to concurrency, Yaws scales in this scenario far better than any other webserver I know). This technique finally lets you break the old request->response cycle, thereby blurring the line between traditional web applications and the rapidly evolving space of instant messaging applications.

One concerete possibility is massively multiplayer online games with browser-based clients. Many types of collaboration and instant communication applications could use this great hybrid as well. (My imagination is limited. I have no doubt we’ll see amazing apps that I have no ability to predict :) )

If I only had the time to build all the apps I want to build…

The Hitchhiker’s Guide to Erlang

Posted by Yariv on July 12, 2006

If you’ve heard about Erlang and you want to use Erlang to build a website site but you’re not sure where to start or where to find good online resources for Erlang web development, I know how you feel. I went through it myself. However, I stuck with it, did my share of Googling and mailing list questioning, and over time I got a good sense of how to navigate the Erlang world. I hope I can make your journey easier by giving you a few pointers.

First, let’s get off to a quick start.

- download Erlang/OTP
- configure, make, make install.
- download Yaws, “The” Erlang web server.
- configure, make, make install
- run yaws from the command line
- create /tmp/foo.yaws and open it in a text editor
- type the following


 
<html>
<head>
<title>my first Yaws page</title>
</head>
<body>
<erl>
out(A) ->
  {ehtml, {p, [], "hello world!"}}.
</erl>
</body>
</html>



- open your browser and go to http://localhost:8000/foo.yaws.

Here ya go! Now you’re officially among the ranks of Erlang web developers. :)

Let’s now take a few steps back. If you’re reading this, you must have heard about Erlang and how its unique strengths let you build scalable, distributed, highly-availabile applications with much less effort than other languages. You want to use Erlang’s power to build a scalable web application, but you’ve probably noticed that Erlang hasn’t been as widely adopted by the web developer community as other solutions (e.g. Ruby on Rails), and that there aren’t too many blogs and tutorials about Erlang web development online.

There’s an Erlang reference book, Concurrent Programming in Erlang , which I admit I haven’t read, but from the table of contents I see it doesn’t discuss web development. You can find a couple of articles about Erlang, but they are mostly introductions Erlang as a language and none of them shows you how to use Erlang to quickly whip up a few web pages, which is probably what you want to with the least amount of pain.

None of this means you should follow the crowd and go to other languages just because they are somewhat more accessible and more developers are using them. I assure you that with some effort you’ll get all the reference and help you need, and in a little while you’ll be able to build the kind of backends that make Google seethe with envy.

Ok, maybe that was a slight exaggeration, but there’s always a chance you’re the next Larry Page, isn’t there? :)

Alright, let’s hit the road. Your first destination should be Open Source Erlang’s official homepage. Every beginner should do the Getting Started Guide, and then the Language Reference.

As you’re going through these manuals, make sure you have the Erlang shell open so you can write some short code samples. Type help() in the shell to see the list of commands.

Emacs is the “standard” development tool (the OTP distribution comes with Emacs language files), but if you’ve been spoiled by Eclipse you’ll be happy to get your hands on Erlide.

When you think you have a good bearings on the basics, you may want to take a look at some code examples (I find that reading examples is often the best way to learn).

Now that you feel comfortable coding in Erlang and you’re ready to experiment with some more web development, you should visit the Yaws webpage. This page has many useful instructions and examples on how to build dynamic web application with Yaws. If you understand Erlang, and you’ve done some web development, Yaws is pretty easy to learn. Yaws doesn’t have a full MVC framework like Ruby on Rails, but it does have some nice features that give you similar abstractions: ehtml for views, appmods for controllers, Mnesia for the model. The Yaws distribution comes with some examples and you’ll pick up some good methodologies by looking at their source code.

Build a few dynamic pages. You’ll feel that tingling satisfaction when you see your Erlang code in action.

You should know that Yaws is a great web server for AJAX apps. Yaws has a JSON-RPC module, and even better, the next version of Yaws will support haXe remoting, hacked by yours truly. Read my previous blog posting about Yaws’s unique strengths for Comet-based apps. IMO, this is the future of webapps, and Erlang + Yaws lead the competition by a wide margin in this area.

After you’ve made a few pages, it’s a good time read the efficiency guide and programming conventions document, which admittedly aren’t super exciting but it’s good to know this stuff. Make sure you understand the cost of common operations. When you have a good bearings on the language, you should browse through the module list in the main documentation site to get a feel of what’s available with the standard distribution

When you feel like you’ve done all you can independently and it’s time to get some help from (gasp!) actual humans, you have two options: the erlang-questions mailing list and the erlyaws mailing list. erlang-questions is the place to go for general questions and erlyaws is more focussed on web development. Very knowledgeable people — among them some of Erlang’s creators — will answer your questions on both mailing lists.

Read the Mnesia User’s Manual. Mnesia is a distributed database written in pure Erlang and many Erlang apps use it. If your app doesn’t require storing many gigabytes of data, Mnesia is a great solution. Keep in mind that Mnesia disc storage has a couple of issues. These may not be deal breakers, but if you have large datasets and you prefer to use a different disc storage engine, I recommend the MySQL or Postgres driver.

If you want to get a truly in-depth understanding of Erlang, you must read Joe Armstrong’s PHD thesis. It will give you the overall picture on Erlang’s history and the decisions that have shaped its design. It also covers basically every aspect of the language and explains how to to design fault tolerant systems in Erlang. I recommend this paper to every new Erlang developer. (Just don’t panic when you read the section about Ericsson’s banning Erlang from new projects. This stuff is ancient history.)

As you’re building your app, you should know about Jungerl, an open source “Jungle of Erlang Code” — a fitting description. Look at the list of modules because some of them may be useful to you.

If you want to explore even more exotic destinations, check out Joel Reymont’s blog, in which he tells the story of building a scalable poker server in Erlang, and also Joel’s DevMaster article about it. The source for his poker backend is available as well.

You can always learn a lot from looking at source code of experienced Erlang hackers. A few good sources I found are Yaws, Jungerl, Joel’s OpenPoker server and ejabberd, a top notch Jabber server written in Erlang. ejabberd has makes use of MySQL/Postgres, and even has an abstraction layer for both drivers, which is useful if you wish to use these databases.

Well, I hope you find this useful. If there’s anything you think I left out, please let me know. If you want to read more of my ramblings about Erlang, check out my previous blog postings about it or stay tuned for some future ones. Otherwise, stop wasting your time here and go build that Erlang-powered Google killer!