Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Perl 6 and Ruby on Rails

by Akhasha (Scribe)
on Apr 06, 2005 at 07:59 UTC ( [id://445204]=note: print w/replies, xml ) Need Help??


in reply to Perl 6 and Ruby on Rails

As far as Ruby vs. Python features go:

1) code blocks. Ruby lets you pass code blocks around. Sounds pretty dull, eh? But in fact it's what makes it possible to create Domain Specific Languages in Ruby quite easily without needing to create a special parser. In many ways Rails can be thought of as a domain specific language built on Ruby.

I'm not sure how this is different to passing function-pointers/coderefs/callables around. Certainly the flexbility of Python, with extensible and substitutable types and operators, could lead one to implement different semantics for most expressions than those prepackaged. Harder to get around the whitespace-is-syntax feature though. If someone can expand on the difference w.r.t. Ruby please do.

2) classes are always open in Ruby(including the Class class). By 'open' I mean you can always add new methods to a class (or even a particular object). Another feature that makes it easy to create DSLs

AFAIK this is also the case for Python and Perl. In Python you can think of every object (and classes are objects) as a hash, with attributes you can diddle at your leisure (and peril?). Perl's blessed references and package symbol tables might be a little less flexible, in that I think adding a method to an object would involve putting it in the package symbol table, thus adding it to every object of that class. (please correct me if I'm wrong on this)

3) continuations. (Not that Rails makes use of them, but some other Ruby-based web programming frameworks do)

Python (2.4) has generators that 'yield' values to the caller and when called again continue from the line after the last yield.

4) Ruby has true lambdas. AFAIK Python's lambdas are pretty limited (limited to one expression?)

Limited to a list of expressions, no statements allowed. IMHO this is a notable shortcoming of Python, its also easier to create anonymous subs in Perl. Python requires you to take a reference of a named function, or write a named function that returns a code reference. But that's not a show-stopper.

Thanks for your post, I'm often reading this or that about different languages and enjoy comparing them. Perl is my job, Python is a hobby and Ruby a mystery.

To answer your question about embedding Python in HTML, its not so bad. Breaking up long lines of HTML+Embedded code is a good idea. Check out Poor Man's Zope for instance.

Update: I reread the node and see what is meant by passing blocks of code around. Sorta :)

Replies are listed 'Best First'.
Re^2: Perl 6 and Ruby on Rails
by mattr (Curate) on Apr 06, 2005 at 15:15 UTC
    Great, thanks for the response. Just to clarify I am not advocating (nor do I really know anything about) Ruby on Rails, nor am I a Ruby programmer. Most everything in the post between "..to answer myself" and "Thanks, Matt" is verbatim snipped from slashdot posts in the referenced thread.

    As I reread a few times my own post I realize the thrust is: Can you create "Domain Specific Languages" easily in Perl 6, and can they look like a natural language (i.e. a minimum of punctuation, use of space-separated words, etc.). I suspect yes though there certainly will be some caveats, for example the "has" reserved word in Perl 6 looks like Class::DBI's has_a() or has_many(). So a nasty semantic mess is possible.

    classes are always open

    I think I saw the same mentioned in a Perl 6 Synopsis.

    thus adding it to every object of that class

    However this I think is contradicted by (was it S4?) mentioned traits and how you can add methods to an object from another object. The converse of that would seem to be the smart match where the tree of inheritance is walked up to find a module that can/handles a method on your object. Sorry I'm newbie to 6.

    As for embedding Python in HTML, sorry that was part of a copied snippet not a wish of mine for sure. I once had to customize a template for an Infoseek installation and it was just that.. it struck me as exceedingly ugly and painful, but maybe because they just used too much of it. This was some years ago..

    Thanks, Matt

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (4)
As of 2024-04-20 03:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found