Debugging Erlang

In 2007 when I keyed my first “HelloWorld.erl” in Notepad, I remember a general uneasiness descending over me.

I’m typing code in Notepad.
Notepad doesn’t have syntax highlighting.
Notepad doesn’t provide error squiggles.
Notepad doesn’t provide IntelliSense.
Notepad doesn’t have a “Build Solution”.
How am I supposed to set a breakpoint from Notepad?
How am I supposed to debug this stuff?
Oh, dark night of the soul! What am I getting into here!?

Well here’s an answer to at least the debugging bit…

This screencast is a simple demo of debugging (stepping through) a recursive function in an Erlang module. For grins, and to make it clear that no IDE magic is involved, the code is edited using Notepad.

My plan is to release a new “Erlang for .NET Developers” screencast each week. Most will follow this simple “answer to common questions” format. In the next one, I’ll show my Emacs Erlang rig (with syntax highlighting, error squiggles, auto-completion) in action. From there I will work down a list of questions that O.J. Reeves (@TheColonial) and I have accumulated. The two of us are drafting a book with the working title “Erlang for .NET Developers”. If you are a .NET developer and learning Erlang, we would love to see your questions. Please post them as comments or via Twitter.

Tags: , ,

1 Comment

Setting up an Erlang Rig on Windows

In January I posted that I was diving into Linux full-time for my Erlang work. Erlang RigErlang itself runs great on Windows, Linux and Mac. I made the shift because most Erlang developers work in Linux and I felt I was probably missing something with my Windows-centric approach. This turned out to be a very valuable exercise. I tried out ErlIDE (Eclipse), a tricked out gedit, Vim, and Emacs. In the end, the best-paved and most productive path for Erlang development appears to be Emacs tricked-out with Erlang goodies and a console standing by for running Rebar and Git commands.

Here’s what my Erlang rig consists of:

  • Emacs 23.3
    • Erlang mode : Provides syntax highlighting,
    • Flymake: shows warnings and errors on the fly as you type like visual studio
    • IDO: Adds a good way to browse directories and open files
    • color-theme: adds pretty colors and fonts
    • Distel: theoretically provides auto-completion, step through debugging and other goodies.
    • Key mappings: Adds the key bindings for Cut,Copy,Paste,Alt-F4, Ctrl-Tab that a red-blooded Windows expects.
  • Rebar
  • Git

A few months in, I realized all of these things should work just fine on Windows. Today I have the same Erlang development rig on both Windows and Linux. This makes me very happy. Why? I’ve mentioned this in previous posts, but I believe C# and Erlang are great complements. Even in a Windows-only .NET shop with no appetite for introducing Linux, there’s no reason to take Erlang off the table. Having a proper Windows tool-chain for Erlang development moves the discussion away from an OS holy war and back to a cost-benefit analysis of Erlang itself. That’s a good place to be.

Each time I’ve done my “Intro to Erlang for C# Developers” talk, folks see my Windows Emacs rig in action and ask “What’s involved in getting that to work?” For anyone who is interested here are the steps:

Get Erlang R14B03

  1. Download Erlang from here.
  2. Run the otp_win32_R14B03.exe setup file. By default the installer wants to put Erlang here “C:\Program Files\erl5.8.4″ but change that to “C:\erlang\erl5.8.4\”. OK, but why? Most of the tools and scripts you will use for Erlang development on Windows were crafted over on Linux and the authors may not have tested for spaces in the path (e.g. “Program Files”). Remove that risk.
  3. Add “C:\erlang\erl5.8.4\bin” to your PATH.

Get Emacs 23.3

  1. Download Emacs 23.3 from here.
  2. Right click the zip and “Unblock” it.
  3. Extract it to a sensible location such as “C:\utility\emacs-23.3″. Again avoid spaces in the path to avoid unnecessary pain.
  4. Add “C:\utility\emacs-23.3\bin” to your PATH.
  5. Add an environment variable named “HOME” and give it the value of your home directory (for me this is “C:\Users\bryanhunter”)
  6. Run Emacs. When it loads it should have a white background, a homely font, and the most hideous splash screen you’ve ever seen.
  7. Close Emacs.

