Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

As to the lack of sigils and arrays and hashes both being indexed with square brackets, that gets more into the Ruby tendency to favour interface polymorphism (or as it's often referred to, "duck typing"). So long as what you're calling the [] method on responds to that method, everything is hunky-dory and it allows for some nice flexibility. I think the example given in one of the books was code which was using a string IO instance with << to build up something for output and the temporary objects were killing performance; they swapped to passing in an array which also groks << (and then called join afterwards once) and the app went from terrible multiuser performance back to acceptable (or something along those lines).

Not that this approach doesn't also have issues (e.g. you call method zorch expecting the object to do foo, but instead it does bar and wipes your hard drive . . .), but there is a rationale behind it.

And also there is a more traditional looking for loop, but it's really (mostly) syntactic sugar for calling each:

for var in iteratable puts "Frobnicated: #{var.frobnicate}" end ## is pretty much just the same as this . . . iteratable.each { |var| puts "Frobnicated: #{var.frobnicate}" }

But really that's like persisting to use C-style loops in Perl . . . :)

The cake is a lie.
The cake is a lie.
The cake is a lie.


In reply to Re: Ruby Before Perl? Nah. by Fletch
in thread Ruby Before Perl? Nah. by starX

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (5)
As of 2024-04-24 08:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found