Ruby vs Python (IMHO)

D

Daniel Carrera

Hi all,

I guess I just want to share a tiny "case study" from a project that I'm
doing in Python and which I wish I could do in Ruby instead.

I am writing a BibTeX filter for the OpenOffice project (BibTeX is the
bibliographic cousin of LaTeX). I am doing it in Python because, of the
languages with stable bridges to the OOo component model (UNO) Python is
the one I like best.

My requirements are mostly related to regular expressions and string
methods. This is an area where Ruby really shines and is light-years
ahead of the competition.

Regular expressions in Ruby are infinitely eaiser and more sensible to
use than in Python.

Ruby:
str =~ /^(#{char})\s*{\s*(#{char}+),(.*)}/


Python:
regex = re.compile(r"^(" + char + "+)\s*{\s*(" + char + "+),(.*)}")
regex.match(str)


Like this, there are many exaples. Quite simply, strings are much easier
to manipulate in Ruby. Regexes are superior, there is varible
substitution, and the string methods are much better.

To make a long story short. If I could do this in Ruby the parser would
be easier to write, more understandable, and I would be more confident of
its correctness.

Cheers,
 
P

Phil Tomson

Hi all,

I guess I just want to share a tiny "case study" from a project that I'm
doing in Python and which I wish I could do in Ruby instead.

I am writing a BibTeX filter for the OpenOffice project (BibTeX is the
bibliographic cousin of LaTeX). I am doing it in Python because, of the
languages with stable bridges to the OOo component model (UNO) Python is
the one I like best.

Hmmm.... so what would it take to include Ruby in the set of languages
with 'stable bridges to the OOo component model'?
My requirements are mostly related to regular expressions and string
methods. This is an area where Ruby really shines and is light-years
ahead of the competition.

Regular expressions in Ruby are infinitely eaiser and more sensible to
use than in Python.

Ruby:
str =~ /^(#{char})\s*{\s*(#{char}+),(.*)}/


Python:
regex = re.compile(r"^(" + char + "+)\s*{\s*(" + char + "+),(.*)}")
regex.match(str)

Ouch, that's painful.

Phil
 
D

Daniel Carrera

Hmmm.... so what would it take to include Ruby in the set of languages
with 'stable bridges to the OOo component model'?

I'm not entirely sure because I know so little about UNO.

I asked around and they said that the easiest way would involve using the
Java implementation of Ruby, alongside the scripting framework. The
scripting framework is just about to be added to the development branch of
OOo. There's not much information about it just yet, but I plan on
bugging the framework people about it.

Ouch, that's painful.


Tha's what I thought. And regexes make up the bulk of the filter (the
hardest part is parsing BibTeX).

Cheers,
 
D

Daniel Carrera

(r"..." is Python for '...', btw: strings without special character
sequence processing. The 'r' stands for "raw" strings.)

I had been wondering about that. Thanks.
 
N

Nikolai Weibull

* Mark J. Reed said:
(r"..." is Python for '...', btw: strings without special character
sequence processing. The 'r' stands for "raw" strings.)
yeah, isn't it obvious? ;-). it really stands out well. this is just
one example of things that seem to be hacks in Python,
nikolai
 
J

Joey Gibson

I'm not entirely sure because I know so little about UNO.

I asked around and they said that the easiest way would involve using the
Java implementation of Ruby, alongside the scripting framework. The
scripting framework is just about to be added to the development branch of
OOo. There's not much information about it just yet, but I plan on
bugging the framework people about it.

Do you have a URL to check this out? I could take a look at what might
be involved with using JRuby like you said...

--
Never trust a girl with your mother's cow
never let your trousers go falling down in the green grass...

http://www.joeygibson.com/blog
http://www.joeygibson.com/blog/life/Wisdom.html
 
D

Daniel Carrera

I'm not entirely sure because I know so little about UNO.
Do you have a URL to check this out? I could take a look at what might
be involved with using JRuby like you said...

They've promised to have one up "any day now". In the mean time, take a
look at http://framework.openoffice.org.

When the more relevant documentation gets written I'll give a shout at
ruby-talk.
 
C

Charles Hixson

Nikolai said:
yeah, isn't it obvious? ;-). it really stands out well. this is just
one example of things that seem to be hacks in Python,
nikolai
That's not a very good example. Ruby Q & q strings are just as bad,
even if they were imports from Perl.
For that matter Ruby has a simply HUGE number of ways of specifying
strings. This isn't usually a problem, but it could be seen as such.
My real problem with Python is that I simply hate using the amount white
space as semantically significant. Ruby has other conveniences. But on
the standard run of problems I deal with the difference isn't huge.
 
D

David Garamond

Nikolai said:
yeah, isn't it obvious? ;-). it really stands out well. this is just
one example of things that seem to be hacks in Python,

I don't see r"" as more hackish than Ruby's %Q(), %q(), %r() or Perl's
``, q(), qq(). It's just an alternative way to express literals.
 
B

Bauduin Raphael

Phil said:
Hmmm.... so what would it take to include Ruby in the set of languages
with 'stable bridges to the OOo component model'?

There was a project about making python modules available to ruby, but
it was not developed anymore (
http://www.goto.info.waseda.ac.jp/~fukusima/ruby/python/doc/ )

I mention it because the question arose on ruby-garden (IIRC) about
which modules available in Python were lacking for Ruby and I see this
as an example :)


Raph
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top