A crosspost from the Perl Community

David Masover wrote:

···

On Friday 06 June 2008 12:21:08 Marc Heiler wrote:

Then we compare our solutions. (Only "in-built" stuff is allowed, i.e.
no cpan modules rubygems etc... things would have to be used from
scratch, so that no language gains an inherent advantage over the other)

That would still potentially be a comparison of standard libraries. And
you
can't get away from that, really.

But it is a valid point that beauty is in the eye of the beholder.
Almost no
one I know who's seen Ruby code argues that Perl is better

We all live in certain communities and we tend to socialize with people
we have something in common with. So it's not such a surprise that a
Ruby programmer knows a lot of people who like Ruby :wink:
--
Posted via http://www.ruby-forum.com/\.

David A. Black wrote:

I think the word is "troll" :slight_smile:

Let's change the subject line, too.

···

--
       vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407

[...]

The only complaint I can have about ruby is that the documentation could
always be improved. The Pickaxe is great, but I think a language should
have at least a great online and up-to-date reference, similar to php,
on the official site.

  Indeed. I really need this!

  rdoc & ri & irb are great, but php.net/function-name is almost perfect with
examples and comments and description and parameters and return values.

  Best regards,

···

Em Friday 13 June 2008, Marc Heiler escreveu:
--
Davi Vidal
--
E-mail: davividal@siscompar.com.br
MSN : davividal@msn.com
GTalk : davividal@gmail.com
Skype : davi vidal
YIM : davi_vidal
ICQ : 138815296

Hi --

Did you just join this mailing list to be a douchebag?

I think the word is "troll" :slight_smile:

Right, Jenda is one of the most intelligent trolls I have ever seen,
he takes care to write some reasonable posts once in a while and then
he just continues to waste bandwith and all the nice things trolls do,
unless his brain has an on-off switch of course.
Please be aware that I do by no means indicate that he has a brain,
this is beyond my abilities to prove, but as I have called him
intelligent he probably has one, unless he found a ghost writer for
the non trollish posts.

I really feel it is good to have him around, makes this list more like
real life, full of people one would consider calling bad names. I do
not do that however because we have a nice saying here in France:
"Stupid is a property of people who do not think like you" (well
language is actually worse "Un con c'est quelqu'un qui pense
differement que toi").

Dear Kenda maybe you can however find other things to do for some
while, I guess you harmed yourself enough for now.
And just in case you did not notice, this is a non sigil language
mailing list, so you probably posted by error. Do not apologize
however as you are forgiven already :).

Cheers and keep not seeing you out there.
Robert

···

On Fri, Jun 13, 2008 at 9:17 PM, David A. Black <dblack@rubypal.com> wrote:

On Sat, 14 Jun 2008, Jeremy McAnally wrote:

David

--
Rails training from David A. Black and Ruby Power and Light:
ADVANCING WITH RAILS June 16-19 Berlin
ADVANCING WITH RAILS July 21-24 Edison, NJ
See http://www.rubypal.com for details and updates!

--
http://ruby-smalltalk.blogspot.com/

---
As simple as possible, but not simpler.
Albert Einstein

From: "Jenda Krynicky" <jenda@cpan.org>
I don't think people get drawn to Ruby because of pretty syntax. I think it's all marketing. Ruby on Rails is (or is it still?) hip. The new cool kid on the block.

To paraphrase David Heinemeier Hansson, "f*ck rails."

<grin>

Apologies for replying to my own post - but it's been bothering me that I forgot
to add a footnote to explain my comment above. And so I worried it might have
sounded harsh to those not familiar with the event my comment puns on.

Thus, here's the footnote I might ought to have included:
http://blog.wekeroad.com/blog/imploding-rails-jesus-dhh-and-the-uncle-ben-principle/
http://www.codinghorror.com/blog/archives/001065.html
(scroll down about a page)

All in fun,

Bill

···

From: "Bill Kelly" <billk@cts.com>

another solution: a) pass the node containing the link you want to
operate along with something saying which link in the node (you'll
probably also need a dummy node at the root/head), b) have a separate
object for the link so you can pass it around (i.e. simply an Array of
one element), c) pass a lambda that can modify the link. None of
these are as elegant as an lvalue reference IMHO. In my early ruby
days a few years ago I put some code in the rubyforge "reference"
project. I still think having something like this readily available
would be useful.

