Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Perl to Ruby translator?

by Anonymous Monk
on Oct 10, 2003 at 16:12 UTC ( [id://298296]=perlmeditation: print w/replies, xml ) Need Help??

Has anyone developed (or is developing) a Perl to Ruby translator? (to facilitate the transference of Perl5 masterpieces like Template toolkit, Mason etc)

I get the impression that Perl6 is at least 5 years away (or am I too optimistic).

... other random thoughts : 1) In Ruby, we have a language out there now that is very Perlish but supports the notion of 'Programming as a craft' much better than Perl5 does. Why not invest our energies in Ruby instead of Perl6

2)Is there a danger Perl6 could end up a bloated monster raher like C++ (Exegesis 6 reminded me somewhat of the effective C++ books by Scott Meyers)

If you love your craft, you'll understand.

Replies are listed 'Best First'.
Re: Perl to Ruby translator?
by Ovid (Cardinal) on Oct 10, 2003 at 16:56 UTC

    Warning: Ramble ahead!

    I do love my craft and I agree that Ruby has some things going for it that Perl 5 does not. However, Perl 5 is, for all intents and purposes, a much more practical language. The primary reason for that is the CPAN. In fact, it may be that the CPAN is the last main reason to stick with Perl 5. That's why we needed Perl 6. Perl 5 is old and it shows (though I must confess that I love the language and all of it's quirks :).

    If we love our craft, we will grow and discover new things. If you appreciate the conciseness that can be found with rich expressivesness, you'll appreciate the direction that Perl 6 is going. Heck, even Java is beginning to realize that things need to be different. Java 1.5 has enough interesting things in the language (such as Generics and Autoboxing*) that it might start moving in some very interesting directions. Most notably, one direction appears to be less code, which is one of the biggest complaints against the language.

    In short, all languages evolve. Perl is evolving, but the direction is exciting. The new features make the language simpler without the overhead that C++ (to use your example) forces upon us. For example, to iterate over lists in parallel:

    for @ids, @customers -> $id, $customer { ... }

    That's the sort of thing that people need to do all the time, but write buggy code to accomplish. If your complaint is that Perl 6 will be a huge language, you're right. I'm not sure how that's a complaint, though. It's still easy to learn the basics and adding little bits and pieces of the language as you go is not a Bad Thing. However, these new constructs make programs shorter and clearer. Not like C++ at all :) To really get a feel for it, though, check out Perl 6 Essentials. It's a very easy read and while it's admittedly already out of date, they will be updating it every year until Perl 6 comes out.

    Cheers,
    Ovid

    New address of my CGI Course.

    * Autoboxing is nice, but I find it pretty annoying that it's a way to deal with a broken "feature" of Java rather than just fix the darned feature. Why won't Sun listen to their users? Or are their users so used to mixing primitives and objects that they don't realize there's a better way?

      I've used, taught, and advocated Perl for several years, and will continue to do so. I toyed with Ruby two years ago, came back to it a year ago, and now choose to implement most of my personal projects in Ruby. It is concise, expressive, and flexible, and while its RAA isn't as developed as CPAN, it does have nearly 1,000 application/library packages many of which are quite mature (and libs for ftp,http,stmp,pop,telnet,webrick,yaml,xml, among others are included as part of Ruby's standard library). It also has flexible iterators, and you can iterate over multiple Enumerable objects already :-)

        What the AM said ;-)

        I've been learning Ruby on the side this year and it has been a most enjoyable process. Nice language. Well designed. Far fewer odd corners than Perl 5.

        I'm seriously considering using it for some commercial work if the opportunity arises.

        Only two downsides that I've encountered:

        1. The lack of CPAN. RAA is nice but not quite at the same level of utility yet. However, for many applications all you need is there.
        2. Speed. Its surprisingly slow. Again, not always a problem. Also, there is no real reason it won't get faster in time. It is, after all, just a trivial matter of programming :-)
