Forum: Ruby Sample Chapter from "Ruby Best Practices"

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
31e038e4e9330f6c75ccfd1fca8010ee?d=identicon&s=25 Gregory Brown (Guest)
on 2009-02-26 02:24
(Received via mailing list)
== The short story

Hi folks, I bugged O'Reilly to let me release a sample chapter of my
book, and they let me.

So you can now directly download a PDF copy of my "Mastering the
Dynamic Toolkit" chapter without having to go through any hoops:

http://cachefly.oreilly.com/catalogs/Mastering_the...

== For a little background on RBP:

This book is aimed mostly at people with a decent technical grasp of
Ruby but not a ton of practical experience.  The goal is to show how
to attack Ruby problems in the way that a seasoned Rubyist might.
Though it might not be suitable for raw beginners, intermediate Ruby
programmers should be able to learn a lot from the book, and strong
Ruby programmers should *enjoy* it.  I've put together a great
internal review team to help me make sure I reach this goal, and we
also have Rough Cuts set up for general feedback.

== For a little background on this chapter

In the PDF I linked above, you'll find all sorts of meta-programming
and DSL goodness, if not by name.  I try to emphasize how much these
'voodoo' like features can be treated like ordinary Ruby code if you
take some care to do things well.

I chose this chapter to release because it's my favorite.  Most of the
other chapters in the book follow the same general format, though.
That means if you like this one, you'll probably enjoy the others as
welll.

== Please help me improve the book!

 I still have a few weeks to make revisions, so whether you plan on
buying the book or not, feel free to offer some feedback.  I've also
made an agreement with O'Reilly to allow me to release the book under
a creative commons license 9 months after publication.

If after reading the chapter you decide you want to see the whole
thing and offer some suggestion before it goes to print, please buy a
rough cut:

http://rubybestpractices.com

If you want to know exactly what's in the book, you can check out this
blog post:

http://blog.majesticseacreature.com/archives/2009....

Anyway, I'll spam the list only twice more, when the book reaches
content completeness (in a few weeks), and when it goes to print
(hopefully in June).   I hope you enjoy it!

-greg
Ff9e18f0699bf079f1fc91c8d4506438?d=identicon&s=25 James Britt (Guest)
on 2009-02-26 06:34
(Received via mailing list)
Gregory Brown wrote:
> == The short story
>
> Hi folks, I bugged O'Reilly to let me release a sample chapter of my
> book, and they let me.
>
> So you can now directly download a PDF copy of my "Mastering the
> Dynamic Toolkit" chapter without having to go through any hoops:
>
> http://cachefly.oreilly.com/catalogs/Mastering_the...

Jump on this.  It's great stuff.

--
James Britt

www.jamesbritt.com           - Playing with Better Toys
www.ruby-doc.org             - Ruby Help & Documentation
www.rubystuff.com            - The Ruby Store for Ruby Stuff
Bb6ecee0238ef2461bef3416722b35c5?d=identicon&s=25 pat eyler (Guest)
on 2009-02-26 18:13
(Received via mailing list)
On Wed, Feb 25, 2009 at 10:33 PM, James Britt <james.britt@gmail.com>
wrote:
>> http://cachefly.oreilly.com/catalogs/Mastering_the...
>
> Jump on this.  It's great stuff.


Seconded, I've seen several of the chapters and talked with Gregory
about this and it's quality.

Ruby books haven't been doing well of late (sales are down 51%
over last year), so it's good to see a good book that the community
can get behind.  Maybe this will help reverse the trend.
4299e35bacef054df40583da2d51edea?d=identicon&s=25 James Gray (bbazzarrakk)
on 2009-02-26 18:19
(Received via mailing list)
On Feb 26, 2009, at 11:05 AM, pat eyler wrote:

>>> Dynamic Toolkit" chapter without having to go through any hoops:
>>>
>>> http://cachefly.oreilly.com/catalogs/Mastering_the...
>>
>> Jump on this.  It's great stuff.
>
>
> Seconded, I've seen several of the chapters and talked with Gregory
> about this and it's quality.

Agreed.  It's been a great project to be an early reviewer on.

James Edward Gray II
31e038e4e9330f6c75ccfd1fca8010ee?d=identicon&s=25 Gregory Brown (Guest)
on 2009-02-26 18:26
(Received via mailing list)
On Wed, Feb 25, 2009 at 8:24 PM, Gregory Brown
<gregory.t.brown@gmail.com> wrote:
> == The short story
>
> Hi folks, I bugged O'Reilly to let me release a sample chapter of my
> book, and they let me.
>
> So you can now directly download a PDF copy of my "Mastering the
> Dynamic Toolkit" chapter without having to go through any hoops:
>
> http://cachefly.oreilly.com/catalogs/Mastering_the...

