On 8 mar, 09:08, “planetthoughtful” [email protected]
wrote:
What I’m looking for:
To be honest, your list is rather simple so there’s going to be a lot
of languages that fit the bill.
As you asked in the Ruby list, and Perl/Python/Ruby were mentioned,
I’ll give you answers for them.
- A language that installs easily onto a WinXP machine, including any
libraries required to do the following things listed below as well.
Ruby has the One-click installer, which you can get from
www.rubyforge.org
(it’s usually at the top of the download list).
Perl and Python have ActiveState versions of the same.
They all use a a microsoft-like installer… with the benefits (easy
to install on machine), and the drawbacks (a pain to install on
hundreds of machines, without some replication tool).
- A language with solid and hopefully well-documented libraries for
connecting to at least MySQL and MSSQL. Being able to connect to
Microsoft Access via ODBC (or even better, natively) would be an extra
bonus.
Perl and Ruby are rather similar. Albeit they both can use that MySQL
backend directly (which mimics the MySQL api), you often use it a
module called DBI, which allows you to easily switch database
drivers. The DBI module is very well documented in Perl, not so well
in Ruby.
Both Ruby and Perl ship with MySQL backends by default in their
windows installers, buy MSSQL is probably something you’ll need to
install yourself. For Ruby:
http://wiki.rubyonrails.com/rails/pages/HowtoConnectToMicrosoftSQLServer
Also, Ruby has stuff like ActiveRecord (like CakePHP), which basically
shields you pretty much completely from writing any SQL, at the price
of performance.
Python has something akin to DBI called the Python DBI API, albeit,
imo, it is not quite as comprehensive or elegant (some people even use
pyperl to get to Perl’s dbi module). I don’t think python comes with
any database backends in their default installation.
- A language with a flexible array or array-like object. One of the
things I love about PHP is the ease with which an array can be
populated (eg “MyArray[] = ‘a new value’;” adds “a new value” as a new
item to the array MyArray).
Here’s the syntax for each:
Perl
push(@arr, $value); # as you can see, not OO. parenthesis optional.
length(@arr) # non-OO, cannot be overridden.
Python
arr.append(value) # OO, parenthesis NOT optional
len(arr) # non-OO, albeit it can be overridden
Ruby
arr << value # OO (even if it does not look like it)
arr.push(value) # same as above – parenthesis are optional.
arr.size # OO, can be overriden and aliased like
arr.length
arr += [value] # Ruby gets brownie points over python and perl
because it can do additions and intersections
arr & other # among arrays easily, too.
arr - other
- A language with strong Regular Expression abilities, and string
manipulation tools / methods.
Perl has the best (and oldest) regexp engine, albeit the latest Python
and Ruby engines are more or less on par. Perl’s syntax is pretty
simple and elegant, albeit since Perl also uses $, @, % and other
symbols for other constructs, it can also get somewhat confusing:
$str =~ /regex/; # match regex against str
sub($str, /regex/, ‘repl’);
print $1,“\n”; # print first grouped match
Perl has a bunch of global variables that get set as regexps are
executed. These contain last/previous matches, groups, etc.
Perl supports accessing variables within regexps.
Ruby1.8’s regexp engine is less powerful than Perl’s or Python’s as it
does not have backtracking, named groups or unicode (if you don’t know
what that is or care, ruby1.8’s regexp are perfect for you already).
Ruby1.9 uses a new regexp engine which is on par to Perl’s and
Python’s.
Ruby’s regexp engine syntax is also very elegant and similar to
Perl’s:
str =~ /regex/
str.sub(/regex/, ‘repl’)
m = str.match(/regex/)
puts $1 # first match
puts m[0] # first match
puts m[‘named’] # named match (ruby1.9 only)
As ruby does not use symbols as much as Perl, ruby’s regexps are a
little more readable. Also, some things that in Perl require extra
switches, Ruby’s parser can handle them directly (know when to compile
once the regexp for example). Ruby also has the same globals as perl,
but it can also mimic’s python’s way of working with regexps.
Ruby supports accessing variables within regexps like Perl and
arbitrary expressions, which is very elegant:
var = ‘hello’
r = /^#{var}/
obj = []
r = /^#{obj.size}/
Python2 (not 1.5) now has a good regexp engine on par with Perl, but
its syntax is a little more cumbersome, as it is not native to the
language:
import re # this is the regex module
re.compile(r"regex").match(str)
m = re.match(r"regex", str)
re.sub(r"regex", ‘repl’, str)
print m.group(0) # print first group
print m.groupdict(‘named’) # print named group
Annoyingly, regexps in python often require an additional r""
character to avoid some quotation rules to take over (it is legacy
from 1.5 python, mainly).
Python cannot interpolate variables or run expressions within a
regexp. You often need to do a printf() kind of thing, like:
var = ‘hello’
r = re.compile(r"%s" % var )
obj = []
r = re.compile(r"%s" % len(obj) )
So, would anyone be able to help me work out if Ruby is the language I
need?
Sure. It can do all you want.