The Ruby Programming Language 172
bdelacey writes "In January 2008, just in time for Ruby's 15th birthday, O'Reilly published The Ruby Programming Language. The co-authors make a strong writing team. Yukihiro (Matz) Matsumoto created Ruby. David Flanagan previously wrote Java In a Nutshell and JavaScript: The Definitive Guide — he has a CS degree from MIT with a concentration in writing. Drawings are the work of Rubyist-extraordinaire why the lucky stiff and technical reviewers include well known Rubyists David A. Black, Charles Oliver Nutter, and Shyouhei Urabe." Read on for the rest of Brian's review.
According to the Preface, Flanagan and Matz modeled this book after the K&R "white book" — The C Programming Language by Brian Kernighan and Dennis Ritchie. Like the "white book", The Ruby Programming Language has a simple structure and provides complete coverage. Just as K&R served as the de facto standard for "C", The Ruby Programming Language will likely be seen as the most authoritative language book for Ruby. Flanagan and Matz provide the following guidance for their readers: The Ruby Programming Language | |
author | David Flanagan & Yukihiro Matsumoto with drawings by why the lucky stiff |
pages | 444 |
publisher | O'Reilly |
rating | 9/10 |
reviewer | Brian DeLacey |
ISBN | 0-596-51617-7 |
summary | A classic and comprehensive guide to Ruby. |
"Because this book documents Ruby comprehensively, it is not a simple book (though we hope that you find it easy to read and understand). It is intended for experienced programmers who want to master Ruby and are willing to read carefully and thoughtfully to achieve that goal. ... [T]his book takes a bottom-up approach to Ruby: it starts with the simplest elements of Ruby's grammar and moves on to document successively higher-level syntactic structures from tokens to values to expressions and control structures to methods and classes. This is a classic approach to documenting programming languages." (p. 17)
You'll read all about boolean flip-flops, duck typing, lambdas, maps, metaprogramming, reflection and patterns of rhyming methods (collect, select, reject, and inject!). You'll also learn about new features in Ruby 1.9, like fundamental changes to text for Unicode support and the introduction of fibers fo coroutines. If it's in Ruby, it's almost certainly in this book. Chapters flow together nicely, although some could even stand on their own as educational materials for a computer science course (e.g. Chapter 7: Classes and Modules covers object-oriented programming and Chapter 8: Reflection and Metaprogramming elaborates on concepts like hooks, tracing, and thread safety).
In Ruby programming, difficult tasks are typically not only possible but often easy. It seems the authors take the same approach in their writing. For example, the complex topic of Domain Specific Languages (DSLs) sometimes creeps into deep discussions involving Ruby. Flanagan and Matz describe it simply and clearly: "A DSL is just an extension of Ruby's syntax (with methods that look like keywords) or API that allows you to solve a problem or represent data more naturally than you could otherwise." (p. 296)
During Ruby's first ten years, nearly two dozen books were in print in Japan but very few were available in English. That changed in 2004 when the introduction of Ruby on Rails created momentum for the language. A flood of new books followed, including Programming Ruby (2004, 2nd edition), The Ruby Way (2006, 2nd edition), Ruby for Rails (2006), and Learning Ruby (2007).
Programming Ruby, with lead author Dave Thomas, is self-described as a "tutorial and reference for the Ruby programming language." The Ruby Way, by Hal Fulton, was intended to complement Programming Ruby. Fulton noted: "There is relatively little in the way of introductory or tutorial information." Ruby for Rails, by David A. Black, has a clearly defined audience: "This book is an introduction to the Ruby programming language, purpose-written for people whose main reason for wanting to know Ruby is that they're working with, or are interested in working with, the Ruby on Rails framework." Learning Ruby, by Michael Fitzgerald, is a 238-page survey for "experienced programmers who want to learn Ruby, and new programmers who want to learn to program."
Programming Ruby and The Ruby Way each weigh in at over 800 pages. The binding on my copy of The Ruby Way came unglued and split in the middle after a year of use. The Ruby Programming Language is a slim, more manageable 444 pages and, in contrast, is the only one to cover Ruby version 1.9. In general, this is a great example of "less is more". Informative text boxes are sprinkled across the book with brief highlights on key technical thoughts. The first chapter's text box on "Other Ruby Implementations" (e.g. JRuby, IronRuby, Rubinius) could, however, be expanded into a several-page discussion of Ruby's various interesting architectures. Inclusion of IDEs and development tools (e.g. Eclipse, NetBeans, and TextMate) might also be helpful. These topics would nicely round out Chapter 10: The Ruby Environment.
The Ruby Programming Language has excellent cross-referencing. Section signs () feel like embedded HTML links that enable you to easily follow your coding curiosity around the book. Or you can just read it the old fashioned way, straight through. As an example, Chapter 3: Datatypes and Objects has subheadings (e.g. 3.1 Numbers) and well defined sections (e.g. 3.1.3 Arithmetic in Ruby.) The page-footers, table of contents and index also provide efficient navigational aids.
Artwork at the "edge of abstract expressionism" is something you might expect from The New Yorker magazine, but a computer book? The Ruby Programming Language introduces readers to "the edge of graphite expressionism". Original "smudgy residue" pencil drawings by why the lucky stiff creatively start each chapter.The Beatles' album cover for Sgt. Pepper's Lonely Hearts Club Band sparked intrigue and investigations into coded messages with hidden meanings. The same could happen here.
In Words and Rules: The Ingredients of Language, author Steven Pinker asks a simple question: "How does language work?" When I think about a new programming language, I have the same type of question in mind: "How does this language work?" Flanagan and Matz provide the answers in outstanding fashion. The Ruby Programming Language should help seasoned programmers who want to master Ruby. In addition, there is enough structure and sample code for determined novices to begin their programming explorations. Better than any other, this book defines the language. It is a classic and comprehensive guide for Ruby and a great 15th birthday present.
One long-time Rails developer sent me an email with their first impressions of The Ruby Programming Language: "I have been finding the book very useful, and I'm glad I did get it sooner rather than later." Matz said "Ruby is designed to make programmers happy." It looks like similar design thinking went into this book.
Brian DeLacey volunteers for the Boston Ruby Group
You can purchase The Ruby Programming Language from amazon.com. Slashdot welcomes readers' book reviews -- to see your own review here, read the book review guidelines, then visit the submission page.
Why can't this book be free? (Score:2)
Re: (Score:2)
Re:Why can't this book be free? (Score:5, Funny)
But they can make their money selling documenta.... oh wait.
(sorry. I *had* to heh)
Re: (Score:2)
I wish more authors would just include a CD with the book that has an electronic copy of the book on it so I didn't have to hunt all over the place for them.
Re: (Score:2)
Re: (Score:2)
This book can be "free", legally even... (Score:2)
It can also be "free" (of marginal financial cost) if you subscribe to Safari.
Re: (Score:2)
Re: (Score:2)
So which language wastes more water, Ruby or Java?
Re: (Score:2)
Huh? Is this the "new" English? (Score:2)
Error parsing sentence. Unable to comprehend.
Is this like the use of the word "your" instead of the correct "you're" as seen in more and more sentences, including a graphic on MSNBC.
Sorry, I'll stick to the old three score and twain. That's 62 in the "new" math.
Re:Huh? Is this the "new" English? (Score:5, Informative)
Drawings are the work of Rubyist-extraordinaire "why the lucky stiff" [whytheluckystiff.net] and technical reviewers include well known Rubyists David A. Black, Charles Oliver Nutter, and Shyouhei Urabe.
The rest of it should be passable English.
Re: (Score:2)
Thanks for the review! (Score:5, Informative)
Thanks for the kind review Slashdot! Thanks, Brian!
You can browse the table of contents of the book and read the beginning of each section at O'Reilly's website [oreilly.com].
You can find another review of the book at rubyinside.com [rubyinside.com]
Re: (Score:2)
Re: (Score:2)
For anyone else with programming-inclined progeny, take a look at one of why's other projects, Hackety Hack [hacketyhack.net]. It's an interactive Ruby environment for beginners.
Re: (Score:2)
Re: (Score:2)
Re: (Score:3, Interesting)
Re:Thanks for the review! (Score:5, Informative)
Re: (Score:2)
I suppose what I've written are more questions about the style of the book than anything else and I think you've answered them well. I hope they'll be useful to other potential readers of the Ruby book. And I look forward to finishing it myself.
I realize that my comments on the drawings
Re: (Score:2)
Re:Thanks for the review! (Score:5, Informative)
If you couldn't redefine constants, the second time you loaded a file you would throw errors. The reason why you would reload files is in a running development environment such as a framework like Rails or Merb. I also have a web framework (currently private but possibly we'll open source later) so I know this issue pretty intimately.
To clarify, the way it works is this: You are viewing a web page through a Ruby framework. The page rendering code is in a class. You want to make a change to a class so you go to the file and edit it. This may include changes to a constant. When you view the page again (by hitting refresh), the Ruby framework checks to see if the file has changed. If the file has changed (e.g. the constant we changed), then the file gets reloaded. Although we don't want to be changing constants in production, the ability to change constants in development mode is valuable. The alternative is we have to restart the server. The fact that it throws a warning is actually a good compromise because it means it's not normal behavior, but it is acceptable in certain circumstances.
Re: (Score:2)
In the context of Ruby, where "private" methods and instance variables are just a wee bit harder to get at rather than actually private, not enormously, though it would probably be cleaner (and consistent with h
Re: (Score:2)
Examples:
my ($x, $y) = ($i % $width, $i / $width);
my ($from, $to, $subject, $date) = get_email_info($email_header);
my ($dirname, $basename) = $path =~ m{^(.*/?)([^/]+)$};
Re: (Score:2)
I come from a different background that thinks something is more easily understo
Re: (Score:3, Informative)
Coroutines (Score:2)
Re: (Score:3, Funny)
Re: (Score:2)
I didn't know about COMEFROM. This is pure genius:
Re: (Score:2)
Why is joke syntax genius?
Re: (Score:2)
Just because it remained me the old times... you know Making it the other way around is funny and brilliant.
Re:Coroutines (Score:4, Insightful)
Most of the web apps I write wouldn't benefit from this sort of treatment, so I haven't jumped in too far, but call/cc has its uses for sure.
Re: (Score:2)
Re: (Score:2)
Re: (Score:2)
But, we are getting off the topic, here, which
Re: (Score:2)
Not so fast! I think you trivialize how well 90% of websites fit into a stateful, transaction-oriented architecture -- especially when hosting and serving requirements are factored in. I don't think that's a consequence of the way the web works, but rather the opposite; I think the way the web works is a consequence of the tools that power most of it.
Of course S
Continuation-based web frameworks and Ruby (Score:2)
To bring it back on topic, there is a Ruby continuation-based web application framework (Borges [rubyforge.org]) that is (or began as) a port of Seaside 2 to Ruby.
Re: (Score:2)
Uses of continuations in the real world (Score:2)
I don't have the code for either handy, but I've used it to implement an asynchronous discrete event simulations environment (loosely based on DEMOS [demos2k.org]) and a stateful-backtracking set up for intertwining syntax and semantics in a natural language system.
In the first case, a multi-threaded version has proved easier to maintain, and in the second case Moore's
Sketchup (Score:2)
Another good book to pick up... (Score:3, Informative)
The nice thing is that he doesn't fool around with explaining the simple stuff that you know already if you've done even one Rails app; he gets right down to business. Of course there are always interesting gotchas [blogs.com], but this is a book every Rails developer should have.
Ruby 1.9 and Programming Ruby (Score:2)
This is true of the dead-tree editions of the three major books you list, though it may be worth noting that the 3rd Edition of the Pickaxe (Programming Ruby) is currently available (in PDF) as a beta book and covers Ruby 1.9.
Re: (Score:2)
Re: (Score:2)
The Ruby Programming Language is a great book, from what I've seen of it (I've read a bit on Safari), but I still like Programming Ruby (and The Ruby Way and Ruby for Rails -- a great general Ruby book that doesn't have as strong a Rails focus as the name might suggest -- even though neither of those two has yet been updated for 1.9), too. I wouldn't particularly want to do without any of them, though if I had to choose only one right now, I might lean toward T
David Flanagan (Score:2)
collect, select, reject, and inject (Score:5, Funny)
I bet mods don't get the reference and mark me down.
I read a bit of this last night (Score:2)
On Friday, a bunch of people asked me about Ruby on Rails. I decided it was time to educate myself. After reading O'Reily's book that provided an overview of Rails, I felt that I should spend some time understanding the underlying language.
By pure coincidence, I bought this book. It's well-written. Last night, I couldn't put it down.
Ruby is a complex, but expressive language. I can't speak from real-world usage, but Ruby appears to provide many subtle variations in its syntax as a way of simplifying
Here be Dragons (Score:2, Interesting)
Take this bit of Ruby code, from _why's poignant guide to ruby [poignantguide.net]
class Dragon < Creature
life 1340 # tough scales
strength 451 # bristling veins
charisma 1020 # toothy smile
Re: (Score:2)
Ruby is (Score:3, Interesting)
This Ruby Grammar tree [flickr.com] shows part of the problem, that god like Primary token in the middle. Ruby requires an arbitrary look-ahead parser, an LL(k) parser which are notoriously problematic. LL(k) parsers are inefficient, difficult to implement and result in ambiguous semantics. The result is that the Ruby grammar requires the token analyser and parser to be tightly coupled, a code smell in most programs. Token lexical analysis is dependent on syntactic context and syntactic context is dependent on semantic information from dynamicaly typed local variables. This is lethal for parsers.
It is not possible to separate the lexical grammar from the language grammar, nor is it possible to properly describe the language grammar in a rigorous way. What defines a good language is that its semantics are well defined and consistent without reference to an underlying mechanisms, The fact that Ruby needs a LL(k) makes the semantics ambiguity, the parser implementation must make arbitratory assumptions about the semantics.
The Ruby syntax cannot be defined with by rigorous context-free grammar, it is ambiguous. This is lethal in Parsers, because two different parser implementations can attach different semantics to the same source code. YES, that's right a Ruby program can run differently on two platforms, even if they have correctly implemented parsers.
This cannot be fixed because this big problem with Ruby is the very thing that makes it attractive, the syntactic flexibility. That flexibility cannot be decoupled from semantic ambiguity, making it error prone to write and more importantly read.
Wirth said of good languages, a language is not so much characterized by what it allows to program, but more so by what it prevents from being expressed.
If you want a dynamic typed languages there are better choices with rigourous grammars.
Wirth was Wrong (Score:3, Insightful)
Wirth was wrong. At least for common definitions of 'good'. I dumped pascal for perl in the 90's, and the only people I know of who still actually use it are maintaining old Delphi. Yeah, there are some others I'm sure, but the practitioners of the art have decided Pascal is no longer useful.
Bill says, "a good language encourages a strong community, so y
Re: (Score:2, Funny)
Re: (Score:3, Informative)
Ruby isn't lightning fast, but its fast enough for lots of things, and its easy enough to interface with C (if you're using the main implementation) or Java (if you are using JRuby) if you need to refactor identified bottlenecks in a lower-level, higher-speed language.
As to scalability, I don't know of any particular problems with Ruby there. Green threads pre-1.9 and a Python-style GIL in 1.9 limit the ability to benefit from SMP architecture in one process on the one side, but
Re:Let's face it: (Score:4, Insightful)
Yup. It's strange - folks will post comments like "Ruby can't scale for a huge enterprise app!". The odd thing there is that for a huge enterprise app the opcode execution speed is probably not going to be the primary bottleneck. In fact, almost anything that reaches over a socket into a database is going to have bottlenecks that have nothing to do with how fast the Ruby interpreter can navigate an AST or set up a stack frame.
Re: (Score:2)
Re: (Score:2)
I'm not a Ruby fanboy but I agree that this argument is quite poor. A lot of entreprise apps don't need to be scaled. I mean we all need easy to code little apps that you run once a week, or a "glue" language for a specific non mission critical task. Most of the time you end up with things like Perl or Bash.
My main concern about Ruby is that very few developers know it. And you still don't know if this trendy lan
Re: (Score:2)
Re: (Score:2)
Hm, well, one concurrent HTTP client, yes. But if a Rails process can serve up 30-40 requests a second and a human using a web browser is only doing a request every 2-3 seconds, and you've got a cluster of 10 Rails processes... it seems to work out ok.
Re: (Score:3, Insightful)
FYI, an Apache worker process can also handle 1 request at the same time. And Apache solves that by... spawning multiple Apache worker processes!
Re: (Score:2)
The difference between scalability and performance is important, and dirt-simple. And it will help you no matter what your platform is.
Re: (Score:2)
Re: (Score:2)
Performance is how fast a program can accomplish a task on a given piece of hardware. If a C program can perform some task 10x faster than Ruby can do on the same hardware then the C program has much higher performance. How that performance is achieved, wether through better memory usage, faster calculations, or a better algorithm doesn't matter. It is simply the amount of work you can perform in a duration of time.
Scalability is simply that when apply more resources the output increases p
Re:Let's face it: (Score:4, Insightful)
Performance is how fast an app runs for a given amount of hardware. This is usually measured in how fast it is with respect to a single core of a single CPU.
Scalability is how well the app behaves when you just throw more hardware at it. That is, if you give it another ten CPUs and five gigs of RAM, will it be able to take advantage of that?
Ruby performance sucks. It is impossibly slow, even compared to languages like Perl or Python. I make no excuses for that. Look at the performance improvements of rails 1.9, and you'll get an idea of just how bad 1.8 is.
But Rails scales very well -- in the simplest example, the default configuration for Rails nowdays is a mongrel cluster, even on a single machine. It's a really strange and perverse design where you put a load-balancing proxy in front of at least three Rails/Mongrel webservers, each listening on a different local port. And unless you've done something stupid, this will Just Work, right out of the box.
But as long as your database server can handle it, you can just throw another server behind that load balancer. A lot of work has gone into making load balancers and database servers scalable, and you can take advantage of that, if you really need to. (For awhile, Ruby is still going to be the bottleneck.)
What this means is that I probably would not write a performance-critical desktop app (like, say, a game) in Ruby. But for web apps, it makes sense. If you can write the same app twice as fast, with half the people, you can afford to throw four times the server resources at it -- and as a bonus, you got it up in half the time as your competitor, who thought scalability == performance.
Re: (Score:2)
Clearly, you mean Ruby 1.9 vs. Ruby 1.8. Rails went from 1.2 to 2.0. Ruby went from 1.8 to 1.9, and in that step also switched to a bytecode compiler/VM (YARV) for a big performance improvement.
Re: (Score:2)
Re:Let's face it: (Score:4, Funny)
These kids. In my day we used to get funky with Fortran and we liked it.
Re: (Score:2, Funny)
No, but Grammar Nazis will.
Re:Trash (Score:4, Insightful)
Personally I don't like Ruby, but that doesn't mean the language is not good. It has some interesting syntactic sugar. And Rails didn't really invent anything new. MVC and ActiveRecord for example had been done to death before, but it packaged them in an attractive and simple little box with a nice glue language that made 80% of building a web app simple. It's always the remaining 20% that's hard, and I think Rails was not designed well enough to enable developers to jump the last hurdles. Much of the criticism I've read in the past few months about Rails is related to problems with how the public Rails API is designed and how too many developers are using runtime hacks to extend objects instead of having sane, language-specific inheritance/override methods for extension purposes. Again, nothing to do with Ruby the language, but you can't reall discuss Ruby without Rails because in the real world it's what currently drives its adoption. I doubt many people are writing desktop apps with it.
Let this be a warning to framework designers: your language, runtime and toolset better match the amount of hype you pile on your work. It's not good enough to have a cool language to go along. The popular Perl (Mason, etc), Python (Django, etc) and PHP frameworks prove it can be done.
Re: (Score:2)
Re: (Score:2)
Re: (Score:2)
Re: (Score:2)
He said there had been a backlash against ruby in blogs, not necessarily amongst startups who are looking to be buzzword compliant.
Re:Trash (Score:4, Insightful)
Actually, the absence of features for explict overriding (vs. implict overrides as the default) is something to do with Ruby the language (just like dynamic rather than static typing, etc. are inherent to Ruby as a language.)
OTOH, the complaints about "monkeypatching" are pretty much just a variation on the complaints about dynamic typing: "the language doesn't bind your hands enough, and someone else might do (or has done) something I don't like that was enabled by that."
Fine, look, everyone knows where to find Java and C if they need them. Beyond that, if you don't like the way the Rails team (or certain third-party plug-in writers) have used the power to reopen classes and objects, its not like there aren't plenty of other Ruby web application frameworks, ORM solutions aside from ActiveRecord, and libraries available for most uses in Ruby. Maybe the one library you really want was programmed by someone whose ideas about how best to use the language don't match yours, but that's possible with any language no matter what features it has. If you want code written to your specs, you've either got to write it yourself or pay someone else to do it for you, and complaining about a language because someone has used it to write a library using techniques you don't like isn't going to solve anything.
I dunno, I find it pretty easy to discuss Ruby without Rails. Rails is certainly the framework that made Ruby really visible in the US (though I gather it was fairly popular in Japan even before Rails), but I think that as it is getting exposed, the size of the non-Rails Ruby community compared to the Rails segment is probably growing.
I would imagine that if there weren't quite a few people doing that, you would have fewer GUI toolkits for it. And, of course, its also useful for system scripting; not every programming task is about a big app, whether web or desktop.
closet collectivist (Score:2)
The hype was far greater than the language could deliver and the fanboi's made it worse as they cannot face the limitations of the language.
Almost every serious book begins with a preface where the author praises his/her primary sources and then concedes "all the errors are my own".
Yet when random, excitable, anonymous forum-crawlers hype a software concept or language, if the hype doesn't come true, it's now the fault of the software. Isn't that an implicit form of collectivism? The entire Ruby community is smeared by hype generated from no particular quarter?
I've always had a soft spot for Perl 6. The engines of hype briefly chuffed into
Re: (Score:2)
Re: (Score:2)
Personally I find Ruby to be stylistically a superior language in many ways, though of course it's not suited for all problems. My chief gripe with it has to do with the difficulty with doing binary I/O. It seems to presume that everything should be translated into characters. And the lack of a non-text database connection. (I've even seen a manual on Ruby that declared that the external representation of numbers SHOULD be text...which is only tru
Re: (Score:2, Interesting)
Re: (Score:2)
I've looked at the Ruby syntax through a couple of books in the bookstore and from what I saw, I liked it a lot. For most stuff I want to do, Reg Ex, SQL Database search/output and Unix shell stuff, Ruby seems like a substantially easier language as you mention. I think C or C++ would be more complex than what I need and I never quite wrapped my head around why Perl is written the way it is. I haven't looked much at Python or s
Re: (Score:2)
Re: (Score:2)
I have tried (strived) to write (and clearly document) Perl code and still have a harder time reading "well written" Perl that *I* wrote than (almost) anybody's Ruby code, not being a Ruby expert (yet).
Try reusing Perl code, outside of stuff written to be part of a Perl Module (.pm). Blech.
Anyway, rather than
Learning Ruby from Rails (Score:2, Informative)
Why? Because Rails gives you a *reason* to learn Ruby. How often do people learn a certain programming language "just cause"? While I love to learn new languages, I tend to learn them when I need to or when there's a great reason to
I actually didn't learn Ruby by learning _all_ of Rails
Re: (Score:2)
Rails *is* the excuse people use to learn Ruby and it is what made it popular, staring in 2004. I will definitely pay it homage, here.
As uber cool as DSL's are, however, they do obscure the language. The irony of Rails is that it's so close to natural language (English) at times!
Re: (Score:2)
Take a look at SQLAlchemy [sqlalchemy.org]. You'll cry at how primitive ActiveRecord is by comparison. If you really need to get your ActiveRecord pattern on (it's the name of a pattern, not a product), there's always the much less powerful, but much simpler and still popular SQLObject [sqlobject.org].
Then there's Django's ORM, GeniuSQL, Storm, Axiom...
Re: (Score:2, Interesting)
If you really need to get your ActiveRecord pattern on (it's the name of a pattern, not a product) ...
We know what ActiveRecord is ;)
Thanks for the reply - SQLAlchemy looks great, tho it kindof "feels" like talking to a database, rather than objects, with "fetching" and "executing." I like ActiveRecord because you could swap out the backend of your objects, re-implement the API, and everything would still feel right. Even when I use plain text files as my backend, I try to implement an API compatible with ActiveRecord so, if I move to a database, it'll be easier to refactor.
Ruby's got tons of ORMs, as we
Re: (Score:3, Funny)
I'm not saying you're wrong but I don't think we can really be 100% sure until someone actually tries.
Re: (Score:2)
Re: (Score:2)
Re: (Score:3, Informative)
http://docs.python.org/tut/
http://diveintopython.org/
http://www.swaroopch.com/byteofpython/
http://openbookproject.net/thinkCSpy/
http://www.greenteapress.com/thinkpython/
http://en.wikibooks.org/wiki/Non-Programmer's_Tutorial_for_Python
Re:Which to learn first: python or ruby? (Score:4, Funny)
Once you learn python you ain't gonna get past hello world in ruby. You will
sit there, look at the syntax and say what the hell do I want to learn this for.
Re: (Score:2)
I'd take either one in a heartbeat over perl though.
Re: (Score:3, Insightful)
After 12 years of Perl, though, I hope I'm done with it. Either Ruby or Python are going to take you far as a programmer, since both languages are modern and elegant, in different ways. Perl 5.x is like BASIC, in that it teaches you bad habits.
Ruby does have a sense of enlightenment, though. I can't comment about Python, concerning this aspect. It seems that its "Lisp
Re: (Score:2)
myList = []
10.times do |i|
mList.push(i)
end
myList.each do |l|
puts l
end
Again it is not about Rails of structuring things, Is the organic aspect of the language that works as an extension of your action with so little translation/morphing. With Ruby, my actions are more transparent. With Ruby I see the actions, not the syntax, which is what I want. Now, If this looks very similar to Python, great. I heard
Re: (Score:2)
# ruby
myList = []
10.times do |i|
mList.push(i)
end
myList.each do |l|
puts l
end
# python (normal loop, more straightforward)
for l in range(0, 10):
print i # or sys.stdout.print("%d\n", l)
# python (list comprehensions, more direct analogy)
import sys
myList = range(0, 10)
[ sys.stdout.print("%d\n", l) for l in myList ]
# note this is a bit wasteful, since list com
Re: (Score:2)
Re: (Score:2)
Sure, but something would have to consume it or it would never start. At that point you may as well just use a loop. I think the OP was just showing off syntax -- no one would ever actually write real world python like that.
Re: (Score:2)
To just print that you'd type
puts (1..10).collect
And if you just wanted it in a variable you could write:
puts nums = (1..10).collect
Personally, I dislike the do/end block style and the multi-line nature. It's wordy and means I can't see as much on the screen. I'd rewrite the example as:
nums = []
10.times {|n| nums << n }
nums.each {|n| puts n }
Though the benefits IMHO come only when you start chaining commands together, as with a pipe (|) in shell.
# take n
Re: (Score:3, Interesting)
I learned Python pretty much immediately before learning Ruby, and I personally find Ruby more attractive, from a syntactic perspective, even before considering Python's interesting use of whitespace, which doesn't bother me as much as it does some people, but still isn't as attractive to me as it appears to be to Python fans.
Re: (Score:2)
Re: (Score:2)