[Tfug] Language choices
Chris Niswander
cn.tfug.account at bitboost.com
Mon Oct 30 04:43:06 MST 2006
Warning: This message provides NO useful information about M L or R E X X!
At 08:47 PM 10/29/2006 -0600, you wrote:
>On Sat, 28 Oct 2006 16:38:18, Chris Niswander <cn.tfug.account at bitboost.com>
>wrote:
>>
>> >for node in nodes: print node
>> > v.
>> >nodes.each { }node| puts node }
>>
>> So, in this context, what do you mean by "more correct"?
>
>
>"More correct" isn't "more correct". It's more powerful, better for
>programmers, smarter in its way. When you're used to blocks, you can hardly
>stand not having them.. Blocks are a very powerful abstraction, and make
>writing code a lot simpler and more clean for people who are block-infected.
>
>I'm sorry that it sounded like there was some kind of formal correctness
>proof.
>
>I think that the first one is easier for people to grasp. I think that
>probably makes it "a more correct choice" for people who aren't programmers,
>like visual basic users. ;-)
Oh, I think you could compose an informal proof that the syntax
nodes.each { |node| puts node }
^
is actually more correct (maybe even clearer!) than
>> >nodes.each { }node| puts node }
>;-)
I'm no Ruby expert, but it looks to me like:
1. The word "block" has long been used in other languages (e.g. C)
to mean something somewhat different from Ruby-style blocks.
For example,
while (i)
{ // this is a 4-line ...
icky = scratchy(i); // C-style "block"
i = squamous(icky.yuck()); // it doesn't take parameters really
...
} // it's not a function def ...
2. Talking about "blocks" as if Ruby-style blocks
were the first and only type that ever existed
invites confusion and/or statements that are *arguably* false or
misleading,
IMHO. Maybe a different term should be used, such as "Ruby-style blocks"?
3. It looks like Ruby supports a syntax in which a 'block'
has the exact same syntax as an anonymous function's definition,
except that a single keyword is left off the front, and the
syntax of either is very similar to a non-anonymous function's definition,
and any of these is fairly terse.
4. I think the observation (by Ruby's designer?) that blocks and anonymous
function definitions are really the same kind of thing, and can be written
with exactly the same (reasonably terse and clear) syntax, is a nice
discovered orthogonality that must provide some benefits.
I doubt I'm the only person who has ever written a loop body,
elaborated it, and then said, "It might be kind of good
to turn this loop body [a block] into a function so I can
(re)use it elsewhere (without splitting it into multiple copies)."
This happened to me a day or two ago, but I was writing in Python,
where as in most languages the conversion takes somewhat more work
(more typing after the cut and paste) so I haven't gotten around to it.
:-)
But from your explanation I don't really have a specific feel for other
benefits, just a very vague suspicion that there might be more benefits
than I know of. :-)
Do you happen to know of a good explanation with more details, to which
you could link? So far I've found some iffy/partial explanations
elsewhere. :-)
5. Also, I found a code example
[1,2,3].delete_if{|x| x == 1} # => [2,3]
and I'm thinking, does Ruby really have a specific loop operator (well,
I guess really a specific method of the standard libraries' collection
classes)
for deleting some items from a list based on a conditional?
What kind of crazy language standard would expect people to
memorize stuff that specific instead of writing it on the fly as needed?
I can't help but think that rather than memorize such specific operators,
I might rather write something like Python-style list comprehensions, e.g.
[x for x in [1,2,3] if x != 1] # written in a few seconds, worked
1st time.
although, frankly, I thought Python list comprehension syntax was a bit
unobvious when I first encountered it, and I still suspect that a better
syntax
could (should?) be designed.
(Please note: I do *not* intend to suggest that Python-style list
comprehensions as-is somehow provide a universal substitute for Ruby
blocks.)
6. Care to kindly correct or elaborate any of this?
Sincrely,
Chris
More information about the tfug
mailing list