The usual solution in Ruby would probably be a) which I find perfectly ok.
Since the manipulation is typically encapsulated inside a LinkedList class
it does not bother me too much if there are two additional elements (for
head and tail). :slight_smile: But I can see how this might be a bit more elegant with
references (although not as much to create an urgent need for references in
Ruby). :slight_smile:

Definitely no urgent need, but a nice thing to have in a bag of
tricks. It could be implemented in Ruby, but you'll get more
efficiency if done in C (ruby implementation would typically need eval
- at least for local vars). No special syntax needed.

External iterators are also like lvalue references and is something
ruby is missing (IMHO).

Is it?

irb(main):027:0> require 'generator'
=> true
irb(main):028:0> arr = %w{foo bar baz}
=> ["foo", "bar", "baz"]
irb(main):029:0> it = Generator.new arr
=> #<Generator:0x1002ffe8 @cont_endp=nil, @index=0,
@block=#<Proc:0x1001bbc4@/usr/lib/ruby/1.8/generator.rb:71>,
@cont_yield=#<Continuation:0x1002f5fc>, @cont_next=nil, @queue=["foo"]>
irb(main):030:0> until it.end?; puts it.current; it.next; end
foo
bar
baz
=> nil

This just gives a very limited external iterator that can read and
move forward (just like an internal iterator). In C++ terms, this
corresponds to one of the simplest - "Input Iterator". Other
operations you might want to do where the iterator is at would be:
write, move back, insert, delete, random access.

An external iterator could be thought of as a
superset of the reference/pointer concept (external iterator looks
like a pointer in C++).

Which is nicely done (in C++'s STL, I mean). But with blocks I don't really
miss external iterators. I rarely have to iterate through multiple
collections in lock step and if I had #zip served me well.

#zip doesn't help if you want to write, back-up, insert, delete, etc
during iteration.

Maybe I'm just not doing enough development that involves sophisticated
algorithms. :slight_smile:

Well, the last year or so I've been exposed to quite a bit of
computational geometry and graph theory. Most of that has been in C++
and a bit of Python (would have used Ruby, but needed a certain API).
Outside of that, my experience would say the same as you. Usually
simple data structures and access methods suffice.

Eric

···

On Fri, Jun 6, 2008 at 10:49 AM, Robert Klemme <shortcutter@googlemail.com> wrote:

On 06.06.2008 17:01, Eric Mahurin wrote:

Todd Benson wrote:

Who's gonna be the judge? Besides, define cleaner!

No matter the solutions, the Ruby ones will look cleaner to the Ruby
proponents and the Perl one to the Perl ones. There's nothing to be
gained from this exercise.

You would need a third party.

Todd

Someone who doesn't know either language?

Yes

Which would not help much
'cause that someone needs to know at least some other programming
language to have any idea whatsoever what's going on in here and then
which ever's closer to his/her language wins.

Agreed.

Spanish makes more sense that English to a portuguese that doesn't know
either, does it say anything about the relative complexity of the two
languages?

Beauty contests are a nice pretext for watching a few chicks in swimwear
(or wet tshirts), but it's not a way to find the most beautiful girl of
the USA in the year 2008. Cause there is no such thing.

Also, here I agree.

In any situation, you need a context for beauty, which you pointed
out. I was subtly suggesting that if you remove the context, then
everyone would be on a level playing field.

What would you suggest? A pissing contest? Just curious.

Todd

···

On Fri, Jun 6, 2008 at 7:47 PM, Jenda Krynicky <jenda@cpan.org> wrote:

On Fri, Jun 6, 2008 at 1:27 PM, Jenda Krynicky <jenda@cpan.org> wrote:

Wouldn't be better leave thread die? JMO...

···

Em Friday 13 June 2008, Joel VanderWerf escreveu:

David A. Black wrote:
> I think the word is "troll" :slight_smile:

Let's change the subject line, too.

--
Davi Vidal
--
E-mail: davividal@siscompar.com.br
MSN : davividal@msn.com
GTalk : davividal@gmail.com
Skype : davi vidal
YIM : davi_vidal
ICQ : 138815296

Is that what they mean by cross-fertiliser?

martin

···

On Fri, Jun 13, 2008 at 12:23 PM, Joel VanderWerf <vjoel@path.berkeley.edu> wrote:

David A. Black wrote:

I think the word is "troll" :slight_smile:

Let's change the subject line, too.

What's the actual procedure for improving Ruby's docs? Is there a doc
team? If there is, is it active? If it is, does it accept suggestions,
patches and/or wholesale chapters? If so, and here's the key part, is
it actually possible to contribute without a huge bureaucratic
nightmare?

A lot of communities fail on that last point. Is Ruby's one of them?
(I am asking because I don't know, not because I think this is the
case.)

···

On Sat, 2008-06-14 at 04:43 +0900, Davi Vidal wrote:

> The only complaint I can have about ruby is that the documentation could
> always be improved. The Pickaxe is great, but I think a language should
> have at least a great online and up-to-date reference, similar to php,
> on the official site.

  Indeed. I really need this!

  rdoc & ri & irb are great, but php.net/function-name is almost perfect with
examples and comments and description and parameters and return values.

--
Michael T. Richter <ttmrichter@gmail.com> (GoogleTalk:
ttmrichter@gmail.com)
If there's one thing that computers do well, it's to make the same
mistake uncountable times at inhuman speed. (Peter Coffee)

another solution: a) pass the node containing the link you want to
operate along with something saying which link in the node (you'll
probably also need a dummy node at the root/head), b) have a separate
object for the link so you can pass it around (i.e. simply an Array of
one element), c) pass a lambda that can modify the link. None of
these are as elegant as an lvalue reference IMHO. In my early ruby
days a few years ago I put some code in the rubyforge "reference"
project. I still think having something like this readily available
would be useful.