I forgot to mention that for the twitter inclined, you can find book
announcements at:
http://twitter.com/rubypractices

Now I'll really stop with the self-promotion :)

-greg
Aaca034456897ccbc8bb14953c4a41c1?d=identicon&s=25 Radosław Bułat (radarek)
on 2009-02-26 18:49
(Received via mailing list)
On Thu, Feb 26, 2009 at 6:05 PM, pat eyler <pat.eyler@gmail.com> wrote:
> Ruby books haven't been doing well of late (sales are down 51%
> over last year), so it's good to see a good book that the community
> can get behind.  Maybe this will help reverse the trend.

Mu guess is that there are too many books that describe only ruby (as
a language) and rails (I'm pretty sure that there are more books about
rails than ruby itself... - it's paradox :)). Gregg's books should be
shiny gem in ruby books land.

--
Pozdrawiam

Rados³aw Bu³at
http://radarek.jogger.pl - mój blog
6111b4012d1401ca83fdcea6b1d71237?d=identicon&s=25 Antonio Cangiano (Guest)
on 2009-02-26 19:02
(Received via mailing list)
2009/2/26 Rados³aw Bu³at <radek.bulat@gmail.com>:
> My guess is that there are too many books that describe only ruby (as
> a language) and rails (I'm pretty sure that there are more books about
> rails than ruby itself... - it's paradox :)). Gregg's books should be
> shiny gem in ruby books land.

IMHO, "Design Patterns in Ruby" by Russ Olsen is another shiny gem.

Cheers,
Antonio
4299e35bacef054df40583da2d51edea?d=identicon&s=25 James Gray (bbazzarrakk)
on 2009-02-26 19:39
(Received via mailing list)
On Feb 26, 2009, at 12:00 PM, Antonio Cangiano wrote:

> 2009/2/26 Rados³aw Bu³at <radek.bulat@gmail.com>:
>> My guess is that there are too many books that describe only ruby (as
>> a language) and rails (I'm pretty sure that there are more books
>> about
>> rails than ruby itself... - it's paradox :)). Gregg's books should be
>> shiny gem in ruby books land.
>
> IMHO, "Design Patterns in Ruby" by Russ Olsen is another shiny gem.

I agree:

http://blog.grayproductions.net/articles/design_pa...

James Edward Gray II
31e038e4e9330f6c75ccfd1fca8010ee?d=identicon&s=25 Gregory Brown (Guest)
on 2009-02-26 19:51
(Received via mailing list)
2009/2/26 James Gray <james@grayproductions.net>:
>
> I agree:
>
> http://blog.grayproductions.net/articles/design_pa...

I've really been wanting to read that book.  It sounds awesome.

-greg
Bb6ecee0238ef2461bef3416722b35c5?d=identicon&s=25 pat eyler (Guest)
on 2009-02-26 20:22
(Received via mailing list)
2009/2/26 Gregory Brown <gregory.t.brown@gmail.com>:
>>> IMHO, "Design Patterns in Ruby" by Russ Olsen is another shiny gem.
>>
>> I agree:
>>
>> http://blog.grayproductions.net/articles/design_pa...
>
> I've really been wanting to read that book.  It sounds awesome.

It is pretty awesome.  If you want a short taste, here's the interview I
did with Russ:

http://on-ruby.blogspot.com/2008/01/russ-olsen-int...
54404bcac0f45bf1c8e8b827cd9bb709?d=identicon&s=25 7stud -- (7stud)
on 2009-02-26 21:31
Gregory Brown wrote:
>
> This book is aimed mostly at people with a decent technical grasp of
> Ruby but not a ton of practical experience.  The goal is to show how
> to attack Ruby problems in the way that a seasoned Rubyist might.
>

I have just about 0 technical grasp of ruby, but so far I can understand
everything in your example chapter.  I did have to look up a few things
in pickaxe2.


>
> == Please help me improve the book!
>
>  I still have a few weeks to make revisions, so whether you plan on
> buying the book or not, feel free to offer some feedback.

Ok, here goes.

1) In this sentence:

"Builder works by capturing calls to missing methods, but if a method is
actually defined, it’d have trouble doing its magic."

The contraction "it'd" is awkward and rarely used in conversation or in
writing.  Substitute "it would" instead.

2) This sentence:

"For example: if XmlMarkup were just a subclass of Object, with no
methods removed, you wouldn't be able produce this XML, due to the
naming conflict."

The phrase 'this XML' had me looking up--instead of down.  It would be
clearer to me if the sentence was changed to this:

"For example, if XmlMarkup were just a subclass of Object with no
methods removed, you wouldn't be able produce **the following** XML due
to **a** naming conflict."


3) Error here:

