Author Archive

Happy Holidays. 2

I’m not sure if anyone reads this regularly, but with that uptick in people stopping by I thought I would wish everyone a great holiday season just in case they do!

I switched the theme for the site because I was running out of tab space at the top and I will be putting up at least one new project for people to look at relatively soon. My first in erlang!

Also, if you haven’t already checked it out, erlanguid.com is up and running. Not too many members right now but I’m hoping that as time passes and I can get some good tutorials/screencasts up there about working with erlang and setting up a development environment (yaws appmods, debugging with emacs, io:format vs io_lib:format, etc).

Again, have a great holiday and a wonderful new year!

An Idea: Scripted C# for ASP.NET Development 0

I work as a .NET consultant in New York, most often with ASP.NET and SharePoint so the frustration expressed here comes directly from experience. Outside of work I like to dabble with lots of other neat tools an one thing I’ve really gotten used to in web development is NOT having to compile when I make simple changes to my app. PHP, Python, and Ruby all make this very easy. And if your project is pretty small, using ASP.NET doesn’t add too much over head. But that doesn’t last for long

The problem is when the project gets large or you group a lot of classes/code into a single DLL and THEN have to compile them to see your changes. Even failing to mention the need to get IIS to clear its cache before anyone can see a change from the code, there’s a wait time of 30 seconds to a minute depending on the size of the dll.

I hear you say, “30 seconds isn’t that big of a deal”, but doing a little math shows you that 30 seconds compounded maybe a hundred times (conservative) a day over the course of a week or two and you end up with hours wasted. All that time spent just waiting, doing nothing. What’s worse is that you lose your focus on what you’re testing. You’re continuity of thought is crushed under the weight of compiling your 1 liner alteration.

So, lots of whining without many suggestions. Well here it is: http://tirania.org/blog/archive/2008/Sep-29.html. That’s the mono project’s leader Miguel De Icaza’s blog and he talks about the csharp interactive shell that came out of the mono project recently.

What I would like to see is a development mode for IIS that deals with C# in a script like fashion, using something like the aforementioned link so that we can stop compiling things while were working on them, and still get the nice quick execution we’ve come to expect from compiled/cached .NET assemblies in production. Faster iterations means more efficiency and less brain breaks when developing web applications.

Right, the page might load slower when you fire up your server, but I’m tired of recompiling some huge thick dll every time I make an extremely small change.

Erlang and Cloud Computing: A Fine Pair Indeed 6

[update]: Some clarification (in it’s favor!) on Mnesia’s limitations thanks to commenter Gleb Peregud

“The Cloud”. Infrastructure as a resource. Whether or not you’ve bought into the hype (or HiPE as you prefer :D ) some of the largest software/IT companies in the world are throwing piles of cash at this idea of a hardware-service. But, for the purposes of new web applications that are looking to take advantage of hardware scaling to meet demand, there’s a lot of work to be done. For a quick roundup on some of the issues facing web applications with the EC2 platform you can check out Tony Arcieri’s Post on Rails with EC2. Just as Tony Points out in his article, Erlang has a lot of tools ready made for these demands, and, with the added side benefit of proven stability/scalability in intense environments, it’s certainly worthy of some consideration for your next cloud ready app.

A Language (and VM) Built to Scale

Erlang has been around the block a few times ( short history ), and it’s been used in some situations with incredible requirements and results. From it’s home at Ericsson to other telecom applications with the likes of Nortel, T-Mobile, and Motorola, where it has achieved 5 nines of availability in some instances, Erlang has been proven as a reliable platform on which to build applications.