Pull down my Emacs configuration files [updated 8/27/2011]

  1. Visit my GitHub repository named ErlangRigEmacsConfig
  2. Read the readme file
  3. Download the zip of the repository. This repository contains the “.el” (Emacs Lisp) files that turn plain old Emacs into something pretty nice for Erlang development.
  4. Right click the zip and unblock it
  5. Extract it into your home directory (for me this is “C:\Users\bryanhunter”). Note: this needs to match what you put in the HOME environment variable under the Emacs steps.
  6. Edit your “~/.emacs” file to something like this:


If all went well, when you open Emacs it will show a nice black background screen. If you (or I) missed something, you will see the hideous default Emacs splash screen.

Extra credit #1: Use a prettier font

  1. Download the lovely “DejaVu” font family from here.
  2. Unblock the zip and extract it somewhere.
  3. Open up the “dejavu-fonts-ttf-2.33\ttf\” directory.
  4. Select all the TTF files and drag them into your “C:\Windows\Fonts” directory.
  5. Open the “my-config.el” file (it’s in your fancy new Emacs configuration directory).
  6. Find the line that reads “:family “Consolas”” and replace “Consolas” with “DejaVu Sans”.
Extra credit #2: Start learning Emacs Lisp
  1. Open the “my-config.el” file (it’s in your shiny new Emacs configuration directory).
  2. Read it top-to-bottom.
  3. Tinker, save your changes, reload Emacs.
  4. Read the “Programming in Emacs Lisp” guide  (here) to get smarter.
  5. GOTO 3

[Note: this post will be in flux until it is correct and complete. Please comment to help me get it there.]

Tags: ,

14 Comments

devLink 2011 and “Erlang: an Intro for .NET Developers”

A big, warm “thank you!” to those who attended my Erlang session at devLink. Your feedback and enthusiasm have made my geek-year.

As promised, here are the slides…

… and the code samples (on github) from my session.

This year’s devLink got off to a great start with Ayende Rahien delivering the opening keynote. It was titled “NoSQL – A change of perspective for the developer of today“. I heard a lot of Aha!-s from the audience as Ayende talked about the cost of hard disk space in the 80s when relational storage climbed to dominance. He described how ideas that are formed under one set of conditions can build momentum and barrel through the decades as unchallenged defaults even after the conditions that made them relevant have vanished. Spotting examples of this truth will provide me years of dark sport.

To my delight, Ayende mentioned “Erlang” 14 times during his keynote. In addition to hundreds of people simultaneously “getting” what non-relational stores are about, many in the crowd had just heard of “Erlang” for the first time. By the end of his keynote, it was clear that he’s an admirer of Erlang’s capabilities even if he thoroughly dislikes its syntax. One section of the keynote that was of particular interest to me was where he recommended that all of the conference attendees should “check out Bryan’s Erlang session”. Wow! This shocker was one part “Too cool!“, one part “Oh, dear…!” As a result of his nod: 1) I didn’t get much sleep, and 2) my talk was packed to the gills. I’m happy to report it went very well.

In addition to the keynote and my talk, I’m aware of several other sessions that touched on Erlang:

  • Alex Robson‘s “Messaging Patterns with RabbitMQ”,
  • Jim Cowart‘s “Getting Started With Node.js”,
  • Chris Meadows‘s “Redis In-Depth”,
  • Josh Bush‘s “Getting Started with CouchDB and .NET”,
  • Dan Mohl‘s “Getting Started With F# Web Development”,

and in the open spaces, Erlang came up in the CQRS session, and in the Corrugated Iron session led by Jerimiah Peschka that I (kicking myself) missed.

There seems to have been some sort of dark-horse, tipping-point event for Erlang at devLink this year. Lots of illumination, lots of chatter, lots of installs. I’d like Erlang to become familiar in good .NET shops in the same way SQL and JavaScript are today. It’s a far off goal, but we moved a bit closer last week. Godspeed!

If anyone knows of other devLink sessions where Erlang got play, please let me know. I’d like to list them above.

Tags: ,

No Comments

CodeStock 2011

