Created
August 4, 2011 22:20
-
-
Save jneen/1126440 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ex05: | |
A minor thing, but ruby programmers almost never use string formatters. I find #{} interpolation to be prettier and easier to understand. | |
ex09: | |
minor: in the heredoc text there's a reference to "three quotes", which aren't actually there. | |
ex12: | |
The word 'module' is used to describe the 'open-uri' library. In Ruby, libraries *usually* define modules, but modules are actually much more general, and an important concept to learn in their own right. The extra credit does say to learn the difference between "require" and "include", but these are such different concepts in Ruby that I think overloading the term at the beginning just sets up the student for confusion later. | |
require 'open-uri' # this is a library that we are ensuring is available. Often these come from "gems". | |
# it references a file named 'open-uri.rb' that is read and evaluated in the global scope | |
# (this is *very* different from python, which sets up a local scope per file). | |
module MyCoolModule # this, OTOH, is a module. | |
# _why used to call modules "buckets of methods", which is fairly accurate, and good enough for a beginner. | |
# they can be included in classes and in other modules, or used to extend objects (incl. classes and modules). | |
end | |
m = Module.new # this is also a module | |
ex29: | |
It'd be nice to hint, at least in the extra credit, that if statements are expressions, just like everything else: | |
foo = if 1 < 2 | |
'sanity' | |
else | |
'omg, wrong universe' | |
end | |
puts foo # => sanity | |
ex25: | |
In Ruby, this is very confusing, and it only made sense to me when I tried to think of the Python equivalent, which is actually pretty easy. To understand the ruby code in Ex25, you need to know about modules (the `include` kind, not the `require` kind), implicit self, metaclasses, and the metaclass `def` syntax, *and* you have to be able to think of them all at the same time. Perhaps the methods could be moved into the global namespace, or this exercise could be postponed until after these have been discussed...? | |
ex32: | |
As I'm sure you know, for..in loops are considered bad practice in Ruby. Aside from the weird destructuring rules and the lack of a constrained variable scope, it distracts from one of Ruby's main points of awesomeness: the Enumerable library. Learning how to use .each is harder, but much more useful when you get to learning about Enumerable. There is one example using .each, but it's sort of mentioned in passing and then forgotten. | |
ex40: | |
The method-in-a-hash thing is a lot more useful in Python than it is in Ruby. While it's possible, the concept is not quite as important and mind-blowing once it's been translated. Ruby methods don't have closures, they're generally bound to a secret "self" somewhere, and are pretty cumbersome to access (`method(:foo)`). Much of the power that Python gets from having closured, first-class functions, Ruby achieves by using blocks (aka "lambdas", aka "procs"). Perhaps a discussion of these is in order? I think it would be prudent to discuss blocks at least sometime before they start using Sinatra. | |
In general: | |
I realize this is a lot of stuff, and most of these don't have obvious solitions. I've forked the repo on Gitorious, and I'll see if I can come up with something a little more concrete to propose. LPTHW is an awesome introduction to most of the things that are awesome about Python, but the things that are awesome about Ruby are not necessarily the same things. ...and maybe someone just needs to write their own damn book about Ruby. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment