This is probably another unapproved translation as zed said his book was meant for teaching python and we need substantial changes for ruby.
The other book basically translated the code from python to ruby while keeping much of the text the same I don't know if this is the case with this one.
The prose in this translation is nearly 100% identical to the Python version with the exception of a few paragraphs that have been modified to be relevant to Ruby. All of the code exercises and required libraries have been completely adapted for Ruby. In other words, Zed did all the really hard work.
Yes, exactly. Rob asked permission, and did a good job doing the translation. My problem with the other attempt was it was half-assed, done without permission, and then left to rot so I had to field frustrated students asking me when it'd be done.
This isn't quite idiomatic ruby, but I think it'll be a good kick-starter for someone who knows nothing, and I'm looking to get people to help mold it to be better.
A Perl version would be good, but given that Modern Perl (http://onyxneon.com/books/modern_perl/) is a fairly recent release, I see many people just pointing newbies towards it since it's very much up to date.
Zed here, this one is different because Rob asked permission and then did a great job actually completing the translation. It's not totally idiomatic Ruby, but it should be a good start for people.
I loved Learning Python the Hard Way so I think I'll do the Ruby version as well, would you recommend anything specific after it to learn idiomatic Ruby?
I was kind of bummed before that a book with such wonderful reviews was only available in one language. This is awesome! Thank you guys so much for doing this :)!
I think that the point of LPTHW/LRTHW is that you type everything yourself instead of copy-pasting the examples:
"You must type each of these exercises in, manually. If you copy and paste, you might as well just not even do them. The point of these exercises is to train your hands, your brain, and your mind in how to read, write, and see code. If you copy-paste, you are cheating yourself out of the effectiveness of the lessons."
Regarding copy/pasting, I do agree. Not much of a point in reading if you're just going to do that.
But, I was having a problem with exercise 4 and so copy/pasted it from the webpage (removed line numbers with TextMate's vertical selection easily enough). Received the same error when trying to run it as I did when I typed it myself:
ex4.rb:10:in `+': can't convert Fixnum into String (TypeError)
from ex4.rb:10:in `<main>'
I'm not familiar enough with Ruby to understand why it's doing that... my googling shows similar ruby tutorials with that format, but one site I found suggested using #{variable_name} instead of the " + variable_name + " and that worked just fine for me.
Is this a real error in the book or something weird going on with my computer (OS X Lion w/ Ruby 1.9.2 installed)?
Couldn't get your way to work, it blew off the rest of the string. Managed to get it to work by calling .to_s on each variable. Wondering if I did something wrong. I have your same setup and I'm a complete Ruby Noob.
Yes, this will throw an error in Ruby because of line 1:
>1 cars = 100
Ruby does not allow the mixing of integers and strings. So, as mentioned, you can invoke the .to_s method. Or you can interpolate the variables as you have done so with #{cars} inside double quotes.
Interpolation actually calls #to_s on the object, so if object.respond_to?(:to_s) returns true, you can use use it inside #{} in any kind of string that allows interpolation.
When I read exercise 4, I thought, "I can't believe Ruby made the same mistake as Javascript!" Glad to learn this particular type of foot shooting is not possible in Ruby.
Also a ruby newb, so I'm not sure, but I think it's an error in the book. I got that error on all versions of ruby I tried. Either var.to_s, or "blah #{var} blah" works for me.
Ah, I should fix that example. It's totally wrong. Nice catch!
In hindsight, I probably should have used "Hello #{name}" style string interpolation in all of the examples since thats the idiomatic way of doing things.
I was trying to expose the newcomer to multiple ways of manipulating and concatenating strings, but since the aforementioned way is almost always best, I should stick to that.
I started off doing this to teach myself Ruby. I enjoyed the Python version so much and thought it would map pretty well since the languages are fairly similar.
After about 15 exercises, I saw that it was actually coming out quite nicely and reached out to Zed. Zed was super cool about releasing it under his license as long as the end result was high quality.
I wouldn't have cared if he said not to release it because I got to learn Ruby and play with Sinatra, Jekyll, etc.
I've been working on corrections and I was actually struck by how seemingly trivial differences in the languages can completely break large parts of the book. For example, the python version introduces modules fairly early because they are needed for other lessons. But I don't think there is a single library dependency in the entire Ruby version. It can't introduce require and then never use it, but there is very little entry level stuff in the Ruby standard library. There should probably be a chapter on making your own libraries, but that would have to be new material very late in the book.
Huh? require is used quite a bit: exercises 12, 25, 43, 47, 48, 50, 52. Some exercises depend on sinatra, some depend on test/unit, some depend on stuff you write yourself.
The problem is it's teaching you Python's module system, which is very different from Ruby's require system.
Ex. 12 introduces `require` with example code that is way over the reader's head at this point in the book, and unrelated to anything they have seen or will see until ex. 25. It also says that features are called "modules" but that's completely wrong -- Ruby modules are something else entirely. And the term "module" is used in the Python sense all over the book. All those need to be changed.
Ex. 25 asks the reader to require their own file but never explains how to get the file in the load path, so I don't think the reader has much chance of completing this exercise.
My point is that I don't think a direct per-exercise translation is going to work. Requires in Ruby are more complicated and used less often than modules in Python, and the book is very linear, so I think require will have to be introduced in a completely different way if it's going to make any sense.
There are other topics that have this problem, like heredocs. In Python they are pretty so it's ok to throw them at the reader early on. But Ruby heredocs will melt their eyeballs out of their sockets, and they are rarely used in practice, so they probably shouldn't be in the book at all.
I am working on these sorts of changes with the intention of sharing them with you to see what you think, but it's starting to snowball so I don't want to promise anything. I'll do my best.
Is there a single-page version of this available that I could put into my Kindle? Alternately, I'd be quite happy to pay for a copy if it was posted to Kindle Self-Publishing (https://kdp.amazon.com)
This is a great resource. I'm in the process of learning Ruby, and will be trying out Ruby Koans and Satish Talim's Ruby Learning site as well in comparison. Does anyone know how good those tutorials are, or if there are any other good online Ruby guides?
Could someone explain the reason why the "learn x the hard way" method has been so popular around here? I keep seeing the name thrown around, but haven't had a chance to look into it yet.
I think it goes beyond simply being Zed's name. It is genuine good stuff. My son has been using LPTHW to learn programming from 0 with positive results so far.
I really like the idea behind these books, it reminds me of how I learnt originally, typing BASIC programs into my zx spectrum from the back of computer magazines.
You too - though i didn't have access to too many computer magazines so had to make do with odd listings gleaned from various sources including kermit.
i'm sure it was helpful. the first skill in learning how to code is little details, like making sure all the text is the same as the listing, and that you pressed enter after every line ... ;-)
Out of curiosity, is Rob Sobers pretty known in the programming community?
I have never heard of him before, but based on the way Zed wrote about him, seems that he just might be famous and I haven't heard about him (which is very possible).
Otherwise, if he was just a 'regular' web designer that learned Python the Hard Way and translated to Ruby and Zed has given him so much credit....that would be AWESOME.
In all honesty, quite uncharacteristic of Zed - as far as I know, not being a dick (just honest) - which is why I think he is 'programming famous'.
I am hoping he was just a regular 'joe blow' though.
I'm definitely not "programming famous." My boss, Joel Spolsky, is though (I work for Fog Creek Software).
I don't know Zed personally either. He was a bit skeptical about me doing this at first, but he was ultimately really cool about it because I respected his terms, and if at any time he told me to ditch the book, I would have.
67 comments
[ 13.7 ms ] story [ 135 ms ] threadIf so, I'm cool with that. Zed can be a firestarter, but this shows he's cool with others contributing something provided they do it the right way.
The other book basically translated the code from python to ruby while keeping much of the text the same I don't know if this is the case with this one.
I don't know at that point what you mean by "unapproved"
http://learncodethehardway.org/
Also, from the linked page:
The prose in this translation is nearly 100% identical to the Python version with the exception of a few paragraphs that have been modified to be relevant to Ruby. All of the code exercises and required libraries have been completely adapted for Ruby. In other words, Zed did all the really hard work.
This isn't quite idiomatic ruby, but I think it'll be a good kick-starter for someone who knows nothing, and I'm looking to get people to help mold it to be better.
Edit: nvm, it's here folks:
https://gitorious.org/learnrubythehardway/learnrubythehardwa...
Cheers!
I know Zed Shaw railed on a previous translation to Ruby; I'd be curious to know the backstory here about why this one is different.
edit: Nevermind, in a different HN thread[1] Zed talks about it.
[1] http://news.ycombinator.com/item?id=2846671
http://twitter.com/#!/zedshaw/status/99151723142184961
It is basically a book of best practices and ruby idioms. (For example, the use of a ruby object's each method instead of for..in.)
Clicking into http://ruby.learncodethehardway.org/intro.html and hitting the title takes me here http://learncodethehardway.org/ruby/
Clicking a link there takes me to http://learncodethehardway.org/ex00.html
It looks like that header should link back to http://ruby.learnruby ...
"You must type each of these exercises in, manually. If you copy and paste, you might as well just not even do them. The point of these exercises is to train your hands, your brain, and your mind in how to read, write, and see code. If you copy-paste, you are cheating yourself out of the effectiveness of the lessons."
http://learnpythonthehardway.org/book/intro.html
Having said that, you could clone the git repository, remove the "linenos" option and run the Jekyll site locally.
But, I was having a problem with exercise 4 and so copy/pasted it from the webpage (removed line numbers with TextMate's vertical selection easily enough). Received the same error when trying to run it as I did when I typed it myself:
ex4.rb:10:in `+': can't convert Fixnum into String (TypeError) from ex4.rb:10:in `<main>'
I'm not familiar enough with Ruby to understand why it's doing that... my googling shows similar ruby tutorials with that format, but one site I found suggested using #{variable_name} instead of the " + variable_name + " and that worked just fine for me.
Is this a real error in the book or something weird going on with my computer (OS X Lion w/ Ruby 1.9.2 installed)?
Great book, by the way.
puts "There are #{cars} cars available."
But, yeah, complete Ruby noob here as well so I don't really know what's wrong.
Yes, this will throw an error in Ruby because of line 1:
>1 cars = 100
Ruby does not allow the mixing of integers and strings. So, as mentioned, you can invoke the .to_s method. Or you can interpolate the variables as you have done so with #{cars} inside double quotes.
This seems to explain it: http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/...
In hindsight, I probably should have used "Hello #{name}" style string interpolation in all of the examples since thats the idiomatic way of doing things.
I was trying to expose the newcomer to multiple ways of manipulating and concatenating strings, but since the aforementioned way is almost always best, I should stick to that.
After about 15 exercises, I saw that it was actually coming out quite nicely and reached out to Zed. Zed was super cool about releasing it under his license as long as the end result was high quality.
I wouldn't have cared if he said not to release it because I got to learn Ruby and play with Sinatra, Jekyll, etc.
Ex. 12 introduces `require` with example code that is way over the reader's head at this point in the book, and unrelated to anything they have seen or will see until ex. 25. It also says that features are called "modules" but that's completely wrong -- Ruby modules are something else entirely. And the term "module" is used in the Python sense all over the book. All those need to be changed.
Ex. 25 asks the reader to require their own file but never explains how to get the file in the load path, so I don't think the reader has much chance of completing this exercise.
My point is that I don't think a direct per-exercise translation is going to work. Requires in Ruby are more complicated and used less often than modules in Python, and the book is very linear, so I think require will have to be introduced in a completely different way if it's going to make any sense.
There are other topics that have this problem, like heredocs. In Python they are pretty so it's ok to throw them at the reader early on. But Ruby heredocs will melt their eyeballs out of their sockets, and they are rarely used in practice, so they probably shouldn't be in the book at all.
I am working on these sorts of changes with the intention of sharing them with you to see what you think, but it's starting to snowball so I don't want to promise anything. I'll do my best.
It's hosted on Rapidshare. I expect Zed will have a better version soon, but this works in a pinch.
Considering that's exactly where I was, it was perfect for me.
He shows you how to do everything...once.
But Zed, please check the Kindle version before you approve it. The Python book for Kindle is absolutely horrible - with all the code stripped out.
ZX Spectrum rocked my world in my childhood :-)
I have never heard of him before, but based on the way Zed wrote about him, seems that he just might be famous and I haven't heard about him (which is very possible).
Otherwise, if he was just a 'regular' web designer that learned Python the Hard Way and translated to Ruby and Zed has given him so much credit....that would be AWESOME.
In all honesty, quite uncharacteristic of Zed - as far as I know, not being a dick (just honest) - which is why I think he is 'programming famous'.
I am hoping he was just a regular 'joe blow' though.
Anyone know?
I don't know Zed personally either. He was a bit skeptical about me doing this at first, but he was ultimately really cool about it because I respected his terms, and if at any time he told me to ditch the book, I would have.
10 There's something going on here. 11 With the three double-quotes
- no triple-double-quotes in ruby version, actually