Platform is the key word there, because it’s not just the language and its syntax that make it great for it’s appointed task but also the VM that it runs on. Erlang’s VM comes with some really great features that also make concurrent programming a lot easier.

  1. “Green Threads” - There’s some disagreement over whether the name is correctly applied in Erlang’s case, but the benefit is clear: Cheap process creation. In comparison system threads are “heavy”, and if a programmer is working with them on a intensive concurrent application they are forced to worry about going thread crazy because of performance degredation. While Erlang doesn’t completely fix this issue, it does the system thread managment for you, allowing for more attention to be paid to building the application as it makes sense for the problem set. If you need a thousand processes, then use a thousand.
  2. Message Passing Primitive’s - Erlang has been designed to pass messages between processes. It has built in syntax constructs specifically for this purpose, and while there are many languages that have something similar, it’s a great indicator of what the language was meant for. Here’s a very simple example:

    As long as you know the Erlang process id of a given bit of running code you can dial it up and tell it what to do.

  3. Hot Code Swapping - This is a big one here. This is where the 5 - 9 nines up-time comes from because, as long as your build your applications with a little forethought, you don’t have to bring them down for the purposes of providing bug fixes or features. Before jumping at the “with a little forethought”, take a read here and see how easy it really is. And it is easy, but even if it was hard when was the last time you worked on an application that didn’t need to be restarted when new code was added?

Libraries Ready Made for Distributing Load

Erlang comes with a whole host of libraries and modules built in support of its primary goal as a massively concurrent programming language. These libraries are important enough that Erlang is often referred to in conjunction with them as “Erlang/OTP”.

  1. Mnesia - “is a distributed DataBase Management System (DBMS), appropriate for telecommunications applications and other Erlang applications which require continuous operation and exhibit soft real-time properties.” (ref) I’m sure many of you are saying to yourselves, “I can distribute load with MySQL so what’s the advantage?”. The advantage comes from being able to add a table copy to a new node as easy as:

    That’s pretty amazing when you consider what it means for easy data distribution.

    Mnesia is not without its drawbacks though. Most importantly it wasn’t designed to store enormous tables like SQL databases. In fact it has a 2gb table size limit for disc_only_copy configuration of tables, but the in memory and memory and disc table copies are only limited by ram size. Also, with more than 8-10 nodes the amount of network communication may begin to inflict performance degredation. (Big thanks to comment poster Gleb Peregud, for both of those tidbits).

  2. gen_server - gen_server is a module that provides an interface that allows your code to take advantage of much of the OTP goodness like process supervision and logging without lifting a finger. Supervision itself is enough to get excited about, as it allows safe and reliable process topologies to be created with ease. Processes monitoring and restarting other processes sounds like a recipe for reliability when implemented correctly.

That’s only two notable examples from an enormouse set of libraries all targeted at reliable distributed infrastructure. Most of which have been proven in the harsh environments mentioned earlier.

Alternatives to Erlang

This is a big enough market that there are bound to be a lot of solutions out there for the problem of easy node addition to applications, and it only takes one look at the comments in one of Yariv’s posts ( Erlang vs Scala ) to see there are a lot of opinions.

At this point I have to confess I can’t really comment with full knowledge on how something like Scala stacks up to Erlang in this specific scenario. What I do know is that Scala runs on the JVM, which is great from a stability perspective but may not be as stellar for massive concurrency because of the way JVM handles threading with real system threads. Much the same, the CLR from Microsoft uses real system threads, but has the ability to use something akin to green threads (reference?). Clearly using either of these has some great advantages, like access to Java libraries (though many argue this might make concurrency more difficult), so it’s not as cut and dry as Erlang > All.

Clouds on the Brain

However you choose to tackle it, the cloud is growing in popularity and importance when considering web applications. Looking to the future, even the most basic hosting plans may consist of on demand hardware for our disposal, and then it will really be up to you how you want to utilize the resources you have to better serve out your apps.

Let me know what you think in the comments!

Functional Programming is harder than Object Oriented Programming 12

I was mouthing off in #erlang last night about OOP and I wanted to summarize some of the conclusions that I came too about why object orientation has become so huge while functional programming has remained relatively unused by comparison.

First, it should be noted that I am by no means an erlang expert, I just started learning, but I’ve been programming plenty long enough to understand why object orientation has become as popular as it is. In fact maybe the title should be “Concurrency Oriented Programming is harder…”, or “Why Object Oriented Programming is more popular…”.

Objects map better to real life

Joe Armstrong’s book claims something to the effect of “we live in a concurrent world”, which is true, but learning to deal with that in the context of code execution is very difficult (with varying degrees depending on the language, this is one of erlang’s obvious strengths). When you’re sitting in CS 101 and they give you the mammal, dog, cat example:

