A couple of questions from a Ruby neophyte

Hi All,

I’m thinking about learning a new scripting language, and I have a
couple of questions I’d like to ask the Ruby community to work out if
Ruby is the language I should be learning.

A little background: most of my usage will be based around writing
console scripts that connect either to MSSQL (ie SQL Server), MySQL or
Microsoft Access databases to perform imports / exports / selections
etc, or it will be around pulling apart text file reports to identify
valid records etc (and often then importing them into a DB). This will
all be on a WinXP machine.

I’m currently very conversant with PHP and VBScript and moderately
conversant with C#.

What I’m looking for:

  • A language that installs easily onto a WinXP machine, including any
    libraries required to do the following things listed below as well.

  • 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.

  • 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).

  • A language with strong Regular Expression abilities, and string
    manipulation tools / methods.

What I don’t (currently?) need:

  • Web support. I’m well aware of Ruby On Rails, and perhaps somewhere
    down the track I’ll build web applications in it, but for the moment
    I’m looking strictly for a console scripting language to handle
    repetitive yet complex database oriented tasks.

So, would anyone be able to help me work out if Ruby is the language I
need?

Many thanks to anyone who gives these questions some thought.

Much warmth,

pt

Before I start: I’ve done most of what you need to do successfully with
Ruby before, for a little while now, so the news is good :slight_smile:

planetthoughtful wrote:

valid records etc (and often then importing them into a DB). This will
all be on a WinXP machine.
I’ve handled MySQL and Access connectivity before (MySQL much more than
Access), and they’re both easy to get working. MySQL has a native
driver, and you can get to Access via ODBC. I assume that MSSQL will be
similarly convenient, but I haven’t used it myself.

I’m currently very conversant with PHP and VBScript and moderately
conversant with C#.

What I’m looking for:

  • A language that installs easily onto a WinXP machine, including any
    libraries required to do the following things listed below as well.
    Yes. The O.-Click-Installer (if you haven’t already found it) takes
    care of this.
  • 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.
    See above.
  • 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).
    Ruby’s arrays aren’t quite as feature-packed as PHP’s arrays, which are
    more like mutant hashes with strange super-powers. A Ruby array is
    created like this:

arr = [‘a’, 2.0, Object.new]

and are addressed only by index:

arr[0] = ‘b’

and appended to like this:

arr << ‘c’

If you want non-numeric keys, we’ve got hashes, which work like this:

hsh = {‘a’ => ‘foo’, 1 => ‘bar’, Object.new => ‘qux’}

addressed (and also assigned to) like this:

hsh[‘a’] = ‘fob’

Unlike PHP’s arrays, Ruby’s hashes don’t preserve order, but there are
libraries around to do that if you need it.

  • A language with strong Regular Expression abilities, and string
    manipulation tools / methods.
    Yup. Better than PHP’s, in my opinion.

So, would anyone be able to help me work out if Ruby is the language I
need?
I guess the thing to do would be to find a simple task you need to do,
and actually try it out, and see how it feels - and check back here if
you need help. That’s how I got hooked :slight_smile:

I think you stumbled on the right language.

Ruby arrays are very powerful, especially in the ways in which they
can be manipulated.

Do try :slight_smile:

Also, check out the RubyMentor project:
http://ruby-vpi.rubyforge.org/doc/images/ruby/

Aur

I mean http://rubymentor.rubyforge.org/

On Thu, Mar 08, 2007 at 09:27:01PM +0900, Alex Y. wrote:

  • 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).
    Ruby’s arrays aren’t quite as feature-packed as PHP’s arrays, which are
    more like mutant hashes with strange super-powers. A Ruby array is
    created like this:

The only quibble I have with your post is the above characterization of
PHP’s array variables. It’s more accurate, I think, to say that by
failing to more carefully separate normal arrays and associative arrays
(hashes) from each other, PHP ends up merely pretending to have two
array types while in fact it only has one – and it’s pretty broken in
some annoying ways. The problems with PHP arrays are mostly in
secondary effects, such that the way they’re implemented imposes
limitations on the language as a whole, even though looking at the
arrays in a vacuum they don’t seem terribly broken at first glance.

