[ANN/ADV] Sample Chapter from "Ruby Best Practices"

Discussion in 'Ruby' started by Gregory Brown, Feb 26, 2009.

  1. == 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_Dynamic_Toolkit.pdf

    == 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.02/whats_in_rbp.html

    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
    Gregory Brown, Feb 26, 2009
    #1
    1. Advertising

  2. Gregory Brown

    James Britt Guest

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


    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
    James Britt, Feb 26, 2009
    #2
    1. Advertising

  3. Gregory Brown

    pat eyler Guest

    On Wed, Feb 25, 2009 at 10:33 PM, James Britt <> wrote=
    :
    > Gregory Brown wrote:
    >>
    >> =3D=3D 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_Dynamic_Toolkit.pdf

    >
    > Jump on this. =A0It'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.



    >
    > --
    > James Britt
    >
    > www.jamesbritt.com =A0 =A0 =A0 =A0 =A0 - Playing with Better Toys
    > www.ruby-doc.org =A0 =A0 =A0 =A0 =A0 =A0 - Ruby Help & Documentation
    > www.rubystuff.com =A0 =A0 =A0 =A0 =A0 =A0- The Ruby Store for Ruby Stuff
    >
    >




    --=20
    thanks,
    -pate
    -------------------------
    Duty makes us do things, Love make us do things well.
    http://on-ruby.blogspot.com
    http://eldersjournal.blogspot.com
    pat eyler, Feb 26, 2009
    #3
  4. Gregory Brown

    James Gray Guest

    On Feb 26, 2009, at 11:05 AM, pat eyler wrote:

    > On Wed, Feb 25, 2009 at 10:33 PM, James Britt
    > <> wrote:
    >> 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_Dynamic_Toolkit.pdf

    >>
    >> 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
    James Gray, Feb 26, 2009
    #4
  5. On Wed, Feb 25, 2009 at 8:24 PM, 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_Dynamic_Toolkit.pdf


    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
    Gregory Brown, Feb 26, 2009
    #5
  6. On Thu, Feb 26, 2009 at 6:05 PM, pat eyler <> 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. =A0Maybe 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.

    --=20
    Pozdrawiam

    Rados=B3aw Bu=B3at
    http://radarek.jogger.pl - m=F3j blog
    Rados³aw Bu³at, Feb 26, 2009
    #6
  7. 2009/2/26 Rados=B3aw Bu=B3at <>:
    > 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
    --=20
    http://antoniocangiano.com - Zen and the Art of Programming
    http://math-blog.com - Mathematics is wonderful!
    http://stacktrace.it - Aperiodico di resistenza informatica
    Follow me on Twitter: http://twitter.com/acangiano
    Recently completed "Ruby on Rails for Microsoft Developers" for Wrox.
    Antonio Cangiano, Feb 26, 2009
    #7
  8. Gregory Brown

    James Gray Guest

    On Feb 26, 2009, at 12:00 PM, Antonio Cangiano wrote:

    > 2009/2/26 Rados=B3aw Bu=B3at <>:
    >> 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 =20
    >> 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_patterns_in_ruby

    James Edward Gray II=
    James Gray, Feb 26, 2009
    #8
  9. 2009/2/26 James Gray <>:
    > On Feb 26, 2009, at 12:00 PM, Antonio Cangiano wrote:
    >
    >> 2009/2/26 Rados=B3aw Bu=B3at <>:
    >>>
    >>> 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_patterns_in_ruby


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

    -greg
    Gregory Brown, Feb 26, 2009
    #9
  10. Gregory Brown

    pat eyler Guest

    2009/2/26 Gregory Brown <>:
    > 2009/2/26 James Gray <>:
    >> On Feb 26, 2009, at 12:00 PM, Antonio Cangiano wrote:
    >>
    >>> 2009/2/26 Rados=B3aw Bu=B3at <>:
    >>>>
    >>>> 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_patterns_in_ruby

    >
    > I've really been wanting to read that book. =A0It 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-interview.html


    >
    > -greg
    >
    >




    --=20
    thanks,
    -pate
    -------------------------
    Duty makes us do things, Love make us do things well.
    http://on-ruby.blogspot.com
    http://eldersjournal.blogspot.com
    pat eyler, Feb 26, 2009
    #10
  11. Gregory Brown

    7stud -- Guest

    Re: Sample Chapter from "Ruby Best Practices"

    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.








    --
    Posted via http://www.ruby-forum.com/.
    7stud --, Feb 26, 2009
    #11
  12. Re: Sample Chapter from "Ruby Best Practices"

    On Thu, Feb 26, 2009 at 3:30 PM, 7stud -- <> 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. =A0The 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. =A0I 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.

    >> =3D=3D Please help me improve the book!
    >>
    >> =A0I 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!! =A0 <-----***
    >
    > You use "Maybe IRB bug!!" in several places, and it doesn't add anything
    > explanatory to the output--quite the contrary. =A0I 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 experi=
    ence.

    > 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
    Gregory Brown, Feb 26, 2009
    #12
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jake
    Replies:
    0
    Views:
    551
  2. Gregory Brown
    Replies:
    0
    Views:
    89
    Gregory Brown
    Jan 10, 2009
  3. Gregory Brown
    Replies:
    29
    Views:
    281
    Gregory Brown
    Apr 16, 2009
  4. Gregory Brown
    Replies:
    1
    Views:
    101
    Todd Benson
    Jun 30, 2009
  5. Tim Chase
    Replies:
    0
    Views:
    70
    Tim Chase
    Feb 16, 2014
Loading...

Share This Page