Re: Perl to Ruby translator?
by Abigail-II (Bishop) on Oct 10, 2003 at 17:01 UTC
    If Ruby is so excellent and so wonderful to program in, how come you're looking for a Perl to Ruby translator? Surely by now Ruby should have its own masterpieces? Ruby has been available since 1995, which is longer than many of the Perl masterpieces.

    So, why doesn't Ruby have its own quality templating system?

    In Ruby, we have a language out there now that is very Perlish but supports the notion of 'Programming as a craft' much better than Perl5 does.
    What are you saying here? That Ruby is very close to Perl that it even can be called "Perlish", or is it very different due to this "notion of 'Programming as a craft'", whatever that maybe?

    I can't help it, but each time if I see someone advocating Ruby, it's like I heard some Python user. Everything is relative to Perl. But if Perl is the measure, Perl is good enough for me.

    Are there some features that carry Ruby on their own? (Other than "everything is an object", I don't really care whether "1" is an object. I don't need it. I've programmed for two decades with numbers, and I've never felt restricted that number weren't objects. (And if I really wanted to modify my numbers, I'd use FORTRAN)).

    Abigail

      Ruby has 2 big features that are worthy of note.

      The first one is irrelevant to most of us, and that is that Ruby smoothly supports multiple different character encodings, including ones for Japanese text which aren't directly-supported other scripting languages (like Perl). This is notable because it is why Ruby was invented.

      Other than that, Ruby is a highly derivative language which is mainly notable for a remarkable consistency in its layout and design. Before I tried Ruby I wouldn't have believed that this was an important feature. After trying it, I was amazed at how many things which in Perl look magical because of how the language has hidden things from you (eg overload and tie) in Ruby are so natural that it was only in retrospect that I realized that the language was cleanly enough structured that no extra hooks had to be added to let the user play with those.

      My capsule summary is this. On a few small projects that I did in Ruby, I found that I did the same thing in about half the code that I did in Perl. However my code ran slower, and I had to rewrite things that in Perl I would have gotten from CPAN. Furthermore, I am unlikely to get a job programming Ruby, but I can with Perl.

      Furthermore I recommend learning Ruby's class library to people at a certain level of expertise in virtually any language as an example of what good design. This only holds in a certain range. If you don't have enough background then you can't see why the design works, and won't get much out of it. If you have too much, then you have hopefully seen the basic ideas already in Smalltalk, Lisp, Perl, etc.

      I can't readily quantify what level is right for that experience to be valuable. But I was certainly in the right range 2 years ago.

      "Everything is an object" is only a tiny part of Ruby's strength: object oriented programming is Clean And Easy. In Perl, it's always messy. There are some other nice things (no special global variables f.ex), but those are really details; some people might also consider "less linenoise" an argument (I'm indifferent). On all other accounts, Perl and Ruby are pretty much on equal footing.

      Makeshifts last the longest.

      I can't help it, but each time if I see someone advocating Ruby, it's like I heard some Python user. Everything is relative to Perl. But if Perl is the measure, Perl is good enough for me.
      Seems Perl is the measure for Perl6 too, just a better Perl by some peoples measure. So, if others find Ruby to be a better Perl by their own measure, it stands to reason they'll use Perl when describing it.

      I think Ruby's biggest weakness is that's its RAA (cpan equivelant) isn't as well developed and as standardized as CPAN. I think CPAN remains Perl's big killer-app. Ruby does have mature templating systems, but as you know, everyone who invents a templating system does it differently. It doesn't seem so odd that a particular templating model "X" might not exist in Ruby and someone would rather see a port of model "X" than use one of the "Y" or "Z" models already implemented in Ruby.

      Or %^H. I've seen you redefine numbers before.

      (Drat. I forgot to include the caret in the variable name and that just spoils the whole thing. Well there it is now.)

Re: Perl to Ruby translator?
by Aristotle (Chancellor) on Oct 10, 2003 at 16:59 UTC

    Ruby is a solidly crafted incarnation of proven stuff. It does not break any new ground, and probably doesn't want to. Perl6 is all about breaking new ground. No, I don't think it's going to be a monster. Closures probably seemed like a pretty outlandish feature at the time of their introduction too.

    Larry and crew have gotten Perl 95% right five times in a row. I trust them to manage that feat again.

    Makeshifts last the longest.

      Perl 6 is almost entirely about not breaking new ground. There's nothing new or revolutionary in it--this is all well-travelled ground. (Granted, not by perl, but well-travelled nonetheless) All that's happening is we've stopped mining the '60s and '70s for features and have started in on the '80s...
        Which is a better way to say what I meant. :) Perl5, Ruby, Python, and even more so the "real" (feh) languages like Java and C++ are all pretty well grounded on the '60s/'70s level. They're not new ground from a scientifical viewpoint, but '80s features will largely present new ground to people coding for a living.

        Makeshifts last the longest.

        All that's happening is we've stopped mining the '60s

        <cough> Lisp? Macros? </cough> :-)

      Perl6 is all about breaking new ground

      I'm curious. What new ground do you think Perl 6 is breaking? It's borrowing lots from other languages but I don't see anything really new.

      What makes Perl so great is its strategy of mugging any languages that happen to be walking past for anything that looks vaguely useful :-)

        I got myself in a bind with that expression, didn't I? It's hard to explain, too. My point is along the lines that Perl6 is about trying to give features formerly considered "esoteric" to "code grunts". I wish I could outline it any clearer.

        Makeshifts last the longest.

        I'm curious. What new ground do you think Perl 6 is breaking? It's borrowing lots from other languages but I don't see anything really new.
        That's just it. Like perl5, it's borrowing all the great features from other languages, enhancing them, makeing them perlish, thus creating a cohesive and coherent, language (platform). Also, almost every perl5 feature is being continually improved, like the regex engine (you won't need flex/bison anymore). Then there are awsome hyperoperators, and generators ... complete programmer satisfaction ;)
      I unerstand your point, but wow, closures are a huge ongoing source of confusion and bugs. If every new feature is as problematic as closures, we're in for a rough ride.

        This may sound arrogant, but - to what level of programmers? I can count on the fingers of one hand (with several to spare) the number of times I got myself in a bind with closures. As the old adage goes, real programmers can write FORTRAN in every language - I doubt anyone who makes a mess with Perl would write clean and sophisticated code if just given another language.

        I don't want to close the post on that note; I understand your concern and know just taking the indoctrinated stance on this doesn't make the problems in practice go away. But in my experience trading expressiveness for simplicity does not pay off in the long run. ("Simplicity" is not quite the right word either.)

        Makeshifts last the longest.

Re: Perl to Ruby translator?
by Anonymous Monk on Oct 10, 2003 at 16:29 UTC

    Parrot will eventually provide a virtual machine that both languages can be targeted to. Not a translator, but sounds like it would help you out.

    Also keep in mind that you're free to translate key modules from Perl to Ruby. Assuming you have a decent knowledge of both languages (and they don't use XS) it wouldn't even be that difficult.