PHP handling of arrays isn’t really something I’ve put too much thought
into analyzing, so I’m afraid I can’t come up with a succinct
description of my objections to how they work just yet, but suffice to
say that despite the atrocious syntactic gyrations needed to deal with
complex data structures in Perl thanks to the list-flattening problem I
still prefer working with complex data structures in Perl over working
with them in PHP. I think your uses of the terms “mutant” and “strange”
are appropriate to describing PHP arrays, but “super-powers” is a bit
less so, and “feature-packed” is only useful to describe PHP arrays
where “feature” is contrasted with “useful functionality”.

Because of its design – and the way arrays work is a decent
demonstration of this fact – PHP’s usefulness as you get beyond simple
templating development drops off significantly. The more complex the
language gets, the more acrobatic your work-arounds must become.

arr << ‘c’

This is a beautiful example of where Ruby handles arrays better than PHP
handles them. Doing it the PHP way:

$arr = ‘c’

. . . is confusing and limiting. It hinders code readability and
maintainability, and restricts the potential uses of the assignment
operator outside of appending values to an array by essentially
overloading the operator haphazardly.

  • A language with strong Regular Expression abilities, and string
    manipulation tools / methods.
    Yup. Better than PHP’s, in my opinion.

Far, far better than PHP’s. In the quartet of commonly cited web
scripting languages (Perl, PHP, Python, and Ruby), PHP’s regular
expression handling is by far the worst. It’s kludgy, inconsistent, and
unwieldy. I try to avoid it. I don’t like Python’s much either, but
it’s a darn sight better than PHP’s.

I think I’ve been spoiled by working primarily with Perl regexen. PHP’s
regex handling is actually better than that of probably 90% of languages
that have regexen at all. I just think you need to be in about the 98th
percentile before you get to the languages that actually have good
regex support, and Ruby is definitely in that category.

So, would anyone be able to help me work out if Ruby is the language I
need?
I guess the thing to do would be to find a simple task you need to do,
and actually try it out, and see how it feels - and check back here if
you need help. That’s how I got hooked :slight_smile:

That’s a pretty good take on it.

The languages I’d suggest, off the top of my head, for the tasks
mentioned here include:

Perl
Python
Ruby

Each has its benefits and detriments, of course. I personally am not a
fan of Python, but it’s still a great language in (most of) the ways
that matter. Ruby’s my favorite, by a long shot, for OOP. Perl may
provide the most comfortable syntax for people who like a unixlike
environment (including me). All three of them handle the needs outlined
in the original post of this thread admirably.

Chad P. wrote:

In the quartet of commonly cited web
scripting languages (Perl, PHP, Python, and Ruby), PHP’s regular
expression handling is by far the worst. It’s kludgy, inconsistent, and
unwieldy. I try to avoid it. I don’t like Python’s much either, but
it’s a darn sight better than PHP’s.

It seems like regular expressions are slightly different from language
to language, but not so much so that it is much of a problem. Although,
if you are used to using advanced features like negative look behinds,
and they aren’t available in the language you are coding in, I guess
that would be frustrating. What deficiencies are there in Python’s
regex support?

I think I’ve been spoiled by working primarily with Perl regexen. PHP’s
regex handling is actually better than that of probably 90% of languages
that have regexen at all. I just think you need to be in about the 98th
percentile before you get to the languages that actually have good
regex support, and Ruby is definitely in that category.

So, would anyone be able to help me work out if Ruby is the language I
need?
I guess the thing to do would be to find a simple task you need to do,
and actually try it out, and see how it feels - and check back here if
you need help. That’s how I got hooked :slight_smile:

That’s a pretty good take on it.

The languages I’d suggest, off the top of my head, for the tasks
mentioned here include:

Perl
Python
Ruby

Each has its benefits and detriments, of course. I personally am not a
fan of Python, but it’s still a great language in (most of) the ways
that matter. Ruby’s my favorite, by a long shot, for OOP. Perl may
provide the most comfortable syntax for people who like a unixlike
environment (including me). All three of them handle the needs outlined
in the original post of this thread admirably.

I’ve been looking at Ruby and Python this week, and I am drawn more to
Python. I went through the “Ruby in 20 minutes tutorial” at the Ruby
website here:

http://www.ruby-lang.org/en/

and the syntax is not that appealing to me. I also started reading the
book “Dive into Python”, which targets experienced programmers moving to
Python, and which is also available for free download at the author’s
web site:

