New to Ruby and Programming

Discussion in 'Ruby' started by Heath Fashina, Aug 16, 2006.

  1. Hi,

    I am making yet another attempt at learning to program. I have a
    little experience with QBASIC, RealBASIC, and Actionscript, but I am
    pretty much a novice.

    I am working my way through Chris Pine's tutorial but I'm stuck on Procs
    and Blocks. I'm just not getting the last half of the chapter.

    http://pine.fm/LearnToProgram/

    Any guidance or detail explanation would be appreciated
     
    Heath Fashina, Aug 16, 2006
    #1
    1. Advertisements

  2. I wrote a blog post on this subject a while back that might at least
    give you another point of view:

    http://blog.grayproductions.net/articles/2006/01/05/code-as-a-data-type

    Hope it helps.

    James Edward Gray II
     
    James Edward Gray II, Aug 16, 2006
    #2
    1. Advertisements

  3. Heath Fashina

    He Fa Guest

    I have very limited knowledge with databases (i.e. filemaker pro and
    some Access). I decided to just press on with my loose grasp of procs
    and blocks and dive into:

    "Programming Ruby:The Pragmatic Programmer's Guide, First Edition (*)

    Hopefully, it'll just hit me or I'll have to find a new hobby
     
    He Fa, Aug 16, 2006
    #3

  4. I suspect you may be getting a bit too obsessive about those darn' blocks
    and procs. While blocks can be useful for all kinds of things, they are not
    'central' to programming in Ruby. Some Ruby programmers tend to get a bit
    obsessive about blocks, procs, lambda functions and the like. If you find
    this stuff baffling (and unless you already have experience of a language
    such as Smalltalk or Scheme in which blocks are a 'natural' part of the
    language), they may initially seem very baffling indeed, my advice would be
    to use blocks only where they are absolutely required - namely, for
    iterating over collections of things as when, for example, iterating over
    the items in an array using the each() method.

    I wouldn't worry at all about using blocks as 'nameless functions' or
    passing and 'yielding' them. These can be useful in certain circumstances
    but then again, you could spend a lifetime doing perfectly productive
    programming in Ruby without ever doing any of those things ;-)

    You may perhaps find my book, The Little Book Of Ruby, of some help. This is
    a free PDF book which you can download from: www.sapphiresteel.com

    While my book covers most of the essentials of Ruby - including things that
    often stump newcomers (blocks, mixins etc.) I've tried to keep restrict it
    to the essential details; you can also download all the source code for all
    the sample programs (personally, it's my feeling that programming topics are
    often easier to understand when you can try them out for yourself).

    best wishes
    Huw Collingbourne

    http://www.sapphiresteel.com
    Ruby Programming In Visual Studio 2005
     
    Huw Collingbourne, Aug 16, 2006
    #4
  5. Heath Fashina

    He Fa Guest

    Hey Thanks,

    I will definately check that out!
     
    He Fa, Aug 16, 2006
    #5
  6. Ruby's standard library is filled with methods that (often optionally)
    take blocks as arguments. Ignoring them isn't gonna do you any good. A
    closure is a function that remembers the environment it was defined
    in, and if you don't understand the concept of a function, programming
    is not for you.
    Ignoring closures, which are extensively used within Ruby's standard
    library and a large part in what makes the language so good for many
    tasks, is not going to do you any good at all.
     
    Simen Edvardsen, Aug 16, 2006
    #6
  7. Perhaps not, but it's like that advice they give for taking tests...if
    you find yourself getting hung up on a particular question, skip it and
    come back to it later.
    Except, you have much more time to skip blocks/closures for now and come
    back to them later than problems on a test.
    If it doesn't make sense now, get familiar with other parts of Ruby and
    then come back to blocks, if it's getting frustrating.

    -Justin
     
    Justin Collins, Aug 16, 2006
    #7
  8. I would agree that the concept of a function (or method) is essential. I
    don't agree that a beginner should be required to understand (or attempt to
    use) blocks to any great extent beyond their role in iteration.

    best wishes
    Huw Collingbourne

    http://www.sapphiresteel.com
    Ruby Programming In Visual Studio 2005
     
    Huw Collingbourne, Aug 16, 2006
    #8
  9. Heath Fashina

    He Fa Guest


    Fortunately, I do understand functions. I tend to understand most
    things when explained thoroughly and using plain english. Or in the
    case of http://poignantguide.net/ruby/ using oddball stories mixed
    with tidbits of Ruby code.

    The guy is nuts, but I'm enjoying the ride

    http://poignantguide.net/ruby/
     
    He Fa, Aug 17, 2006
    #9
  10. Heath Fashina

    Matt Todd Guest

    Whether it is completely correct or not, I like to look at blocks as
    little functions that I pass to another function as an argument, just
    like I'd pass it a number or another object.

    The distinction, though, is how that block of code is called, and that
    that block of code can still access the variables you have laying
    around where that block of code was called. It's like rewriting part
    of the insides of another function!

    As I said, the details are a bit more, well, detailed, and tricky,
    too, but, as a very simple explaination, it works.

    Now, as a way to get more familiar with it, I'd definitily check out
    the Poignant Guide[1] and also _Why[2]'s TryRuby[3] interactive
    walkthrough.

    M.T.

    1. http://poignantguide.net/
    2. http://redhanded.hobix.com/
    3. http://tryruby.hobix.com/
     
    Matt Todd, Aug 17, 2006
    #10
  11. Heath Fashina

    Daniel Baird Guest

    you should watch what you say about _why.. I've heard he sends his
    winged monkeys after people who offend him.

    Or someone else does that. Maybe I read it somewhere. What's
    important here is that someone has got monkeys with wings. In a cage,
    I assume.
     
    Daniel Baird, Aug 17, 2006
    #11
  12. Heath Fashina

    Chad Perrin Guest

    Not just monkeys -- legions of mediocre code monkeys. They're in
    cubicles, not cages. Mostly, it's Java shops that have those, though.
     
    Chad Perrin, Aug 17, 2006
    #12
  13. Heath Fashina

    Matt Todd Guest

    Fortunately, _Why is masterful enough to confuse them with strange
    Rubyisms like 10.method:)+).call(20) while obfuscating their mind-code
    and enslaving them to dwell on Javacs all day long. That and he feeds
    them yummy noodles.

    Hail javacs! I mean, _why! I wish you'd appear out of nowhere in
    Atlanta at a random coder BBQ! ;)

    M.T.
     
    Matt Todd, Aug 17, 2006
    #13
  14. I notice that you have not yet removed unnecessary attacks on members
    of the Ruby community from the website.

    Antagonizing the community will win you no friends.

    -austin
     
    Austin Ziegler, Aug 18, 2006
    #14
    1. Advertisements

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.