More About Decentralized Media Types

February 11th, 2008  |  Published in HTTP, REST, standards  |  1 Comment  |  Bookmark on Pinboard.in

I figured the decentralized media types idea that Stefan Tilkov and I each wrote about recently couldn’t be all that simple. So, not surprisingly, it turns out that at least Mark Baker (and according to Mark, also Mark Nottingham (mnot) as well), Bill de hÓra, and James Snell don’t like it. When either Mark or Mark speaks on matters pertaining to the web, I listen; I’ve been around each of them long enough to know that when they aren’t sure whether something is a good idea, it’s definitely worthwhile to take the time to understand why. I don’t believe I’ve ever met Bill or James in person, but I read their blogs for a good reason, plus James just got his blue belt so I’d like to avoid getting on his bad side. :-)

I particularly like Stu Charlton’s opinion on the matter, though, in part because he acknowledges the tension between the needs of the Internet vs. those of intranets.

At the end of the day, I understand the various explanations for why decentralizing media types is not a good idea after all, and I agree with them. I was unaware that mnot had already tried to go down this path. I see this issue as another stop along the way to a more thorough understanding of REST, and bringing it up has gotten some good technical explanations out in the open, where perhaps more people can see them and learn from them. Thanks to those mentioned above for providing those explanations, and to Stefan for kicking off the discussion.

Decentralized Media Types

February 9th, 2008  |  Published in HTTP, REST, standards  |  Bookmark on Pinboard.in

In RESTful systems, media types define the formats of data exchanged between client and server. Standard media types are centrally registered and managed via the Internet Assigned Numbers Authority (IANA). If none of the registered IANA media types fits your application, you’re free to write up and submit a new one that does.

Less than one week ago I was wondering to myself why media types are centrally managed when the web typically prefers decentralization. I was therefore pleasantly surprised today when I read Stefan Tilkov’s posting on this very topic. The proposed solution he describes, from Sanjiva Weerawarana, Paul Fremantle, Jonathan Marsh, and James Clark, is pretty much in line with what I was thinking: register a new media type that has a URI parameter for identifying an actual data description. Very simple and yet potentially extremely effective.

I like this approach for several reasons beyond just the decentralization win. First, this allows us to gain experience with new media types before they’re standardized. Second, this augments rather than replaces the current IANA registration approach, and doesn’t break the existing IANA registration process in any way. Third, it doesn’t break or otherwise negatively impact any existing applications.

So, enough emailing and blogging about it — who’s going to write it and submit it to the IANA? I hereby offer to pitch in and help in whatever way I can.

Wiger on Erlang-style Concurrency

February 7th, 2008  |  Published in concurrency, erlang, HTTP, messaging  |  3 Comments  |  Bookmark on Pinboard.in

Since a number of people seem to be experimenting with adding Erlang-style concurrency to other languages, Ulf Wiger has written a nice explanation of what Erlang-style concurrency actually is. Definitely informative.

On a related note, I chuckled when I saw this posting from Robert Virding, who helped create Erlang, in the erlang-questions list about a month ago:

After reading the blogs about how good Erlang’s concurrency model is and how we just just made a super implementation of it in XXX I have been led to formulate Virding’s First Rule of Programming:

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

This is, of course, a mild travesty of Greenspun but I think it is fundamental enough to be my first rule, not the tenth.

I can understand where he’s coming from. When I see the kind of blog postings he’s referring to, I always wonder why they don’t just use Erlang itself instead of trying to reinvent it in another system whose design trade-offs are unlikely to be able to support it. Well, I guess it would make sense in the case where they’re specifically studying various implementations of concurrency, but other than that, I don’t get it.

On another related note, I found the comment below in another blog. It refers specifically to my own use of Erlang:

it’s [sic] be interesting to see how Steve mix [sic] Erlang and HTTP, since Erlang is asynchronous in nature and does not have any “resource” concept and HTTP’s sweet spots are just the opposite