http://www.diveintopython.org/

It’s given a 5 star rating in the python book reviews here(click on the
book names for the full reviews):

http://www.awaretek.com/book.html

How great is that?! A free 5 star rated programming book? It has a
unique format: the author starts each section with a few lines of some
indecipherable code, and then spends the rest of the section introducing
the concepts and language features that make the code crystal clear by
the end. The first two chapters are definitely worth reading, and they
introduce Python’s data structures: arrays(called “lists”),
dictionaries("associative arrays, i.e. arrays with non numeric index
values), and tuples(immutable arrays).

The poster might be interested in a quick look at a “python in 10
minutes tutorial”:

http://www.poromenos.org/tutorials/python

Anyway, I was wondering if you could give some further insights into why
you prefer Ruby and don’t like Python?

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.

On Sat, Mar 10, 2007 at 12:23:04PM +0900, 7stud 7stud wrote:

and they aren’t available in the language you are coding in, I guess
that would be frustrating. What deficiencies are there in Python’s
regex support?

If you’ve ever noticed the way OOP characteristics look bolted-on in
Perl, you might understand how regex support looks bolted-on in Python.
For one thing, regex support is provided only through a library, rather
than as part of the core language – in other words, it really is
bolted on.

It’s better than Java’s regex support. In fact, it may be in the top
half-dozen languages for regex support, but after extensive use of
Perl’s it feels half-baked. So far (which isn’t too far yet), Ruby’s
regex support is a very close second to Perl’s, in my opinion. In fact,
there are a couple things I think Ruby does better.

Each has its benefits and detriments, of course. I personally am not a
http://www.ruby-lang.org/en/

and the syntax is not that appealing to me. I also started reading the
book “Dive into Python”, which targets experienced programmers moving to
Python, and which is also available for free download at the author’s
web site:

http://www.diveintopython.org/

You might want to judge Ruby syntax on something other than a
demonstration of irb.

One of the problems I have with Python’s syntax is that it always looks
unfinished, somehow, to me. I realize that the footnote-like
construction of Python source code might be more appealing to some
people, but not to me. The way things look in irb examples isn’t really
representative of Ruby code in general, though.

the end. The first two chapters are definitely worth reading, and they
introduce Python’s data structures: arrays(called “lists”),
dictionaries("associative arrays, i.e. arrays with non numeric index
values), and tuples(immutable arrays).

There’s a quality Ruby book for just about every writing style out
there. Between Programming Ruby, Learning to Program, Everyday
Scripting, The Ruby Way, Why’s (poignant) Guide, and half a dozen other
notable works, each written in a different style so that they don’t tend
to be redundant, there isn’t much ground left uncovered. Shop around a
little, and you can probably find what you need – if what you need
involves Ruby. Just stay away from Mr. Neighborly’s Humble Little Ruby
Book. In my opinion, it’s organized exceedingly well to get a beginner
started, but written just as poorly as the organization of it was done
well.

Of those, early versions of Programming Ruby and Learning to Program, as
well as the only edition of Why’s (poignant) Guide (and the Humble
Little Ruby Book for that matter), are available for free online.

The poster might be interested in a quick look at a “python in 10
minutes tutorial”:

http://www.poromenos.org/tutorials/python

Anyway, I was wondering if you could give some further insights into why
you prefer Ruby and don’t like Python?

I’ve done a little of that. I could explain more if you like, but it’d
be a short email – I spent a fair bit of time giving it a good look,
decided I didn’t like what I found, and set it aside. I then proceeded
to forget most of what I knew, so I’m not sure I’d even remember the
specifics so well. I mostly just remember that I prefer other
languages, I suspect.

. . . though I’ll probably come back to it and really learn Python at
some point in the distant future. You know, when I’m done with Ruby,
UCBLogo, Objective Caml, Objective C, Common Lisp, Scheme, Haskell, Perl
6, and refamiliarizing myself with C. I’m pretty sure refamiliarizing
myself with Java comes after Python, though.

Unfortunately, the realities of the work world will probably result in
learning even more PHP before I get to Python, too. Ew. On the other
hand, as I learn about Rails, I find that if at all possible I’m far
better off if I can convince any clients that Rails is the way to go
than to go with PHP, all else being equal.

