Re: [LISA] Ruby
On 2012-06-03 at 22:27 -0500, Brandon Weaver wrote:
> I'm a new admin learning scripting, and Ruby has really been catching my
> eye so far. I've heard that most places still use Perl, and larger names
> like Google are Python based, how many places solidly use Ruby? How do
> larger companies regard Ruby?
>
> Between Rails and Metaprogramming I can see it as being a valuable tool.
Everyone who has gotten heavily invested in any major framework because
of hype has come to regret it. It doesn't matter which language it's
written in. The hype too often is coming from the Newly Converted, who
often don't know enough to be wincing at the shortcomings created by
someone who has ignored history, rather than learning and improving upon
it.
Each of those scripting languages has its own idioms and its own
favoured styles, which emphasise different aspects of how to write code.
In fact this applies to *any* programming language, not just those
labelled "scripting".
The most important thing to learn is how to teach yourself whatever you
need to know, and how to absorb knowledge. If you're only ever able to
perform what you can use a search engine to discover, then you can at
best only ever copy the work of others with no understanding, which
means you'll make mistakes. If you have enough background knowledge,
you'll be able to apply meaningful discretion and *assess*, *judge* and
where needed *fix* based on understanding. You can be the person others
turn to for help.
"Just in time knowledge" is unsieved data. Build a knowledge base of
your own, of things you know well, and you'll find yourself able to pick
up enough of whatever scripting language you encounter to get things
done.
Learn how programming languages work. Learn what OS facilities are
being made available and how they're being abstracted. Learn the
difference between a system call and a library call and how the system
calls affect what's fundamentally possible while the library calls
affect what's easy in the language using that library. Learn scalar vs
linear array vs dictionary vs set and learn O notation. Look a little
at what things like tries are and figure out how your OS implements the
routing and forwarding tables and matches are done.
Learn the details of a system at one level of abstraction deeper than
the level at which you routinely will use it. Learn different
programming language types. Procedural, functional, type-matching,
whatever.
Learn regular expressions. Learn what a state machine is. Learn about
callbacks and lambdas. Learn about the difference between code and data
and how security problems arise whenever people mix the two.
Then you'll be able to do things like go "oh, that's BeanShell embedded
in your Java programs? Let me learn enough to do ... *this*" and fix
some problem. "Oh, that software is written in O'Caml? I haven't
touched this sort of thing in years ... arrgh, but here, I've fixed this
glitch and now the software runs reliably on my system".
Bear in mind this:
"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
-- Brian W. Kernighan
Learn to recognise write-only languages. Learn how to use and when
*not* to use them. For instance, shell is useful, but full of dangerous
quirks. zsh is incredibly powerful and I'm happy to use it for my REPL
system interface, but when you start *using* that power, you quickly
discover that it's write-only. Here's a snippet which I preserved as an
example, written to let the tab-completion work with many binaries
produced at a former employer:
local -a flags
flags=( \
${${(M)${${(@f)"$( ${words[1]} 2>/dev/null --logtostderr \
--tab_completion_columns $COLUMNS --tab_completion_word=-- \
)"}## #}##--[^-]*}// #\[[^]]#\] #/[}\]
)
Seriously. That's not even the worst I've seen. Probably not the worst
I've written, just the worst where I've noticed after writing it and
blinked.
*Every* language has warts. Learn to appreciate the power, but if you
find yourself talking enthusiastically about how great the language is
to the point where anybody who isn't using it is ignorant/dumb/whatever,
then it's time to stop, take a deep breath, go do something without
using computers and re-ground yourself in reality.
If you read past this point, be prepared to be annoyed. I'm not
trolling, but I should probably get an asbestos suit as what I'm going
to say will annoy some people. Heck, I'll annoy ~everyone.
Shell: learn what the bug is in this line:
local temp_dir="$(mktemp -d foo.XXXXXXXX)" || die "mktemp failed"
Larry Wall has a great intuitive understanding of how humans learn and
think and parse and did great work in Perl which is often unappreciated
by detractors; he was also a sysadmin and understood how to make a
framework for maintainable systems; many of the current Perl maintainers
appear to lack that understanding.
Guido van Rossum has created an excellent language and the "batteries
included" idea was great. Until you found that no module could ever be
deprecated and replacement modules sometimes lacked the features needed
from an older module. urllib vs urllib2. Python3 fixes much of this,
but they went overboard with the puritanism and it took until 3.2 for
some of the nuked features to return and for things to settle down.
With 3.2, there's something solid to migrate to. Now if only there were
a really decent continuation mechanism.
Yukihiro Matsumoto did some great stuff with Ruby. The conventions
around methods ending ! and ? just cuts right through some of the older
arguments about the ways to design an API. It's unfortunate that a
cultural gap about humour and one of his early joking essays put off so
many western programmers I know. And then Rails came along and ignored
most of the good stuff and created a framework which makes it really
easy to quickly create something powerful. And unmaintainable.
And yet I've seen great software in Shell, Perl, Python, Ruby. I've
written acceptable software in all of them. I've patched software in
languages which I've forgotten about.
How? By learning the fundamentals.
-Phil
This archive was generated by a fusion of
Pipermail (Mailman edition) and
MHonArc.