That’s easy. If you want to experience HTTP as implemented in Erlang, just go to the Yaws website, which of course is powered by Yaws itself. As Ulf’s blog posting explains, Erlang message passing is asynchronous, but that really has nothing to do with Erlang’s ability to support protocols like HTTP. For example, when I was learning Erlang, given my CORBA background I wrote a subset of IIOP, and it was really quite easy. Furthermore, Erlang doesn’t need a “resource” concept to support HTTP. A resource in that context is, after all, ultimately just a chunk of code that processes incoming requests, and of course Erlang can do that.

If you want to know more, go pick up Joe Armstrong’s Erlang book — it’s quite excellent.

Static Languages: Rationalizations and Myths

February 5th, 2008  |  Published in dynamic languages, emacs-lisp, erlang, perl, python, Ruby  |  33 Comments  |  Bookmark on Pinboard.in

I see my old pal Bill is spreading dynamic language FUD again. I’m the “dynamic language evangelist colleague” to whom he sent the email he mentions.

First, I find it funny that he calls me a “dynamic language evangelist.” I’m really more of a multi-language evangelist, or as Ola Bini recently put it, a polyglot programmer (in fact much of Ola’s recent thread on this topic matches up well with what I said on the closing JAOO 2006 panel). This year marks my 20th year of using C++, for example, and I still use it every day, so that probably automatically disqualifies me from membership in any dynamic language clubs. But this year also marks my 20th year of using both Perl and emacs-lisp, so maybe there’s hope for me yet.

Bill gets irrationally upset when I tell him I write in five different languages every day. They are, in no particular order, Erlang, C++, Python, Perl, and emacs-lisp. I really like Ruby but unfortunately don’t get much chance to use it at the moment. I even have to delve into SQL every now and again. Apparently, this notion drives Bill crazy not only because I don’t use Java (though I’ve written my share of it in the past), but also because it means I can’t use an IDE, since no IDE can handle all of the above. Apparently, if you can’t use an IDE to automatically rename your methods for you every 10 minutes or so, you’re not a real programmer.

Bill’s posting, like his original email to me that sparked it, is yet another “we’ve got to put these dynamic language folks in their place” postings (read to the bottom of that link for the context). He basically says so himself. His posting is full of the usual misunderstandings, rumors, poor guesses, and misinformation.

Issue 1: Dynamic Language XXXX didn’t do well against Java in XXXX benchmark

According to Bill, glaring differences between languages in how they perform on benchmarks must be recognized. Yes, that’s true — if all languages performed equally for all tasks, then we wouldn’t need multiple languages. Unfortunately, monolingual developers like Bill don’t view it that way; instead, they view benchmarks as some sort of strange competition where you can try to build up your self-esteem by gloating over the benchmarks for which your one language looks good.

I asked Bill why anyone would choose a language not known for its number crunching capabilities and actually try to use it for real code requiring number-crunching, like calculations involving the Mandelbrot set. He didn’t answer.

In reality, we need multiple languages because there are so many trade-offs to make. One way to address the need to make trade-offs is to choose a general-purpose language like Java and hope that it’s good enough for whatever you have to work on. Another way, and the way I prefer, is to be adept at multiple languages so that you can use the right tool for the job and handle unforeseen requirements. When a monolingual developer runs into a task for which their one language is ill-suited, they typically either bend the problem to fit their language, or they just avoid solving it altogether. Hammer, meet nail. Either way, they’re out of luck, or actually, their customer is out of luck. We polyglots don’t have that problem.

Issue 2: Ruby VM cannot support kernel threads

This issue is already addressed in comments in Bill’s blog, where several people mention all the current work on Ruby internals. But I would add that someone who’s writing authoritatively about Ruby should at least do his homework and already know that this “burning” issue is actually not an issue. Bill mentioned both in his email to me and on his blog that even his beloved Java still needs work, citing the need for “typesafe closures to complement annotations,” “a standard, non-code generating way of adding behavior to annotations,” and “a structural syntax to make initialization easier.” I assume therefore that the fact that Ruby also needs work will not be held against it.