it makes a lot of sense. Both the Dog and the Cat are mammals, and all those things that ALL mammals do/have (LiveBirth, Fur) should be done/had by both a dog and a cat, right? Right. This might get tougher to keep strait when you’re working with very abstract business objects but that’s rare, and otherwise object orientation is VERY INTUITIVE.

Human beings are born with the ability to find commonality between actions/objects and it maps well for programming. It’s how you learned to talk. Your mother said the same thing 15 times while pointing to the zucchini, so you noticed that the common elements were that green thing on the counter, the noise of the word zucchini issuing from your mother’s gob, and the shapes she made with her mouth to create said noise.

In short, object orientation opened computer programming to a broader audience. It gave people confidence that, if they could just determine the objects present for a given problem, they could eventually work out how they all fit together, and get them to do the things they want.

OOP has _definable_ elegance

I will be the first to say that functional programing languages can create amazingly elegant applications. They empower you to be clever with the tools provided such that you can write very complex code with relatively little typing. Saying that OOP languages have definable elegance doesn’t mean that FP languages don’t have elegance at all.

But, I have yet to find a blog, book, or article that defines best practice for FP in the same concrete terms that you hear when someone references OOP. Even simple things like, using interfaces as contracts for what a class will be expected to do/be, and leveraging polymorphism to perform operations on objects with a common parent, represent definable ways to improve code. “Oh I don’t have to write two methods to have a collection of Cats and Dogs perform a LiveBirth because I can just treat them as mammals”.

This has two effects that I can see:

  1. Teachers can point out mistakes to students, which makes teaching object orientation nice and easy.
  2. People can say, look how good my code is, and we have rules by which we can all evaluate the validity of their statement.

The first could be said of functional programming to an extent. For erlang, it might sound something like, “if you use a list comprehension there, it will be one line as opposed to a whole separate function”. So you can offer ways for people to do things that will be better, possibly more elegant, but not with the same clarity as telling someone “You’ve written two classes that are nearly the same here, with a lot of code duplication, there must be some parent object from which they can both be descendants”.

I think the second is the most important though. Just as human beings are very good at finding commonality, human beings LOVE to be right. Being able to say: “I’m right because of X, Y, and Z” is a huge shot for you ego, and if getting it right just means mapping objects to code, programmers are going to be happy.

Good programmers gravitate towards FP constructs

That one might piss someone off. Let me be clear though: that doesn’t mean that people who use object oriented languages are bad programmers. Not at all. It just means that the things the FP languages have and will let you do are awesome enough include in some OOP languages.

Take Ruby for example. Ruby’s popularity has exploded because good hackers love the language and have done crazy things with it (see Rails). And some of the things that hackers love most? lambdas, blocks, multiple assignment. Even C# has jumped on the lambda boat. These things make for elegant, _concise_ code, which is pleasing to the hacker’s eye.

At this point, you might ask yourself “Then why don’t all the best hackers just work with FP languages?”, and the answer is two fold. First, as I mentioned above, mass appeal. More people can work with Rails because Ruby is object oriented, and everyone wants to be a celebrity who’s identity can be discerned from an acronym consisting of 3 letters, so they will build their framework with OOP. Second, and most importantly, because some problems sets map well to objects. A lot, maybe even most, of them do.

But some don’t, such as massively concurrent programs.

I think the claim that erlang will be the next java/c#/ruby/anything doesn’t make much sense. Not everyone can use functional programming languages, and more importantly not everyone should. It depends on what you are trying to do. Take web frameworks like erlyweb. It looks to me like erlang might not be that great for the web, and even if it is pretty awesome, you’re going to be hard pressed to find people with the ability to learn it as easily as Ruby and its stack Rails.

Let me know what you think in the comments.

Developing for fun, some observations 8

[UPDATE]: Some really nice additions to the list here.