My first CodeStock was big fun. Very healthy vibe, cool space, cool people, the nightly parties were crazy and Charles Petzold gave the best keynote I’ve ever seen. I was originally scheduled to only present “Intro to Caliburn.Micro”, but with the last minute Mono news and schedule changes Michael asked if I could also do an “Intro to Erlang (for C# Developers)”. Heck yeah! Here are my promise fulfillments (slides, links,…) from these two talks.

“Intro to Caliburn.Micro” Saturday, June 4, 9:50-11:00.

You can find the slides and code samples for this talk on GitHub here. The samples are built against (and include) the Caliburn.Micro 1.1 RTW build. Shawn Lacroix and I are planning a screencast series (five minutes each) that will capture all the juices and flavors of this talk. I’ll post here when we pull that off.

“Intro to Erlang for C# Developers” Saturday, June 4, 11:10-12:20

This was the first time I had given this talk, and it was a fun one. You might wonder why the president of the Nashville .NET User Group is going around evangelizing Erlang? I’ve got that question; so here’s the why…

I first learned of Erlang in 2007 while on a six-week consulting engagement in Oslo, Norway. In a sea of leaky C++, tower-of-babel class hierarchies and endless event storms there was one patch of calm: it was an Erlang system that had been running for years with no bugs and with no downtime. I was stunned. When I got back to Nashville I picked up Joe Armstong’s book (listed below) and have been digging in ever since.

Erlang is a beautiful (and fun) language, and its pattern matching is simply amazing. When asked on Twitter “Why Erlang?” here’s my answer: “Erlang is open source, cross-platform and proven. It simplifies writing safe, concurrent, distributed code.”

At a certain point it started to seem like a real shame that so few .NET developers were familiar with Erlang. A team of C# and Erlang developers is a force to be reckoned with because Erlang and .NET are complements. Each is lousy at what the other is exceptional at. Realizing this can save a company a lot of time, money and headaches.

Well, how do you even get started? How does a .NET shop begin to evaluate Erlang? How do you interop .NET and Erlang code? That’s what I hope this talk helped with.

Packed in at CodeStock

In the picture we’re discussing Virding’s First Rule of Programming which states:

“Any sufficiently complicated concurrent program in another language contains an ad hoc informally-specified bug-ridden slow implementation of half of Erlang.”

This quote is one part “funny”, one part “flash of embarrassing truth” to anyone who has home-grown a distributed, concurrent system. Ahhh… the past is the past; to the future!

Here’s what I promised during the presentation:

“Getting started with Erlang” links:

If you were at either of my sessions, I’d love to hear your suggestions. Also, let me know if I forgot any promised links.

If you weren’t there, but it sounds interesting, I’ll be giving an updated version of “Intro to Erlang (for .NET Developers)” at devLink (August 17-19) and at drivable-from-Nashville .NET user groups (e.g. Evansville, IN). I am trying to decide what mix of speaking engagements, blog posts and screencasts make the most sense.

Feedback welcome!

Tags: , ,

2 Comments

Installing Erlang R14B03 on Ubuntu 11.04

In January I said I would post instructions on installing the latest Erlang on the latest Ubuntu. Apparently organized people can write major updates to both operating systems and to languages faster than I can write a single paragraph in WordPress. Sigh... Ubuntu is now at 11.04 and Erlang is at R14B03 (just released today!). To make up for being a slacker, here’s a script (a github gist) to install Erlang 14B03 on a fresh install of Ubuntu 11.04:

It’s not as pretty as “apt-get install erlang”, but unfortunately apt-get will give you R13B03 which was released way back in Nov 2009 (five releases ago). If you spot anything silly let me know. For what it’s worth it works on my machine… : )

Erlang R14B03 (erts-5.8.4) [source] [64-bit] [smp:2:2] [rq:2] [async-threads:0] [hipe] [kernel-poll:false]

Eshell V5.8.4  (abort with ^G)
(node1@firefly)1>

Tags: , ,

9 Comments

I, n00b: At the border-crossing from C# to Erlang (on Ubuntu)

I’m a C# .NET developer. I have spent most of the past 18 years in Windows. I’ve played around with various Linux distros, but it’s really been hobby stuff. Another hobby over the past three years has been learning Erlang. Until recently I’ve used the Windows builds of Erlang and it’s been fun and easy.