(Brief anecdote, re my happiness with Rails:
I followed along with the text in Agile Web D. with Rails, and
found myself thinking “Woah, this is talking like I already have a
database set up, but I don’t remember anything about that.” I went
back, read between the lines a bit, and realized that creating database
tables is so absurdly easy in Rails that I’d already done so and didn’t
even realize it. I mean, really. So easy, it’s scary.)

gga [email protected] wrote:

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).

Don’t understand the difference here. Anyway the official Python
distribution has an installer of its own:
http://www.python.org/ftp/python/2.5/python-2.5.msi
http://www.python.org/ftp/python/2.5/python-2.5.ia64.msi
http://www.python.org/ftp/python/2.5/python-2.5.amd64.msi

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

For the record, with Python you can connect with mysqldb-python

Also, Ruby has stuff like ActiveRecord (like CakePHP), which basically
shields you pretty much completely from writing any SQL, at the price
of performance.

Take a look at SQLAlchemy for your Python stuff
http://www.sqlalchemy.org/

It’s really good and follow a rather different approach than AR

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.

The correct name is “DB API” which is an API dictating how interfaces
for various DBs should be so ideally you can change the underline API
and don’t change your business layer.

Python does ship with database backends. There’s the SQLite 3 backend
from the 2.5 version and there’s support for Unix DBM from day one I
think and Berkeley DB since ages.

Python

arr.append(value) # OO, parenthesis NOT optional
len(arr) # non-OO, albeit it can be overridden

There’s a bit of misunderstading of what’s called OOP in regard of
“message(object)” or “object.message” but I don’t want to start a
religious war here. Suffice to say that arr or an object who wants to
mimic that behavior must implement a len method so I don’t really
understand why that’s not OOP. Smalltalk does use a similar syntax and I
will not be the one stating that ST is not OO :wink:

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

You can use set() in Python for such insiemistic operation.

HTH

all of the languages you’re looking at are available for WinXP.
toy with each one and see which one strikes you as feeling right.
They can do pretty much the same things. But every language has
things it is better for. You don’t have to use just one. Just use one
you like or that meets your needs. They’re tools, not religions.
But that said, at some point if you’re seriously wanting to learn
these things, understand they were all originally created in C on
some form of Unix/Linux, so you couldn’t hurt yourself by dabbling in
C and definitely could learn a lot by learning to use the command
line in a *nix system and learning the *nix style of directories and
stuff. It makes a lot of languages make more sense. Seems like a tall
order, but you won’t regret it. Download Ubuntu or Kubuntu and
install it to a partition or external hard drive. (or get a Mac and
make it all easier on yourself)

Chad P. [email protected] wrote:

If you’ve ever noticed the way OOP characteristics look bolted-on in
Perl, you might understand how regex support looks bolted-on in Python.
For one thing, regex support is provided only through a library, rather
than as part of the core language – in other words, it really is
bolted on.

That’s maybe a deficiency in language design but I don’t think the
Python’s regex support is worse because of that. The ‘re’ module
http://docs.python.org/lib/module-re.html is very comprehensive and
it’s object oriented. The matching objects are objects indeed. Ruby
does have regexp support builtin but hey, there must be some differences
between the languages or we won’t be here to talk about those :slight_smile:

It’s better than Java’s regex support. In fact, it may be in the top
half-dozen languages for regex support, but after extensive use of
Perl’s it feels half-baked. So far (which isn’t too far yet), Ruby’s
regex support is a very close second to Perl’s, in my opinion. In fact,
there are a couple things I think Ruby does better.

Never been a Perlista so I can’t really judge but I do like the builtin
Ruby support for regexp and I don’t dislike the Python’s one (being
mostly a Pythonista myself) so I guess I’m caught up in the middle.

You might want to judge Ruby syntax on something other than a
demonstration of irb.

I agree. My first taste of Ruby syntax was not really that good but
after a couple of more bites I really enjoyed the meal and there are
cases where I find Ruby to cleaner than Python.

On Sat, Mar 10, 2007 at 12:23:04PM +0900, 7stud 7stud wrote:

http://www.diveintopython.org/

It’s given a 5 star rating in the python book reviews here(click on the
book names for the full reviews):

http://www.awaretek.com/book.html