The usual solution in Ruby would probably be a) which I find perfectly ok.
Since the manipulation is typically encapsulated inside a LinkedList class
it does not bother me too much if there are two additional elements (for
head and tail). :slight_smile: But I can see how this might be a bit more elegant with
references (although not as much to create an urgent need for references in
Ruby). :slight_smile:

Definitely no urgent need, but a nice thing to have in a bag of
tricks. It could be implemented in Ruby, but you'll get more
efficiency if done in C (ruby implementation would typically need eval
- at least for local vars). No special syntax needed.

Acutally, there *is* an implementation already:

irb(main):002:0> s=SimpleDelegator.new nil
=> nil
irb(main):003:0> s.__getobj__
=> nil
irb(main):004:0> s.__setobj__ "foo"
=> "foo"
irb(main):005:0> s
=> "foo"
irb(main):006:0> s.__getobj__
=> "foo"
irb(main):007:0> s.__setobj__ "bar"
=> "bar"
irb(main):008:0> s.__getobj__
=> "bar"
irb(main):009:0> s.length
=> 3
irb(main):010:0> s.gsub /./, 'X'
=> "XXX"

:slight_smile:

External iterators are also like lvalue references and is something
ruby is missing (IMHO).

Is it?

irb(main):027:0> require 'generator'

This just gives a very limited external iterator that can read and
move forward (just like an internal iterator). In C++ terms, this
corresponds to one of the simplest - "Input Iterator". Other
operations you might want to do where the iterator is at would be:
write, move back, insert, delete, random access.

Right you are.

An external iterator could be thought of as a
superset of the reference/pointer concept (external iterator looks
like a pointer in C++).

Which is nicely done (in C++'s STL, I mean). But with blocks I don't really
miss external iterators. I rarely have to iterate through multiple
collections in lock step and if I had #zip served me well.

#zip doesn't help if you want to write, back-up, insert, delete, etc
during iteration.

Correct. For Array this could easily be build as an external class (attached is an experimental version).

Maybe I'm just not doing enough development that involves sophisticated
algorithms. :slight_smile:

Well, the last year or so I've been exposed to quite a bit of
computational geometry and graph theory. Most of that has been in C++
and a bit of Python (would have used Ruby, but needed a certain API).
Outside of that, my experience would say the same as you. Usually
simple data structures and access methods suffice.

Thank you for this exchange!

Kind regards

  robert

iter.rb (1.4 KB)

···

On 07.06.2008 04:30, Eric Mahurin wrote:

On Fri, Jun 6, 2008 at 10:49 AM, Robert Klemme > <shortcutter@googlemail.com> wrote:

On 06.06.2008 17:01, Eric Mahurin wrote:

Todd Benson wrote:

···

On Fri, Jun 6, 2008 at 7:47 PM, Jenda Krynicky <jenda@cpan.org> wrote:

Beauty contests are a nice pretext for watching a few chicks in swimwear
(or wet tshirts), but it's not a way to find the most beautiful girl of
the USA in the year 2008. Cause there is no such thing.

Also, here I agree.

In any situation, you need a context for beauty, which you pointed
out. I was subtly suggesting that if you remove the context, then
everyone would be on a level playing field.

What would you suggest? A pissing contest? Just curious.

Todd

I suggest to drop the idea. A beauty contest in this area is just a
flamewar-sure-to-happen. And it's completely pointless, you can't
convince anyone something (or someone) is more beautiful (or clean). And
there's penty of both Perl and Ruby examples all around the Internet so
there is no point to add yet another bunch.

Jenda
--
Posted via http://www.ruby-forum.com/\.

>
> >
> > > another solution: a) pass the node containing the link you want to
> > > operate along with something saying which link in the node (you'll
> > > probably also need a dummy node at the root/head), b) have a