Dynamic languages like Ruby, Python, etc… are not typesafe/statically typed

This is where Bill gets into the IDE religion. When I told him I use five different languages every day and said that I don’t need an IDE, he got mad and called me a name. It wasn’t even a particularly imaginative name, so perhaps he could get his IDE to automatically rename that name for him to turn it into a better insult. I asked if he could recommend a good IDE that could adequately handle all those languages for me, but he didn’t answer.

I use emacs. I’ve used it since 1985. I used Eclipse over the past few years for my Java work, and I really had strong hopes for it for other languages, but it’s still too Java-centric, and my current work doesn’t involve Java anyway. I am highly productive with emacs, and I see no reason whatsoever to change.

Bill asks why we can’t have a dynamically statically typed language. We can; see for example Haskell, and go look at all of Erik Meijer’s work.

Lack of type safety doesn’t scale well to large teams

Prove it. This is pure conjecture, nothing more, nothing less. Scaling development has everything to do with the team members and how they work and work together. Saying that “my buddy Jason was on a team that had to put type names in their Python function names” is certainly not even close to being solid evidence of your claim, Bill. For that particular example, BTW, why not describe the typing expectations for a function in its docstring, thus making it easily accessible to actual human programmers from their interactive Python prompts? That’s way better than applying some weird brittle Hungarian notation convention.

Lack of static typing does not allow for reliable refactoring in modern IDEs

The contrived Ruby example that Bill uses to “prove” this is, well, contrived. Why would anyone write code like that or suddenly get the urge to rename init to init2? I’m no Ruby expert, but I’d probably rename the method and then stick a method_missing in there to catch any call instances I might have missed with my editor. I’m sure a stronger Ruby developer can suggest a better way. Either way, it’s really not a big deal, Bill. I’m sure I could get it done well within the timespan you waste on fantasy football every day. ;-)

In 20 years of writing some pretty large C++ systems, for example, I don’t really recall ever having to go and rename a whole bunch of functions across a codebase. I recently had to move some classes from one C++ namespace to another, but a few lines of elisp automatically fixed 3000+ files for me, all without breaking the build (and yes I’m aware of namespace aliasing, thanks).

I asked him if these magical modern IDEs that raise productivity and eliminate common errors also eliminate defects caused by missing or misunderstood requirements, missed use cases, or just plain ol’ bad programming. Again, no answer. The reason I asked this is that those are the bad bugs; syntactical errors are really the least of your worries. Even if the IDE spits out common idiom/pattern skeletons for you, it’s still quite possible to screw up the code logic, and neither the IDE nor the compiler is going to prevent that.

I asked Bill if he’s ever considered that Java IDEs are the way they are due to issues with the Java language itself that must be compensated for. Consider its verbosity, for example, which is why IDEs spit out those skeletons. I can’t remember if he called me a name for asking that, or if he just didn’t answer. Either way, I got no response.

Bill asks if we can’t just learn how to type, but isn’t it the other way around? Shouldn’t he be asking why he needs the IDE to type for him? Odd.

Considering how old Java is, it’s obvious that it’s taken quite a bit of time to get these IDEs to where they are today. I asked Bill if everyone should have to wait a long time, on the order of 10-15 years, before an IDE truly becomes valuable for a given language. No answer. Personally, I’d rather stick to my emacs and UNIX tools, with their infinite applicability and flexibility that can be used for development in pretty much any language, than wait around for someone else to give me a far less functional IDE that barely addresses only one language. But then again, if one language is all you got, then I guess you have no choice.

The rest of the myths Bill cites just circle back to the same weak IDE arguments again, so I’ll skip those, save for this one:

Software Engineers should use the best language for the job

Yes, this is true, unless you’re an elitist.