How great is that?! A free 5 star rated programming book?

I learned through “Programming Ruby”, a.k.a. the venerable “Pickaxe”
book,
which suited my needs as an experienced programmer well. The 1st edition
is
still free to read on-line: http://www.rubycentral.com/book/

If you like it, and don’t want to get a real paper book (or give up the
shelf space) then the 2nd edition is available as a pay-for PDF
download.

It has a
unique format: the author starts each section with a few lines of some
indecipherable code, and then spends the rest of the section introducing
the concepts and language features that make the code crystal clear by
the end.

I never found any of the examples in Programming Ruby cryptic; most of
it
was clear from day one. Once I’d got my head around ‘yield’ I was hooked
:slight_smile:

Regards,

Brian.

On Sun, Mar 11, 2007 at 02:32:13AM +0900, M. Edward (Ed) Borasky wrote:

This is probably a FAQ, but just how different are Perl and Ruby regex
capabilities? I’m not a heavy regex user by any stretch of the
imagination. I do the basic stuff that will work anywhere (original
“vi”, “grep”, “sed”, “awk”) so Perl and Ruby are overkill for me.

I don’t know if all the differences are documented anywhere, but the one
which bit me was that ^ and $ do not match only start and end of string,
but
also start and end of line within a string.

So if you want to safely validate an entire string against a pattern,
use
/\A…\z/
not
/^…$/

The regexp modifiers are different too. If I remember rightly, Ruby /…/
acts like Perl /…/m. And if you write /…/m in Ruby, it’s like Perl
/…/ms