separate

> > > object for the link so you can pass it around (i.e. simply an Array

of

> > > one element), c) pass a lambda that can modify the link. None of
> > > these are as elegant as an lvalue reference IMHO. In my early ruby
> > > days a few years ago I put some code in the rubyforge "reference"
> > > project. I still think having something like this readily available
> > > would be useful.
> > >
> > The usual solution in Ruby would probably be a) which I find perfectly
ok.
> > Since the manipulation is typically encapsulated inside a LinkedList
class
> > it does not bother me too much if there are two additional elements

(for

> > head and tail). :slight_smile: But I can see how this might be a bit more

elegant

with
> > references (although not as much to create an urgent need for

references

in
> > Ruby). :slight_smile:
> >
>
> Definitely no urgent need, but a nice thing to have in a bag of
> tricks. It could be implemented in Ruby, but you'll get more
> efficiency if done in C (ruby implementation would typically need eval
> - at least for local vars). No special syntax needed.
>

Acutally, there *is* an implementation already:

irb(main):002:0> s=SimpleDelegator.new nil
=> nil
irb(main):003:0> s.__getobj__
=> nil
irb(main):004:0> s.__setobj__ "foo"
=> "foo"
irb(main):005:0> s
=> "foo"
irb(main):006:0> s.__getobj__
=> "foo"
irb(main):007:0> s.__setobj__ "bar"
=> "bar"
irb(main):008:0> s.__getobj__
=> "bar"
irb(main):009:0> s.length
=> 3
irb(main):010:0> s.gsub /./, 'X'
=> "XXX"

:slight_smile:

But, this doesn't give you an lvalue reference, just an anonymous reference
(which could be used for a case b implementation). A one element Array
would work just as well:

s = ["foo"]
p s[0] # => "foo"
s[0] = "bar"
p s[0] # => "bar"

I usually make a little class with and = methods that take no args in
the , so I don't need the "0" and the suffix is equivalent to the *
prefix in C/C++.

Here would be an fairly efficient instance variable lvalue reference class:

class InstanceVariable
    def initialize(obj, var); @obj=obj; @var=var; end
    def ; @obj.instance_variable_get(@var); end
    def =(val); @obj.instance_variable_set(@var, val); end
end
node = Object.new
node.instance_variable_set(:@next, nil)
node2 = Object.new
link = InstanceVariable.new(node, :@next)
p link # => nil
link = node2
p link.equal?(node2) # => true
p node.instance_variable_get(:@next).equal?(node2) # => true

Here would be a more general class for referencing any lvalue:

class LValue
    def initialize(&lvalue); @lvalue = lvalue; end
    def ; eval(@lvalue.to_s, @lvalue.binding); end
    def =(val); eval("proc {|v| #{@lvalue.to_s} = v}",
@lvalue.binding)[val]; end
end
def swap(a, b); b, a = a, b; end
x = 1
y = 2
swap(LValue.new { :x }, LValue.new { :y })
p x # => 2
p y # => 1

> #zip doesn't help if you want to write, back-up, insert, delete, etc
> during iteration.
>

Correct. For Array this could easily be build as an external class
(attached is an experimental version).

For Array, there isn't a whole lot of value for an external iterator,
because we already have something that works as a poor man's replacement -
index (an integer). The index can't do its own dereferencing (to read and
write an element), but Array can using an index. In C++ STL, an external
iterator can't do all operations either. To do an erase or insert for
example, you call a method on the container with an iterator.

I think external iterators are more useful for other data structures where
you don't have random access - linked lists, trees, etc. I guess you could
provide an index-like API (but the index might not be an integer) instead of
a normal external iterator.

