peterlog

the web log of peter sabaini

  • Home
  • About
    • 0
      22 Jan 2012

      Puppet & Ruby

      • Edit
      • Delete
      • Tags
      • Autopost

      So I spent the last week in Amsterdam for training. Amsterdam is a great city, so it's unfortunate that I didn't have all that much time for exploration. Luckily I at least managed a small trip to the Rijksmuseum; while most of the museum is closed for restoration, they have a small selection with truly great pieces on display.

      Ijfafjjd

      Training was also very enjoyable however. Topic of the training was the IT automation toolkit Puppet, and, since Puppet is written in Ruby, also a little of that was covered. Mr Haugen from Puppetlabs did an excellent job as an instructor; with just the right mix of theory presentation and exercises (and in between answering lots of questions).

      I have a bit of a love/hate relationship with Puppet. I've been using Puppet before; it sure is a very useful tool but on the other hand... It does have some warts.  

      For one the terminology of the DSL. For someone who has done OO programming the word "class" carries very specifc meaning. Puppet also has classes, but the are almost entirely unlike those from OOP. For example, all Puppet classes are singletons and may not be instantiated more than once. Also, there is some inheritance but overriding parameters is not supported; so the advice is to avoid inheritance and use includes. Include is not at all like someone with a C (or Erlang) background might expect it to be; it's not a simple literal file include but actually a kind of import + instantiate function. And so on.

      Jbiebdfj

      On the other hand, I much like the declarative model and the fact that it is very open and extensible. For instance, configuration parameters need not be held in static files but may also reside in an external repository; all that is needed is a glue script to fetch said parameters.

      Also Puppets approach is refreshingly pragmatic; it's all about getting stuff done. One can easily see that there are actual sysadmins using this stuff in production. It has decent support for testing and dry runs, for example -- good to have if you're not that confident about a system change you're going to roll out to a few thousand hosts. 

      It actually reminded me a little bit of the earlier days of Zope2 -- lots of magic and little documenation; for someone who knows how to push the right buttons a lot can be done with little effort but to get there you have a not so friendly learning curve.

      Puppet is written in Ruby, and for many types of extensions you have to get down to the Ruby level.

      Bcejeddf

      I haven't done much with Ruby before, so I'd like to take up the opportuniy write up some thoughts about the language and platform. My reference here is mainly Python, a) because these languages are in a pretty similar niche and b) Python is what I know best.

      For this Python programmer, Ruby tends to feel a little "Perlish" from time to time. In cases where Python might choose to focus on "one right way" to do something, Ruby would rather provide several ways (in different flavors) to accomplish the same thing. This sometimes can be quite useful, sometimes rather confusing. For me, this makes Python more intuitively useful, but admittedly sometimes more verbose. 

      One of the Perlish features of Ruby that I quite like are built-in regular expressions. For Sysadmins who constantly have to wrangle output of other tools to their own end regular expressions are a must have.  While Python of course has an excellent library for RE's it is still not the same level of integration as a native datatype with accompanying operators etc. On the other hand Ruby has Perls habit of setting tons of special global variables for RE matches -- not trying to be dogmatic here but can we maybe just try to avoid automatic global vars? Please? People get hurt by that stuff! This, to be fair, is entirely possible because Ruby _also_ provides other ways of accessing these values, without resorting to globals.

      One of the Perlish things in Ruby that I wish they just had left out is the postfix conditional, ie. one can write "if x then foobar()" but also "foobar() if x". Larry Wall has stressed how that helps make Perl like writing English but in all honesty I'd like to have my software a little more regular than the English language with its abundance of corner cases and special rules for all kinds of occasions.

      Speaking of conditionals -- many things which would be statements in other languages are actually expressions in Ruby, ie. they have a value; also including if-conditions. Eg. this function would add 2 to numbers smaller than 23 (since functions return the value of their last expression):

             def foo(a)
                 if a < 23
                    a+2
                 else
                   a
                 end
             end

      I find having more expressions lets one focus more on the data than on the procedure of how to operate on it. Yay for expressions! 

      Ruby has a very easy way to parametrize methods with anonymous blocks of code. While this allows for some very higher-order / functional coding style (which I appreciate) I had the impression that feature tends to get somewhat overused (well at least from what I've seen in Puppet). Sometimes it felt as if people we're actively trying to avoid writing regular methods and instead resorting to fiddling with blobs of anonymous code to achieve the same thing. Still, good to have for functional programming.

      Ruby is more consistent in its OO compared to Python, eg. while Python provides a built-in "length()" function, in Ruby only values which actually have a length (ie. Arrays) provide a ".length()" method. Makes a lot more sense, in my opinion.

      By the way, you may call methods with or without parentheses in Ruby. Personally I prefer parentheses for calls, I find code easier to read that way, but that might also just be a matter of practice.

      As to concurrency, Ruby unfortunately has similar problems as Python. The only directly supported concurrency model is a threading one, and like Python Ruby has to serialize access to data through a global interpreter lock. This usually results in Ruby code not scaling up very well on CPU-bound tasks. On the other hand, if you are doing CPU-intensive tasks you might want to consider a C extension anyway; these are luckily quite easy to embed (there even is a library that lets you inline C code into Ruby).

      Iijgcbbj

      Moving away from the core language on to the runtime environment -- there's a lot of good and also some bad there. 

      First to the bad: the standard library is, at least compared to the Python equivalent, a pretty rough place. Many modules are sparsely documented or not at all, and for some of the modules I kinda
      wonder if anyone uses them.

      The good, of course, is the gem system, to the point that I'm thinking maybe gems are the reason the stdlib seems to be lacking in maintenance.

      Gems is Ruby's packaging format and application, and it handles everything a packaging system should -- installation, dependency management, querying, etc. Pythons packaging system(s) are, in comparison, a bit of a mess.

      There are a lot of gems available. Rubygems.org boasts a total of 33160 packages available, and >444 million downloads. While nothing can be infered about the quality and/or usefulness of the provided libraries (and while still below CPANs legendary scale), these are nevertheless some impressive numbers.

      All in all, I'm looking forward to doing more Puppet and Ruby. There's lots to discover!

      • views
      • Tweet
    • 0
      26 Sep 2011

      Learning Go

      • Edit
      • Delete
      • Tags
      • Autopost

      That is, Go the programming language, not the board game.

      Gopherport

      I've tremendously enjoyed learning Erlang some time back, and I've
      realized that besides the value the Erlang/OTP platform itself
      provided, learning a new computer programming language has all sorts
      of benefits in itself. So, I've since been more curious than ever
      about programming languages. Also, these are good times for language
      lovers: there are lots of interesting and powerful programming
      languages around!

      Especially Clojure had fascinated me, and I hope to be able to
      take a look at it further down the road. In the end, I went for Go out
      of practical reasons. My bread-and-butter language is Python, and a
      language closer to the metal (like Golang) would complement it better
      than the rather high-level Clojure. I wanted to experiment with
      distributed systems type stuff, and an efficient systems language
      would just fit the bill.

      I'm on vacation now for a few days, and while the main project for
      it will be spending time with family, I'll set aside some hours to
      dive deeper into Go. I have already read a bit about Go, and today
      Frank Müllers Go book arrived in the mail -- so for the most part I
      will work through that.

      • views
      • Tweet
    • 0
      25 Sep 2011

      To MVC or not MVC

      • Edit
      • Delete
      • Tags
      • Autopost

      Andrzej Krzywda opines that Ruby on Rails is not in fact modeled after
      the MVC pattern
      despite claims to the contrary. One could add that
      Rails is not the only web framework or -application which misuses the
      "MVC" tag. As Andrzej notes, the crux is that MVC requires the Model
      to notify the View about any data changes. Something which in
      classical web apps doesn't happen save for Websockets or similar
      "push" technologies.

      Indeed it seems that MVC has become some kind of marketing term, to
      the point that not being "MVC" in a way reflects negatively on the
      product in question.

      Despite this, there are architectural patterns that make a lot more
      sense for a web framework than MVC, which has its roots firmly in GUI
      applications. For instance, Martin Fowler describes some patterns that are much closer to the way real web applications work.

       

      • views
      • Tweet
    • 0
      29 Jul 2011

      Erlang Ghetto

      • Edit
      • Delete
      • Tags
      • Autopost

      I don't use Erlang much these days (can't use it at my job, not much free time for my own projects), but I follow Erlang mailing lists and blogs pretty closely. The people there are as a rule much smarter than me, so I can only benefit :-) Tony Arcieri, the creator of Reia, recently ranted about the shortcomings of Erlang, and some of the points he raises do have merit, and others not so much IMHO. There are also some good comments on the mailing list about that post here.

      Records Suck

      Yes they do. There are more dynamic data types available, but only as libraries, not as native datatypes. I miss the built-in hashmaps that used to be found only in the "scripting" world are now built into many modern languages.

      Erlang isn't general purpose

      Because Erlang only has immutable variables. Or so he argues. I find the argument not that compelling. Mnesia, the built-in database is quite easy to handle and well suited for small-to-medium datasets. For large (or "Big") data sets you want a specialized system anyway -- a relational database, a NoSQL system, whatever. Anyway, there are certainly things Erlang is suited for (distributed realiable systems eg.) and for some tasks it's not so great for (OS-level stuff, GUI-heavy stuff eg.). That's pretty much true of any language I'd say.

      The syntax is atrocious

      Well, one gets used to it. No, really. The syntax is a little unusual and sometimes just impractical -- for instance, the different expression terminators which make it impossible to copy/paste pieces of code verbatim or move lines around is just not that likeable. Other things just take a little getting used to and work reasonably well. So, while beautiful syntax may not be Erlangs strong suit, the syntax is certainly usable.

      The standard library is inconsistent, ugly, and riddled with legacy

      For me, this is the biggest practical impediment. I don't have photographic memory, and memorizing the varying naming conventions of different stdlib modules is just... annoying. As is the mapping of some functions to libraries and the language itself. Why is a function to compute an adler32 checksum a language built-in, but modules for list and dictionary handling banned to the stdlib? There are massive violations of the principle of least surprise there.

      Strings-as-lists suck

      Yes they do. Strings are just too important to handle them as a special case of lists. They are of course, it's just that they deserve some extra syntactic sugar on top.

      What doesn't suck

      So, there are definitely warts here. The good thing is, they are only that -- warts. As opposed to design flaws, these can (and are) remedied. In contrast, the things Erlang is good at -- easy and safe concurrency, reliability, and so on -- are really hard to solve, and require great effort on other platforms. Designing a program around concurrently running tasks that pass messages to each other has been nothing short of relevatory to me. Once you "get" it, it's just the most natural way to think about a problem. And the built-in infrastructure for detecting and handling failure is just excellent. This, for me, is an easy tradeoff: If I have to create software in the problem space that Erlang excels at, like most server software, especially if reliability is an issue, I gladly take the syntax warts, the uneven libraries et al. and gain a great deal of features that would otherwise be hard to get.

      • views
      • Tweet
    • 0
      27 Apr 2011

      Be sexy, don't scale

      • Edit
      • Delete
      • Tags
      • Autopost

      Mr Berkus delivers valuable advice on how to be sexy as a developer by not scaling.

      (via HighScalability)

       

      • views
      • Tweet
    • 0
      6 Feb 2011

      More dynamic Python imports

      • Edit
      • Delete
      • Tags
      • Autopost

      I like the idea of this — make Python imports more dynamic through an explicit mapper, as implemented by Exocet

      I’ve implemented plugin systems previously myself, and it’s not that hard in Python, but with Exocet its much cleaner (and with more features) than what I did.

      • views
      • Tweet
    • 0
      3 Jan 2011

      Meld, a visual diff

      • Edit
      • Delete
      • Tags
      • Autopost

      Just discovered a nice tool for visual diffing, meld

      Also integrates nicely with git via git difftool

      I’ve executed

      % git config --global diff.tool meld

      to make meld the default tool for git-difftool.

      • views
      • Tweet
    • 0
      23 Dec 2010

      21 Lines Spelling Corrector

      • Edit
      • Delete
      • Tags
      • Autopost

      Mr Norvig demonstrates a neat spelling corrector in 21 lines of clean Python. Good explanation of the statistics too, and an updated section with implementations in other languages.

      • views
      • Tweet
    • Search

    • Tags

      • linux
      • system
      • python
      • switzerland
      • photo
      • posterous
      • zug
      • database
      • android
      • erlang
      • kitteh
      • music
      • tool
      • couchdb
      • electronica
      • teaching
      • work
      • JavaScript
      • NoScript
      • animation
      • aquarium
      • austria
      • biking
      • bug
      • comic
      • conveniencetrumpssecurity
      • dns
      • ehealth
      • elga
      • emacs
      • emkuu
      • fun
      • gaming
      • gesundheitspolitik
      • golang
      • graphic novel
      • html5
      • industrial
      • java
      • latex
      • mail
      • messaging
      • microformats
      • mysql
      • oracle
      • perl
      • politics
      • postgresql
      • puppet
      • rant
      • restructuredtext
      • ruby
      • science
      • security
      • skype
      • styria
      • twisted
      • vintage
      • younggods
      • zeroconf
      • zope
    • Archive

      • 2012 (13)
        • May (2)
        • April (1)
        • March (2)
        • February (1)
        • January (7)
      • 2011 (29)
        • December (5)
        • September (4)
        • August (3)
        • July (1)
        • June (1)
        • April (4)
        • March (5)
        • February (1)
        • January (5)
      • 2010 (35)
        • December (6)
        • November (4)
        • October (3)
        • September (5)
        • August (5)
        • July (11)
        • June (1)
    • Obox Design
  • peterlog

    software, sysadmin, python, zope, erlang, linux, teh interwebs, cats, austria, switzerland

    18898 Views
  • Get Updates

    Follow this Space »
    You're following this Space (Edit)
    You're a contributor here (Edit)
    This is your Space (Edit)
    Follow by email »
    Get the latest updates in your email box automatically.
    Loading...
    Subscribe via RSS
    TwitterFacebookBuzzLinkedIn