Like Bill, I’ve spent much of my career writing middleware. However, unlike Bill, I’m not happy to sit around thinking that C++ or Java is the best we can do. I wish I would have known about Erlang 10 years ago, for example, so I could have saved myself countless development hours and headaches. In hindsight, I wasted way too much time trying to build in C++ and Java what Erlang basically gives you for free. I have only my own ignorance to blame, but now I know better. Thankfully, I now work in a place that lets me apply the right language for the right job, and our productivity is significantly higher than any place else I’ve ever worked.

I told Bill that if he wanted to do benchmarking, he should go benchmark the Yaws web server, written in Erlang, against Apache or some Java web server. Needless to say, that would be far more realistic to a lot of developers than Mandelbrot calculations. His response was that he didn’t need to, because Apache would win. That kind of poor assumption is much like the mindset that led me to poorly reinvent half of Erlang in my years of middleware work. These days, though, if I saw this graph I’d be highly intrigued — and in fact, I was when I first saw it — so much so that I’d want to run my own tests to see if those claims were accurate. My own tests were smaller scale than what that graph shows, but the results were basically the same. I’ve rerun my own tests and some others as well, and I get the same results every time. So Bill, rather than guess and make assumptions, why not try it for yourself? Or are you afraid to find out that dynamic languages actually are quite useful?

The things I write about in this blog are based on significant hands-on experience. Unlike many developers, I’ve heavily used approaches and techniques from both sides of the fence, and based on all my experiences, I’d rather use dynamic languages than static ones. I have more success with them, and the systems I use them for turn out better. That’s not wishful thinking or fabrication, that’s simply the cold, hard, factual truth. I wonder, then, why Bill and others like him insist of trying to “cure” me and others like me of our successes?

If you don’t like dynamic languages, then don’t use them! Leave us alone and go back to your monolingual world, and maybe rename your methods again. You can even have my IDE, since I’m not using it, which should double your productivity yet again, right?

Ruby and WS

January 29th, 2008  |  Published in code generation, dynamic languages, productivity, Ruby, services, WS-*, WSDL  |  5 Comments  |  Bookmark on Pinboard.in

Via Stefan Tilkov: Assaf Arkin talks about his upcoming book, Ruby in Practice. I don’t know anything about the book, but it sounds interesting.

Assaf talks about having a nice Ruby interface for WS, and also talks about wrapping Websphere MQ with Ruby. It reminded me of some work I was doing about a year and a half ago, when I still worked for IONA: developing a Ruby wrapper for Artix. I left there before it ever saw the light of day, so I doubt anyone will ever see it, but it was pretty cool. It was implemented using only customer-visible C++ APIs, and it afforded at least an order of magnitude reduction in the number of lines of code required to get anything done. It used WSDL4R to interpret a WSDL definition at runtime and dynamically generate accessor functions for the service, i.e., there was no up-front static code generation. You could point the client at the service, and if the service supported access to its WSDL (typically via a ?wsdl query string added to the service URI), the client could download the WSDL and dynamically generate everything required to access that service. I wrote about how to develop such Ruby extensions in my Sep/Oct 2006 IC column.

I remember presenting an example of the system in an internal sales engineering meeting where the original C++ and Java code required 70-80 lines of code while the equivalent Ruby code was only 7 lines. It wasn’t 7 lines of obfuscated expert-only Ruby, either; it was quite easy to read and understand. The SEs, most of whom worked only in Java and C++, kept looking at it and scratching their heads. They’d say, “Hey, you forgot to do this!” and I’d say, no, that happens right here. And they’d say something similar about another required action, and the answer was always the same: no, it’s in there. Basically, Ruby allowed me to hide a bunch of crufty, verbose, uninteresting but required boilerplate and focus only on service interactions. Waaay nicer than the equivalent Java and C++, for sure.

On a related note, just prior to that project, I did some work with Apache CXF to develop a server-side JavaScript and E4X JAX-WS capability. Since I no longer work in the middleware or WS worlds, I haven’t kept track of that code, so I don’t know if CXF still supports it or not. But either way, given the fact that JRuby now exists, there’s no reason that someone couldn’t take that work and redo it in JRuby. It would be pretty straightforward.