RoR with Rust
10/13/2015 § Leave a comment
Mention the C programming language and the younger guns head for the hill and look around like they need a life preserver because the office is sinking. This effect flies in the face of the fact that most of the Web 2.0 (and newer) languages resemble C in all but the most trivial of ways.
C is easy to grasp, in my opinion, and simply makes sense. Its no great mystery to understand why new languages take their structure and syntax from it. If you want a language that completely departs from C then you have to go back to older languages like LISP and Ada. Ruby and its web application framework Rails are the few examples that are a complete departure from the C syntax paradigm. D is a great attempt at complete type safety with speed but you’ll starve as a D programmer.
I have a friend I’ve known since college who loves Forth, and he claims he uses it in his current position. He’s doing fine but I kind of imagine him locked in a basement typing in Forth code and giggling to himself.
Pascal was great, that was the first language I learned that I could do anything with, and in the days of 300 baud modems war diallers were a thing. I wrote a dandy one using whatever pascal compiler was in vogue at the time (we’re going back 30 years, I want to say it was a Borland product but I can’t remember).
Then there’s Python. Python is a truly interesting “new” (its at least 10 years old) tool. If you like Python but miss RoR’s ability to create a working website and nearly automatic connectivity to a data base with only a few commands give Web2py a try. Its based on Aaron Swartz’s web.py. Aaron Swartz‘s sad story is another tale of injustice for another time.
I once did work for a bar tap company converting a RoR embedded application to C. Yes, it was a complete RoR application that had to fit in less than 800K of memory. The application worked, but it was a complete disaster. Its VM barely fit in in the space given, and was constantly having problems trying to work in that confined space. Clearly, RoR is not applicable to every scenario,
Python has its issue as well. Using white space delimiters is a bit of a problem if you like your code to look a certain way. I worked on a python project with one dev who insisted on using Emacs as his IDE. I sort of admire that, having used it early on myself. Its a sort of swiss army knife of an editor, you can use it as an email client, a firewall control panel, a word processor, and a C IDE, just about any kind of desk top client for almost any systems process, especially if that process will read a socket. However, in this particular case the Python programmer would check out other dev’s code from source control, edit it, and the check it back in re-formatted by Emacs to something it liked better, occasionally breaking the code. A serious problem. But that said, I think Python one of the best attempts at write once run anywhere around.
While WORA is good, except in somewhat trivial cases, it doesn’t seem to be something that is truly workable. Sure, its in effect, python does indeed deliver WORA, Java, others, do achieve it with a fair degree of reliability. But customization and addressing hardware is pretty difficult to deliver in a neat package, and that’s 90 percent of the work, at least in the systems work that I do. In just about every case I’ve had to re-compile servlets for a Tomcat app, or re-work a python tool to for a particular scenario. Why not just cut to the chase and write the thing in C? You get performance and a tiny foot print in the bargain. Is C so scary that no one wants to do it for web apps? It would seem so. Any reason to avoid pointers and memory allocation seems the be the reasons. devs appear to want to avoid touching the bare metal if at all possible. Memory leaks are often cited as another reason, “…you have to constantly trace down memory leaks if use C. Run valgrind on tomcat some time and tell me about memory leaks.
So what’s the upshot? I dunno. I’ve noticed the number of ads asking for RoR engineers not quite as numerous as they were a couple of years ago. Languages seem very faddish. I’m really happy doing C/C++ programming. I hope I can keep doing it for some time to come. So far so good.
So writing Ruby GEM extensions with Rust is an interesting thing however. I was introduced to rust by a colleague who wanted to use rust gems to add extensions to read usb censors. I naturally thought we should just whip out a C GEM to do it, as did several others, but this guy was insistent. So I took a closer look at Rust. It does indeed have some nice features as these new languages tend to do. I was again impressed by its speed ranking in comparison to other languages. I typed in a little hello world program along and it was in my opinion even easier than a python program. It compiles down to a typical-looking Linux app as well; you can run it by simply pre-pending a dot-slash to the name of the file in its directory. Really pretty nifty. But here’s the bad part; the compiled program ballooned from 46 bytes to 570,075. Holy crap. A minimal application requires over half a meg of support code. I was hoping to see if writing the GEMs for that bar tap application in rust might have made a difference, I see that writing them in C as I did was the right way to go.
Ok, well, what was I expecting.
I don’t do a lot a RoR work, in fact none, I’m not exactly a fan, and I doubt I’ll be doing much in the future. But language unions have always been an interest of mine, its nice to explore.