Re: Perl to Ruby translator?
by iguanodon (Priest) on Oct 10, 2003 at 16:30 UTC
    In Ruby, we have a language out there now that is very Perlish but supports the notion of 'Programming as a craft' much better than Perl5 does.
    Can you elaborate on that please? I'm not familiar with Ruby, nor with what you mean by 'Programming as a craft' for that matter.

Re: Perl to Ruby translator?
by Jaap (Curate) on Oct 10, 2003 at 23:27 UTC
    Hmmmmzzzz... looking at some Ruby code (here) i must say: it look pretty clean and well... perlish.

    Might give it a go one of these days...
Re: Perl to Ruby translator?
by cbraga (Pilgrim) on Oct 10, 2003 at 20:34 UTC
    I've never tried Ruby so I can't be sure, but I suppose it's possible to embed Perl code into Ruby. Making the point moot.

    Besides, auto-translated code is never too exciting to work with.

Re: Perl to Ruby translator?
by adrianh (Chancellor) on Oct 11, 2003 at 20:44 UTC
    Has anyone developed (or is developing) a Perl to Ruby translator? (to facilitate the transference of Perl5 masterpieces like Template toolkit, Mason etc)

    Not AFAIK. Perl and Ruby are different enough to make this non-trivial. Ruby is also busy making its own masterpieces.

    There's also the fact that that good Ruby style is sufficiently different from good Perl style that moving between the two would probably jar stylistically.

    I get the impression that Perl6 is at least 5 years away (or am I too optimistic).

    Personally I'm a bit more optimistic than that. I wouldn't be surprised to see something vaguely usable in a couple of years (but I am an eternal optimist ;-)

    ... other random thoughts : 1) In Ruby, we have a language out there now that is very Perlish but supports the notion of 'Programming as a craft' much better than Perl5 does. Why not invest our energies in Ruby instead of Perl6

    Because Perl 6 is a very different language from Ruby. There is stuff that you'll see in Perl 6 that you're unlikely to see in Ruby because Larry et al have different design philosophies than Matz (BTW there is a brief interview with Matz over on artima.com). For example I don't think you'll ever see something like Perl 6 macros or full multiple-inheritance in Ruby.

    A more interesting question is whether Ruby is a good alternative to Perl 5. I'm seriously considering doing commercial work in Ruby in situations where CPAN won't give me a major advantage.

    2)Is there a danger Perl6 could end up a bloated monster raher like C++ (Exegesis 6 reminded me somewhat of the effective C++ books by Scott Meyers)

    I don't think so. The Exegesis are not intended to be easy to understand - they're very concise summaries of language features. More design documents than anything else.

    I actually think you'll find Perl 6 will be easier to learn than Perl 5 :-)

Re: Perl to Ruby translator?
by Jarble (Initiate) on Aug 03, 2018 at 23:39 UTC
    My universal-transpiler tool converts some simple Perl programs into Ruby, but it's only a proof-of-concept.
      You should look into "Marpa"

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlmeditation [id://298296]
Approved by Ovid
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (4)
As of 2024-04-19 20:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found