BTW, another external iterator we already have is IO, which operates at a
specific point in a file.

Eric

···

On 6/7/08, Robert Klemme <shortcutter@googlemail.com> wrote:

On 07.06.2008 04:30, Eric Mahurin wrote:
> On Fri, Jun 6, 2008 at 10:49 AM, Robert Klemme > > <shortcutter@googlemail.com> wrote:
> > On 06.06.2008 17:01, Eric Mahurin wrote:

I'm just going to have to agree with you again. I'm torn, you see. I
see elegance in Ruby, but at the same time get a little frustrated
with its flexibility; a taste of scariness even. I'll continue to
favor the language over some popular other ones, because, for me, I
can read the code easier, even if the same thing is done several
different ways.

I should point out as a side note that I still haven't bought into the
whole "pragmatic" thing, simply because I don't think that programming
paradigm really trustfully exists yet, be it Perl, PHP, Ruby, Python,
whatever. I guess I'm kind of old school in thinking "there's no free
lunch", and that's probably having to do with the database/engineer
background. Ah, well, maybe I'll grow up.

Todd

···

On Fri, Jun 13, 2008 at 6:22 AM, Jenda Krynicky <jenda@cpan.org> wrote:

Todd Benson wrote:
I suggest to drop the idea. A beauty contest in this area is just a
flamewar-sure-to-happen. And it's completely pointless, you can't
convince anyone something (or someone) is more beautiful (or clean). And
there's penty of both Perl and Ruby examples all around the Internet so
there is no point to add yet another bunch.

Here is a little richer and more efficient solution:

class Ref
    def initialize(get=nil, &set); @get = get||set; @set = set; end
    def ; @get; end
    def =(val); @set[val]; end
end
def Ref(get=nil, &set); Ref.new(get, set); end
def LValue(&lvalue)
    Ref.new(eval("proc { #{lvalue.to_s} }", lvalue.binding),
            &eval("proc { |val| #{lvalue.to_s} = val}"))
end
def InstVar(obj, var)
    Ref.new(lambda { obj.instance_variable_get(var) }) { |val|
        obj.instance_variable_set(var, val)
    }
end
def Attr(obj, attr, *args)
    get = obj.method(attr)
    set = obj.method("#{attr.to_s}=")
    if args.empty?
        Ref.new(get, &set)
    else
        # curry *args
        Ref.new(lambda { get[*args] }) { |val|
            set[*(args.clone<<val)]
        }
    end
end

# some examples

def swap(a, b); b, a = a, b; end

x = 1
y = 2
swap(LValue { :x }, LValue { :y }) # swap x an y
p x # => 2
p y # => 1

x = [1, 2, 3, 4]
y = [5, 6, 7, 8]
swap(Attr(x, :, 0..2), Attr(y, :, 3..3)) # swap x[0..2] and y[3..3]
p x # => [8, 4]
p y # => [5, 6, 7, 1, 2, 3]

x = Struct.new(:a).new(1)
y = Object.new; y.instance_variable_set(:@b, 2)
swap(Attr(x, :a), InstVar(y, :@b)) # swap x.a and y.@b
p x.a # => 2
p y.instance_variable_get(:@b) # => 1

···

On 6/7/08, Eric Mahurin <eric.mahurin@gmail.com> wrote:

Here would be an fairly efficient instance variable lvalue reference class:

class InstanceVariable
    def initialize(obj, var); @obj=obj; @var=var; end
    def ; @obj.instance_variable_get(@var); end
    def =(val); @obj.instance_variable_set(@var, val); end
end
node = Object.new
node.instance_variable_set(:@next, nil)
node2 = Object.new
link = InstanceVariable.new(node, :@next)
p link # => nil
link = node2
p link.equal?(node2) # => true
p node.instance_variable_get(:@next).equal?(node2) # => true

Here would be a more general class for referencing any lvalue:

class LValue
    def initialize(&lvalue); @lvalue = lvalue; end
    def ; eval(@lvalue.to_s, @lvalue.binding); end
    def =(val); eval("proc {|v| #{@lvalue.to_s} = v}",
@lvalue.binding)[val]; end
end

def swap(a, b); b, a = a, b; end

x = 1
y = 2
swap(LValue.new { :x }, LValue.new { :y })
p x # => 2
p y # => 1