10 ms·
> Meanwhile, Ruby is used primarily for web development. What? I just started learning Ruby, and I intend to do some sys-admin tasks also. Am I going down the
by jalan 13y ago
> Meanwhile, Ruby is used primarily for web development.
What? I just started learning Ruby, and I intend to do some sys-admin tasks also. Am I going down the wrong path?
I know Homebrew is using Ruby as base language, and doing pretty fine.
Is this misleading or what?
- barbs 13y agoPrimarily != exclusively
- mjhea0 13y agoThanks! :)
- zem 13y agoyou're not, ruby is an excellent sysadmin language. python has the edge for scientific computing, though, due to the larger base of people using it for that. also pygame is great.
- erichurkman 13y agoRuby can be used for sys-admin stuff, absolutely. Look at Chef.
- zdw 13y agoPuppet uses Ruby too. Ansible and SaltStack both use Python. Older systems frequently use Perl (for example, ticketing systems like RT or OTRS), or even older systems use Tcl. Sysadmin tools are a tossup, driven mainly by whatever the rest of the ecosystem uses.
- Stubb 13y ago> What? I just started learning Ruby, and I intend to do some sys-admin tasks also. Am I going down the wrong path? I don't think so. Ruby has for me replaced bash scripting along with sed, awk, and Perl. It's nice to do all these things with one consistent syntax. And be sure to check out Pry (http://pryrepl.org/ http://pryrepl.org/)! I'll give Python another look once v3 catches on.
- navyrain 13y agoRuby is the lingua franca of devops; it is an entirely sensible choice for that purpose.
- deleted 13y ago[deleted]
- pwang 13y agoThat's kind of a stretch. Bash is the only lingua franca of devops. Perl might be next, depending on the organization you're involved with. Then Python or Ruby might be next... hard to even figure out how to objectively measure which of the two is more popular in the "devops" space.
- panzi 13y agoI don't think there is something inherent to either language that makes it more or less suited to sys admin tasks. Python just happens to be used more often for this. Many Linux sys admin tools (GUI and non-GUI) are written in Python (PyQt/PyGTK). yum, HP printer tools, firewalld, the setup tools of many distributions, dtrace, iotop, anaconda, mercurial. Python is stricter and more explicit. Ruby has many convenience functions that I consider messy and some even dangerous. E.g. Ruby supports the same ` `-Syntax as the Unix shell, with all it's implications. So in Ruby you could do: output = `/some/app #{arg}` And in Python you would do this: import subprocess output = subprocess.Popen(["/some/app",arg],stdout=subprocess.PIPE).stdout.read() Yes, it's more to write but it's more powerful and you don't have code injection problems. It feels to me that Python encourages you to do the proper clean thing while Ruby tries to be very concise and quick. Also compare regular expressions. Ruby: if "foo" =~ /f(oo)/ puts $1 end Oh my god, it assigns a global(?)/magic variable as a side effect. Yes, there are other ways to do it and when I write Ruby code I am using these other ways, but when I see other peoples Ruby code its done like that. I do this: match = /f(oo)/.match("foo") if match puts match[1] end Python: import re match = re.match("f(oo)","foo") if match: print(match.group(1)) If you evaluate the regular expression more than once you should compile it: import re regex = re.compile("f(oo)") match = regex.match("foo") if match: print(match.group(1)) Again in Python you tend to write it the clean way. Of course it's possible to write non-clean Python code and clean Ruby code, but the culture behind the languages encourage different things. You will find a lot of Ruby libraries/frameworks that extend (monkey patch) standard types. While this is also possible in Python (for non-builtin/-binding types) it is usually not done. Look at JavaScript: Prototype monkey patched a lot of standard types and messed up a lot. jQuery learned from that and tries not to monkey patch anything. Another issue is string encodings. Note that what I write here applies to Python 3. It's a bit more complicated/less clean in Python 2. The idea in Python is that files/network streams etc. are binary data and thus somehow encoded. But you as a programmer don't care about encodings, you want to manipulate text (or sequences of unicode code points). So you read bytes and decode them into str(ing)s. After you are done processing the text you encode with a certain encoding again and write the bytes into the file/network stream. So there is the bytes (and bytearray) class that has a decode method and there is the str class that has an encode method. str objects are always valid unicode codepoint sequences. Encoding errors can only happen on decode/encode. In Ruby there are only Strings. These strings have an encoding attached. Binary data has the "encoding" ASCII-8BIT. You can force a wrong encoding onto a string which will cause an InvalidByteSequenceError at some later point. If you try to concatenate two String objects that have a different encoding you will get a CompatibilityError. You can only hope that all your DB drivers return proper UTF-8 strings in all cases. I was told even Perl does this better (like Python). Furthermore in Ruby strings are mutable, in Python they are immutable. This means if you get a string passed in Ruby and want to store it in a classes attribute and want to be sure it does not change under your but you have to make a copy. So you can clearly see what language I think is cleaner. I write Ruby code for work but when I write some shell script to automate some task/write some small GUI tool I use Python (and PyQt).
- matt__rose 13y agoyes, well, mostly. python has subprocess.Popen which is an awesome way to call out shell cmds, but I do most of my SA work in ruby. I just find it more pleasant to write.