Since I graduated from college, I’ve sort of stuttered and started when it came to coding in my free time. I knew that I loved to problem solve, and I got great satisfaction out if that aspect of programming (its why I do it for a living), but that didn’t seem to be enough to keep me interested for more than a few weeks/months. I’d always get tired of it, and wonder how the people doing crazy things like hacking the Linux kernel kept at it. For years no less! What follows are a few observations on how to keep programming fun when you’re doing it in your free time.

  1. Small Triumphs - You’re rarely going to write the next big thing, or anything really meaningful in a single day’s work. The “great undertaking” is the basis of what the open source movement is today, but most of them started out extremely small (ie Linus cobbling together the first Linux kernel). I’ve found that setting very short term subgoals for your project that can be achieved in under a week, are important to continued interest and minimizing frustration, especially when you are first starting a project
  2. Self-useful - If you work on something that you are going to use day to day, you’re software will always be more feature complete and robust. One of my github projects you can see up there to the right (RyC) is a set of Ruby scripts and classes that makes unit testing C a tad easier. I don’t hack C, and though I do use Ruby a lot I have little or no interest in working on it anymore. At the very least, try and write something that you _could_ use day to day.
  3. Prioritize - Write whatever you need to put a useful piece of software out, then add on the frills later. This will let you release earlier, possibly get feedback and, if anyone is interested in your project, maybe even get help.
  4. Advice - I find myself afraid of asking questions for fear that someone else will steal my idea or think I’m an idiot, and this keeps me from heading to the an irc channel when I need help. The bottom line is, 99 percent of the people who come up with really cool ideas never finish them and most never even start, so if you need to divulge a little in the interest of getting the thing done, do it.
  5. The Wife/Husband - Keep the wife/husband happy. If he/she is happy you will be able to work on your project in peace. I tend to wait until my wife goes to bed to work on anything so I can concentrate. If you don’t have a wife, then you should be hacking ’till you are blue in the face, clamming glory in the name of open source, and telling us all about your exploits so we can live vicariously through you.

None of the above will be true for everyone, and the list is far from complete. I just hope that someone will find it useful. Happy hacking!

[EDIT]: second to last sentence.

delicious-user-top javascript 0

Github: delicious-user-top

So if you stopped by last week you saw that I hacked together the github-repos javascript plugin for my new forum, erlanguid, to pull a users github repo information and display it in their posts. It was so easy that I got kind of plugin happy and decided to do a few more for my forum. The latest pulls the users top links for a given tag or tags from Delicious.com. Here’s how to use it!

If you read the github-repos post this script works in the same way, but since we need more information than just the user name, in this case the tag(s), and because the delicious feed doesn’t return the username with its json data like github does, things got more interesting.

The first big change was adding the tag(s) to the id of the div the links would be added to. In the page, the html where the links will be inserted looks like this:

You’ll notice that the id has the users delicious id, and also the tag were looking to search for. In this case we want johndoe’s links tagged with erlang. It’s important to note that you can add tags with a plus. So if I wanted to find only those links that had been tagged as both erlang and mnesia it would look like this:

So once thats in the page, and you’ve included delicious-user-top.js in the head of your page, you’ll get the links for the user and tags specified.

The second big change was forced by delicious only passing an array of links back with no association to the user which we queried for. Understandable, but it made it much more difficult to target the correct divs on the page for a given user and tags.

To maintain the asynchronous nature of the loading and also make sure that the script could add the new links to multiple divs in the page with the same username and tags, I simply added a new method into the DOM that would call the DeliciousTop.DisplayLinks method with the right id and the callback data. After that was defined, I added the script element that made the remote resource call to delicious with the user specific method added before as the callback. When all was said and done, for our example the DOM would have looked something like this:

The only reason for this is to pass the “johndoe|erlang” string to the function so it can insert the data from the callback into the right divs. It looks like crazyness but is necessary for multiple places on the page.

As a result everything works just fine for multiple divs for the same user. Because the function name doesn’t include tags, the same user can’t have multiple divs with different tags in the same page. This could be changed by making different functions with each of the tags added to the function name, but its not necessary for my purposes.

Post in the comments if you have any questions, or send me a message on github.

UPDATE: requires jQuery 1.2.6

Adding Textile to happenings with RedCloth 0

This is why I love Rails:

RedCloth Addition

In the commit you’ll notice that there are two files that got changed. The output for the Textile, and adding the gem to the environment.rb. Other than that all I had to do was install the gem in both dev and production, and unpack it in production.

This is certainly a short post, but I have to say that when you’ve used Rails enough to know exactly what to do in a given situation, that “todo” ends up being a very light undertaking.

Make no mistake, Rails is the framework of the future.

Next Page »