I’m now on a full-time Erlang project and have realized my Windows-centric approach to Erlang development is adding lots of friction to “going pro”. Erlang runs perfectly well on Windows, but most of the Erlang community develops on Linux (or Mac). As a result, the developer tool-chain is much more complete in Linux. As I learn I’m constantly translating to Windows what the experts are saying and doing in Linux, and occasionally I hit dead ends. It’s been a challenge, but not the fun, worthwhile kind. So now I’m learning how to be an all-day-in-it Erlang developer on Linux (Ubuntu 10.10). I’ve had many newbie questions and I’m attempting to document them.  I plan to post answers as I stumble across them (e.g.- I’m currently piecing together a post on “Upgrading Erlang to 14B01 on Ubuntu 10.10″ ).

I have a professional goal of being able to fluidly shift between C#, Ruby, F# and Erlang on both Windows and Linux. Bigotry and partisanship aren’t pretty anywhere– not even in technology. I’m aiming to not have favorites or default answers, but instead to pick the best tool for the situation. It’s going to hurt a bit, but I think on the other side of this journey I’ll be a happier, smarter and more useful developer. And really what’s the alternative? Complacency? To acknowledge there are better ways to do what I’m doing, but that I’m too much of a “sorry ass” to get there? Please, heavens, no.

I’d be curious to hear from other folks who have made (or are embarking on) this journey.

Tags: , , , ,

4 Comments

“Caliburn.Micro Talk” project now on github

Going forward you’ll be able to find the latest revision of my “Caliburn.Micro Talk” on github here. If you don’t use Git (yet) you can download a zip of the latest here. If you have trouble compiling, or if you see ways to improve the samples I’d really appreciate the feedback.

Tags: , ,

No Comments

Caliburn.Micro talk at Nash.NET

I had a great time introducing folks to Caliburn.Micro at the October 14 meeting of the Nashville .NET user group. You can download the code samples here. The zip contains code samples (slightly updated from devLink), slides and a Word Document that compiles all of the documentation from caliburnmicro.codeplex.com.

Tags: , , ,

No Comments

Caliburn.Micro talk at devLink

I presented Caliburn.Micro at devLink on Thursday, August 5. You can download a zip of the code samples and slides here, or if you just want to preview the slides…

Not all presentations are fun to prepare, deliver or attend, but with this one I had a blast. Caliburn.Micro (CM) is a good topic. Folks can go from “zero” to “fumbling novice” after a one-hour session and within a couple of weeks of daily use they’re “old pros”. CM is powerful, small, and improves the air-quality in XAML shops (think code smells). At Firefly Logic we picked Caliburn.Micro as our company standard for XAML-based development just two weeks after it was released. Before you make a commitment like that it’s wise to have someone look over the entire code-base, and I did (each of the 2,000 lines). I didn’t spot a single skeleton, leather-gimp-hood, or toxic-waste-barrel in there. Three cheers to Rob Eisenberg!

So at the devLink session on Caliburn.Micro the room was packed (despite me being the speaker). Folks seemed excited about this new funky fresh addition to their toolbox. At the end of the talk a “by popular demand” follow-up session was added to the conference schedule, and in a surge of adrenaline I decided I would run it as an unstructured “dunking booth” talk— no agenda, the audience would just throw Caliburn questions, and I would try to answer them (without getting dunked). I like this format; lots of tacit knowledge is transferred that simply can’t flow in a structured PowerPoint-driven talk. The format has some problems though: it is chaotic and it’s terribly easy for the speaker to look like a damn fool. Happy to report I only got dunked twice!

If you’ve been thinking about speaking at your local .NET Users Group, you should consider Caliburn.Micro as a topic. Feel free to harvest stuff from my slides and samples if you do. This week I’ll start a series of “Caliburn.Micro from the trenches” posts you may find handy as well. The first will be on CM’s coroutines— very useful, but tricky.  Compressing this into a five minute epiphany box is my goal. We’ll see.

Tags: , , , ,

5 Comments

devLink – Functional C# (slides)

Here are the slides from my “Functional C#” talk at devLink. Enjoy.

Tags: , ,

No Comments