Hacker News new | past | comments | ask | show | jobs | submit login
Zed Shaw: The wonderful Rob Sobers did a great job translating LPTHW to Ruby (learncodethehardway.org)
327 points by knowtheory on Aug 4, 2011 | hide | past | favorite | 65 comments



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.


Would you prefer minor copy edits to come in the form of pull requests, or just comments?


Pull requests work best since there are other contributors now. Thanks!


There was an unapproved translation before, IIRC. I guess this is out because the adapter asked Zed's permission first and kept the copyright?

If 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.


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.


How can we help? I can't find the source for this on Gitorious.

Edit: nvm, it's here folks:

https://gitorious.org/learnrubythehardway/learnrubythehardwa...

Cheers!


The main thing is, help improve the ruby code with the least number of changes. I'll have a guide written up today for folks who want to help.



Anyone doing a Perl version or a !GASP! Tcl version?


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.


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.


Uh, given that Zed tweeted this out, and it's up on the learncodethehardway.org domain, this at least has Zed's tacit blessing.

I don't know at that point what you mean by "unapproved"


This looks like an approved translation to me:

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.


It's approved - check the domain (same as LPTHW)



(side note, there seems to be a page linking problem)

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 ...


Fixed. I had to move it to ruby.lcthw.org to keep the various languages straight, but I didn't update the jekyll _config.yml.


similar problem in exercise 26. It contains a link to http://learncodethehardway.com/ruby/exercise26.txt, which doesn't exist (and is the wrong domain anyways).


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)


I wanted one too, so I PDF-printed all the pages, combined them into one file and also made a Kindle version: http://bit.ly/o7gfMH

It's hosted on Rapidshare. I expect Zed will have a better version soon, but this works in a pinch.


I work with Rob. I always knew he was awesome, but I didn't realize he was this awesome. Great job Rob!


Is there a particular reason pagination navigation is not used (e.g. at the bottom of each page, including previous/next links)?


No particular reason. I'll probably add this at some point since it's pretty helpful.


Here's a pretty rough and ready bookmarklet to add them: http://jsfiddle.net/FVAYG/2/


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 :)!


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.

Anyone know?


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.


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.


Because Zed Shaw's original book makes learning Python so easy for anyone without assuming any prior knowledge, plus he's hilarious.


He assumes you are a very bright person who happens to be utterly helpless about this domain.

Considering that's exactly where I was, it was perfect for me.

He shows you how to do everything...once.


The reason is Zed Shaw. He has a large following here on HN.


And it's a pretty decent way to learn some basic programming skills, irrelevant of the actual language.


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.

ZX Spectrum rocked my world in my childhood :-)


I typed in CBM64 programs - not sure how helpful it was in learning to code though...

  2000 DATA 103, 20, 122, 58, 53, 240, 188, 86, ...
[ctd for 8 pages]...


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 ... ;-)


Where is the source for the quote from Zed Shaw? The link doesn't mention it at all.

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


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 can't speak specifically to how idiomatic it is as I've yet to read it, but I've heard http://www.amazon.com/Eloquent-Ruby-Addison-Wesley-Professio... recommended a few times.


I am not sure, but I'll ask some Ruby folks who might know and then update the book to point people in the right direction.


The title Eloquent Ruby has been getting excellent reviews by beginners and Rubyists alike. And I happened to have loved reading it.

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.)


Apologies i figured a link to the site was more useful than the link to the tweet:

http://twitter.com/#!/zedshaw/status/99151723142184961


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?


@zedshaw Would you be up for a Factor version done with the same spirit and quality?


Exercise 9:

10 There's something going on here. 11 With the three double-quotes

- no triple-double-quotes in ruby version, actually


I would buy it for Kindle!


Yeah, I would too.

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.


Great thanks Rob!


It would be nice to be able to copy and paste the code snippets without the line numbers. Otherwise great job!


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."

http://learnpythonthehardway.org/book/intro.html


The point of The Hard Way methodology is to type everything out and understand what you're doing.

Having said that, you could clone the git repository, remove the "linenos" option and run the Jekyll site locally.


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)?

Great book, by the way.


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.


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.

This seems to explain it: http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/...


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.


to be clear, my line 10 looks like this:

puts "There are #{cars} cars available."

But, yeah, complete Ruby noob here as well so I don't really know what's wrong.


>10 puts "There are " + cars + " cars available."

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.


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.


Thank you, that makes sense.


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.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: