Re: Scripting language for DBAs

From: Robert Klemme <shortcutter_at_googlemail.com>
Date: Mon, 16 Apr 2012 13:18:55 +0200
Message-ID: <9v2dgvFnmaU1_at_mid.individual.net>



On 16.04.2012 12:00, Noons wrote:
> Robert Klemme wrote,on my timestamp of 16/04/2012 5:26 PM:
>
>> On 16.04.2012 03:14, Noons wrote:
>
>> Why "too niche"? Are you referring to functionality, code base,
>> community or
>> what else?
>
> Niche because they were created for a subset of functionality of the net

Hmm... First of all Python, Ruby and Perl are general purpose programming languages. Perl is extremely strong in text processing but Ruby's regular expression engine is not far behind since 1.9.* version of the language. I cannot judge Python. What makes you say they were created for the net only / mostly?

> OO is useless for any quick database work.

It might depend on the overhead. I find it very convenient to create classes with a set of properties on a single line in Ruby:

Person = Struct.new :forename, :surname, :born

You can even add methods easily

Person = Struct.new :forename, :surname, :born do

   def age_days; (Date.today - born).to_i end end

I find myself often using a few self defined classes (and of course a lot of classes from the standard library) even in short ad hoc scripts.   Personally I find it very helpful to use proper OO abstractions of entities of the problem domain. I wouldn't script in Java though where the syntactic and other overhead is significantly higher.

Btw., another feature which makes Ruby code quick to write and easy to read is the feature that every method can accept an anonymous callback function which helps separating iteration from processing and makes iterations and generally visitor like things very concise.

users = [...] # an array
users.each {|pers| puts pers.surname if pers.age > 18}

Plus, with that block pattern resource cleanup is simple and cannot be forgotten:

File.foreach ".bash_history" do |line|

   puts line[0...10] # first 10 chars
end # implicit file close, even with exception

http://blog.rubybestpractices.com/posts/rklemme/001-Using_blocks_for_Robustness.html

OK, 'nuff advertising. ;-)

Kind regards

        robert

-- 
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/
Received on Mon Apr 16 2012 - 06:18:55 CDT

Original text of this message