New to Ruby and Programming

H

Heath Fashina

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
 
J

James Edward Gray II

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

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
 
H

He Fa

James said:
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

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
 
H

Huw Collingbourne

He Fa said:
James Gray wrote:
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


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
 
S

Simen Edvardsen

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.

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

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

Justin Collins

Simen said:
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.

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
 
H

Huw Collingbourne

Simen Edvardsen said:
if you don't understand the concept of a function, programming
is not for you.

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
 
H

He Fa

Simen said:
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.


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/
 
M

Matt Todd

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/
 
D

Daniel Baird

The guy is nuts, but I'm enjoying the ride
http://poignantguide.net/ruby/

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

Chad Perrin

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.

Not just monkeys -- legions of mediocre code monkeys. They're in
cubicles, not cages. Mostly, it's Java shops that have those, though.
 
M

Matt Todd

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

Austin Ziegler

The owner of the Oriental Theater and I signed on the dotted line
today for the unofficial add-on to the 2006 Ruby Conference.
See rubyrouc.com for more details.
Looking for presenters. Presentations can be via internet video
conferencing
link or via video on DVD. Of course being here live is the cat's
pajamas.

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
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,996
Messages
2,570,237
Members
46,825
Latest member
VernonQuy6

Latest Threads

Top