"The technique used here is simply to initialize a hidden_methods hash
within the class, and then assign **then** method name as a key to the
associated UnboundMethod object."

That seems to be a common error in the text.  You should do a search for
'then' to find similar errors.

Also, the "a @hidden_methods" phrase is awkward.  An alternative:

"The technique used here is simply to initialize a method named
@hidden_methods with a hash..."

I think the phrase 'within the class' is redundant, so that could be
eliminated to make the sentence approximately the same length.

4) I found this confusing:

>> A.new
NoMethodError: undefined method `inspect' for #<A:0x42ac34>
...
Maybe IRB bug!!   <-----***

You use "Maybe IRB bug!!" in several places, and it doesn't add anything
explanatory to the output--quite the contrary.  I found it confusing.

5) I found the following example more confusing than what it was trying
to explain:

-----
Think of this as a much higher-level version of simple temporary
state modification that mirrors this structure:

>> x = 10
=> 10
>> old_x, x  = x, nil
=> [10, nil]
>> x.nil?
=> true
>> x = old_x
=> 10
---------

I think the parallel assignment makes it hard to track what's going on.
If the reader is such a beginner that you need to spell out how to save
a value and then later restore it, how about doing it with absolute
crystal clarity(which in my opinion can't be done with irb output):

x = "hello"
old_x = x

x = 30
puts x   #30

x = old_x
puts x   #"hello"

Personally, I think the original explanation was clear enough, and this
example should be binned.
31e038e4e9330f6c75ccfd1fca8010ee?d=identicon&s=25 Gregory Brown (Guest)
on 2009-02-26 21:48
(Received via mailing list)
On Thu, Feb 26, 2009 at 3:30 PM, 7stud -- <bbxx789_05ss@yahoo.com>
wrote:
> Gregory Brown wrote:
>>
>> This book is aimed mostly at people with a decent technical grasp of
>> Ruby but not a ton of practical experience.  The goal is to show how
>> to attack Ruby problems in the way that a seasoned Rubyist might.
>>
>
> I have just about 0 technical grasp of ruby, but so far I can understand
> everything in your example chapter.  I did have to look up a few things
> in pickaxe2.

That's great.  If you can read this chapter with a reference to dive
into when you need it, then you'll have no trouble with the whole
book.  My disclaimer is mostly because I don't make any effort to
include 'beginner ruby' content, but it may not be as difficult to
approach as I make it sound for those who are willing to look things
up.

>> == Please help me improve the book!
>>
>>  I still have a few weeks to make revisions, so whether you plan on
>> buying the book or not, feel free to offer some feedback.
>
> Ok, here goes.

For the grammatical corrections, I'll make all of them.  I should have
put a disclaimer that this hasn't gone through O'Reilly's proofreaders
yet, only the internal tech review team I set up.  So the typos and
bad grammar are all my fault, and will be corrected before we print,
hopefully.  Of course, those who have signed up for roughcuts or read
this free chapter are still encouraged to point out these issues.  The
more I fix before I hand the draft over, the better.

> 4) I found this confusing:
>
>>> A.new
> NoMethodError: undefined method `inspect' for #<A:0x42ac34>
> ...
> Maybe IRB bug!!   <-----***
>
> You use "Maybe IRB bug!!" in several places, and it doesn't add anything
> explanatory to the output--quite the contrary.  I found it confusing.

It's part of the actual irb output, so that's just verbatim copying,
not added commentary. I agree though.  Take it up with ruby-core :)

> 5) I found the following example more confusing than what it was trying
> to explain:

> I think the parallel assignment makes it hard to track what's going on.
> If the reader is such a beginner that you need to spell out how to save
> a value and then later restore it, how about doing it with absolute
> crystal clarity(which in my opinion can't be done with irb output):

You're right... I shouldn't be expecting the reader to not have this
experience.

> Personally, I think the original explanation was clear enough, and this
> example should be binned.

So, actually... there are more than a few cases where an internal tech
reviewer pointed something out, and I said "If a reader points this
out, I'll make the change".  This is one of them.  Consider that
example slashed.

Thanks for the great feedback.

-greg
This topic is locked and can not be replied to.