(or it could be the other way round :slight_smile:

Regards,

Brian.

On Sat, Mar 10, 2007 at 09:15:05PM +0900, Lawrence O. wrote:

it’s object oriented. The matching objects are objects indeed. Ruby
does have regexp support builtin but hey, there must be some differences
between the languages or we won’t be here to talk about those :slight_smile:

It may not be worse internally, but it’s more annoying to use – and
really, the important bit for language design is how we end up having to
use it. The principles of OOP actually support me in this: I shouldn’t
care about the internal workings of Python’s regex engine as much as the
interface through which I use it. If the interface sucks, it sucks; if
the interface is good, it’s good.

You might want to judge Ruby syntax on something other than a
demonstration of irb.

I agree. My first taste of Ruby syntax was not really that good but
after a couple of more bites I really enjoyed the meal and there are
cases where I find Ruby to cleaner than Python.

I’ve come to believe that Ruby and Python probably have equivalently
clean, elegant syntax – but one or the other may look more or less
clean and elegant, depending on personal taste, and depending on the
specific bit of code you’re writing. Overall, I find Ruby more readable
than Python, but then I find Python’s reliance on whitespace to define
blocks (in the generic, non-Ruby sense of the term “blocks”) of code
somewhat less conducive to readability than the way Ruby lends itself to
being written. It’s probably just a personal thing.

Chad P. wrote:

So far (which isn’t too far yet), Ruby’s
regex support is a very close second to Perl’s, in my opinion. In fact,
there are a couple things I think Ruby does better.

This is probably a FAQ, but just how different are Perl and Ruby regex
capabilities? I’m not a heavy regex user by any stretch of the
imagination. I do the basic stuff that will work anywhere (original
“vi”, “grep”, “sed”, “awk”) so Perl and Ruby are overkill for me.

. . . though I’ll probably come back to it and really learn Python at
some point in the distant future. You know, when I’m done with Ruby,
UCBLogo, Objective Caml, Objective C, Common Lisp, Scheme, Haskell, Perl
6, and refamiliarizing myself with C. I’m pretty sure refamiliarizing
myself with Java comes after Python, though.

Awww … you left off Forth :wink: It was an accident, I trust. :wink:


M. Edward (Ed) Borasky, FBG, AB, PTA, PGS, MS, MNLP, NST, ACMC§
http://borasky-research.blogspot.com/

If God had meant for carrots to be eaten cooked, He would have given
rabbits fire.

On Sun, Mar 11, 2007 at 02:32:13AM +0900, M. Edward (Ed) Borasky wrote:

Chad P. wrote:

So far (which isn’t too far yet), Ruby’s
regex support is a very close second to Perl’s, in my opinion. In fact,
there are a couple things I think Ruby does better.

This is probably a FAQ, but just how different are Perl and Ruby regex
capabilities? I’m not a heavy regex user by any stretch of the
imagination. I do the basic stuff that will work anywhere (original
“vi”, “grep”, “sed”, “awk”) so Perl and Ruby are overkill for me.

For the most part, they’re pretty similar. There are a few differences
that can trip you up, though – for instance, in Ruby this works for
matching either foo or bar:

/foo|bar/

. . . whereas in Perl you’d need to do this:

/(foo|bar)/

To be really correct, unless you wanted to capture the match in a
variable, you’d do this in Perl:

/(?:foo|bar)/

. . . since without the “?:” you would get the match of “foo|bar” stored
in the $1 variable. Not a big deal normally, but if you’re iterating
over a list of thousands, and you don’t need the variable captures, but
performance is important, unneeded capture of matches in variables might
create a performance hit.

Also, Perl has nothing that looks like this:

string.gsub(/foo/, ‘bar’)

Instead, you’d just do this:

string =~ s/foo/bar/g;

. . . though I’ll probably come back to it and really learn Python at
some point in the distant future. You know, when I’m done with Ruby,
UCBLogo, Objective Caml, Objective C, Common Lisp, Scheme, Haskell, Perl
6, and refamiliarizing myself with C. I’m pretty sure refamiliarizing
myself with Java comes after Python, though.

Awww … you left off Forth :wink: It was an accident, I trust. :wink:

Umm . . . sure.

Truth be told, Forth hasn’t really made it onto my radar. On the other
hand, if it makes you feel better, you might just assume that Forth is
one of the languages I already know, so that it didn’t need to be
mentioned.

On Sun, Mar 11, 2007 at 04:42:19AM +0900, Chad P. wrote:

. . . whereas in Perl you’d need to do this:

/(foo|bar)/

Really?

$ perl -e ‘$_ = “abcfoodef”; print “match!\n” if /foo|bar/’
match!
$ perl -v | head -3

This is perl, v5.8.7 built for i486-linux-gnu-thread-multi
(with 1 registered patch, see perl -V for more detail)

On Sun, Mar 11, 2007 at 05:17:24AM +0900, Brian C. wrote:

/foo|bar/

This is perl, v5.8.7 built for i486-linux-gnu-thread-multi
(with 1 registered patch, see perl -V for more detail)

Wow. All this time, I thought the parentheses were necessary.

Funny.

Thanks for disabusing me of that notion.

For what’s its worth I think Ruby is the way to go. It sounds like
you might be using vbscript to access some Windows specific
resources. For my part about a year ago I switched away from VBscript
because I wanted a more portable language. After looking around I
chose Ruby I found the switch from vbscript fairly painless and
straight forward. I’ve used win32ole to access AciveDirectory
resources. I’ve also used the DBI module to connect to MSSQL and
while as has already been said DBI not the best documented it was
pretty simple even for a newbie like myself. I think if you gave Ruby
a try yo umight be pleasantly surprised by what you find.

CParticle

On Mar 8, 7:08 am, “planetthoughtful” [email protected]

On Mar 11, 9:18 am, “CParticle” [email protected] wrote:

For what’s its worth I think Ruby is the way to go. It sounds like
you might be using vbscript to access some Windows specific
resources. For my part about a year ago I switched away from VBscript
because I wanted a more portable language. After looking around I
chose Ruby I found the switch from vbscript fairly painless and
straight forward. I’ve used win32ole to access AciveDirectory
resources. I’ve also used the DBI module to connect to MSSQL and
while as has already been said DBI not the best documented it was
pretty simple even for a newbie like myself. I think if you gave Ruby
a try yo umight be pleasantly surprised by what you find.

Hi, so far I’m finding learning Ruby to be an interesting process. In
particular, I was looking for a scripting language that had better
error handling than VBScript - or, more to the point, any error
handling at all beyond ‘On Error Resume Next’.

You correctly guessed that I’m automating things on a windows box, and
even only a week with Ruby has opened up a lot of interesting
possibilities. I haven’t delved into win32ole yet, but I will at some
point. I also haven’t had to look at the DBI module (I’ve used the
ODBC module and the MySQL module), but again I’m sure I will at some
point too.

All the best,

pt