Live data from Hacker News

How Ruby is beating Python in the battle for the Soul of System Administration

devopsanywhere.blogspot.com

41–47 of 47 posts

Re: How Ruby is beating Python in the battle for the Soul of System Administration

#41
post #3

Neither Python nor Ruby are best suited for one-liners that the author is emphasising. One liners are bash-fu or commandline-fu. Anything above 100 lines (just a figure from the article) is what Python or Ruby should be used for. Last 10 lines in a file? 'tail -10 filename.txt' Right tools for the right job. As to Python vs Ruby? I believe the argument isn't about the language (although I think Python is more 'sane'…

Not that you can't do this in python: python -c "print '\n'.join(open('LICENSE.txt','r').read().split('\n')[:-10])" But this is besides the point.

Your split and join seem redundnant, and open defaults to read-only.

  print open('whatever.file').readlines()[:-10]
But still, don't do that on any log too big to read into memory.

Re: How Ruby is beating Python in the battle for the Soul of System Administration

#42
post #30

I'm not persuaded that the arrow of causality has been drawn correctly here. I.e., it seems rather that Ruby has gained a high profile in system administration, not due to any inherent characteristics of the language or library, but because Puppet and subsequently Chef happened to be written by people who wanted to use Ruby. Based on TFA, this was a matter of taste. I can't, for example, see why it should particularl…

I fail to see how Perl-golf style conciseness is inherently more "productive" (particularly when it makes it harder to understand and maintain operationally important software). I'm not sure the author made a great case, but it does matter. Unix admins often think in terms of lines, because lines are the default unit of action. No matter how much planning and cfengining you do, there are still times when an admin mus…

I can get insanely concise one-liners out of C and shell, but that doesn't make those inherently more-productive languages.

I forget what bash does, but when I write a block of shell in zsh, it is saved as a 'line.' This is a tool issue, not an issue of language expressiveness.

If you can't write concise Python, maybe that's just because you aren't that comfortable with Python... that's a perfectly good reason not to use it but it isn't some sort of dramatic limiting case requiring all system administrators to use Ruby instead.

Re: How Ruby is beating Python in the battle for the Soul of System Administration

#43

The Python example is completely broken. It'd be something like: import os if 'vmware' in os.popen('dmidecode').upper(): print 'this is a vmware vm' else: print 'this is not a vmware vm' I like regexps as much as the next ex-Perl hacker, but sometimes a little string manipulation is a lot better.

The condition will always evaluate to False, a lower-case string can't be in a string that has been .uppper()ed. popen(...).lower() will work.

Re: How Ruby is beating Python in the battle for the Soul of System Administration

#44
post #30

Earlier quoted context omitted.

I fail to see how Perl-golf style conciseness is inherently more "productive" (particularly when it makes it harder to understand and maintain operationally important software). I'm not sure the author made a great case, but it does matter. Unix admins often think in terms of lines, because lines are the default unit of action. No matter how much planning and cfengining you do, there are still times when an admin mus…

I can get insanely concise one-liners out of C and shell, but that doesn't make those inherently more-productive languages. I forget what bash does, but when I write a block of shell in zsh, it is saved as a 'line.' This is a tool issue, not an issue of language expressiveness. If you can't write concise Python, maybe that's just because you aren't that comfortable with Python... that's a perfectly good reason not to…

I don't use Ruby at all, personally. I use Python and Bash almost exclusively. I use Puppet but am not a huge fan, and I certainly have no plans to switch to ruby. I mostly agree with your original point.

However, the CLI thing is a legitimate advantage in favor of Ruby and Perl. Python is just really annoying to use for system administration one-liners. A number of fundamental design choices that have a minimal impact on even the smallest .py files make 'python -c' cumbersome.

Specifically:

A number of common tasks available as syntax in Perl and Ruby are in libraries in python. In particular, you often need to import sys, os, re, and subprocess. Not a real issue writing scripts, but adds a lot of overhead to a single line.

You can't pass a DEDENT token to '-c', at least I haven't figured it out, meaning you can't use more than one loop or control structure. You can work around this to some extent using list comprehensions.

Python's string literal syntax is more limited. I have never had an issue with this writing scripts, however from the command line it can be annoyingly tricky to keep track of which quote characters are needed. Ruby and Perl both have non-conflicting options for notating string literals. In shell scripts, strings are the default literal and you only need to worry about keywords and special characters.

Another advantage of shell are list literals. (I don't have enough practice to know how Ruby and Perl fare in this regard).

Bash also has some extremely convenient list expansion syntax.

    for fqdn in {www,news}.ycombinator.com ; do echo $fqdn ; done

    python -c "import sys; [sys.stdout.write('%s\n' % fqdn) for fqdn in ['%s.ycombinator.com' % sd for sd in ['www', 'news']]]"
Obviously this particular example could technically be shorter, since I could use for-loop syntax (and in python 3+ print is a function). But I would have to arrange it like this if I needed another nested loop. If you wanted to perform some additional action on the names you might have to import yet another library.

Incidentally, C can be a useful admin tool if you know how to use it, but usually the compile-execute cycle makes it more cumbersome than it's worth for one-offs. A C compiler might not even be available on your production system.

Re: How Ruby is beating Python in the battle for the Soul of System Administration

#46
post #39
post #38

Earlier quoted context omitted.

I don't think this is true. Have you ever read the code of a bigger Perl distribution. For example Mojolicious. https://github.com/kraih/mojo While I also like other languages and for example have great fun using CoffeeScript for my current projects Perl is really good when it comes to describing what the code actually does. This is a benefit of "there is more than one way to do it". At the beginning t is hard to und…

Thank you for the links and the advice, but it is misplaced. I know and use Perl. I also dread having to do so. These two statements are related. "There's more than one way to do it" is, for me, a negative, at least in the Perl implementation of it; while there are cases where multiple ways to do the same thing is great (for example, C#'s foreach versus the IEnumerable extension method that takes a delegate/lambda),…

Just so you know, there is somewhat of a movement afoot in Perl these days. Many of us long term Perl programmers know well the dangers of TIMTOWTDI. So we have created TIMTOWTDI-BSCINABTE (pronounced TimToady Bicarbonate) and stands for "But Sometimes Consistency Is Not A Bad Thing Either". This has come specifically out of the Moose community and basically pushes to try and spread consistent best practices throughout the community.

I think the issue you encounter is a combination of isolation (the more involved you are in the community, the more you are exposed to best-practices and idiomatic Perl) and the quality of some of the older Perl documentation and books. In some of these older documents there was an emphasis put on "cleverness through TIMTOWTDI" which really had a damaging effect on some people (read: the people whose code you have inherited).

Perl is an extremely flexible language, which in the right hands can be very powerful. However, as Uncle Ben said, with great power comes great responsibility. I personally would rather my language require a little more self discipline from me 90% of the time, so that in the remaining 10% of the time I can hack some really crazy shit to get the job done.

Re: How Ruby is beating Python in the battle for the Soul of System Administration

#47
Ruby and Python break backward compatibility too often even with minor language version upgrade. It's harder to maintain working language version across servers than do real sysadmin tasks.

Perl rocks and robust to that.

See Perl equvalent to Ruby's Capistrano/Puppet/Chef.. or Python's Fabric/func..

Rex - http://rexify.org/

Post reply on HN