In search of a compelling reason to use ruby

Hope you'll have fun using ruby :)

There is a growing community of python malcontents that might be
interested in ruby.

Well, it’s true that there is a constant flux of people trying to make
ruby their own language. I tried this too :slight_smile:

We just don’t have forks/clones, stuff that is in many places for
python (CPython’s core,Stackless’ continuations,Prothon’s prototypes
and ‘=’ as an expression) is all available in core ruby or can be
easily done through smart usage of few features.

They have a lot of really creative syntax ideas, most
of which are ignored by the mainstream python community. I think it would
be of benefit to the ruby community to be aware of some of their interests
and motivations.

I use to read c.l.py from time to time, and I found prothon initially
interesting.
But, the core idea from Prothon (i.e. classless prototyped OO) is
already available in ruby[1], (provided that you define with()
properly and use Object.clone()), while many others like the funny
obj$met syntax and many things in David Mc Quigg’s proposals (the
‘python 3’ and ‘python 4’ ones) does not sound really nice to me…

Some of those programmers might be interested in
contributing to ruby, rather than working on their own independent
python forks, if I can illustrate ways in which ruby meets their
individual needs.

You’re missing the social point of view:
everybody wants to write the next big language :slight_smile:

[1]
well, partially joking :slight_smile:

···

il Tue, 11 May 2004 07:26:02 GMT, Ryan Paul segphault@sbcglobal.net ha scritto::

Ryan Paul wrote:

I’ve been taking a lot of notes while learning ruby, comparing the ruby
examples to python equivalents, and recording how both ruby and
python solve certain problems. I think I could probably clean up my notes
a bit, and restructure them into a relatively good comparison between the
languages. When I fill it out a bit more, i’ll make it publicly available

I also want to write parts of it like a cookbook so that python
programmers can see how ruby handles some of the specific things that are
commonly done with python.

Presentation is always an issue, and i’m still deciding what the best way
to express the information would be. If I started a conversation with a
python programmer saying something like “have you ever tried ruby? it does
some neat things!” they would probably scoff, but if I said “what if you
could do assignments in anonymous functions?” I might capture their
interest.

… flexible and powerful interpreted language … a progressive and
intuitive development paradigm … bold enough to cast aside standards
and cliches to return the power to the user.

–segphault

Sounds to me like you might have a great contribution to make to
Why Ruby? http://whyruby.rubyforge.org/
which is a project discussed in a thread on this group:
Promoting Ruby news:EAENKKNOJPMNCDMLDOMLCEANEEAA.curt@hibbs.com
The aim of Why Ruby is to produce advocacy and presentation materials, to
the end of improving Ruby’s take-up in the workplace.

I’m glad, too, that you’ve found Ruby such a help.

Dave

In article pan.2004.05.11.07.22.06.816380@sbcglobal.net,

I’ve been taking a lot of notes while learning ruby, comparing the ruby
examples to python equivalents, and recording how both ruby and
python solve certain problems. I think I could probably clean up my notes
a bit, and restructure them into a relatively good comparison between the
languages. When I fill it out a bit more, i’ll make it publicly available,
and drop a link here and in comp.lang.python (where I will probably be
lynched for my impertinence).

Wear asbestos clothing that day :wink:

So far, most of the criticisms of ruby that
flourish in the python community are based on misconceptions. (for
instance, a lot of people seem to know that ruby only supports single
inheritance, but what they dont know is that the mixin system MORE than
makes up for it)

We often hear that there’s not much difference between Ruby and Python
(and some Pythonistas suggest that Ruby is redundant). I don’t have
extensive Python experience, but my intuition is that this isn’t true at
all once you get past superficial comparisons. You seem to be debunking
the myth that the two languages are essentially equivilent.

I also want to write parts of it like a cookbook so that python
programmers can see how ruby handles some of the specific things that are
commonly done with python. The idea of ‘switching languages’ is really
unnerving for a lot of programmers, and I think its really important to
illustrate just how minimal the learning curve is. Ruby feels almost like
a logical extension of python, with some pleasant perl tricks thrown in
for good measure.

They’re not real big on mentioning Perl over there :wink:

Presentation is always an issue, and i’m still deciding what the best way
to express the information would be. If I started a conversation with a
python programmer saying something like “have you ever tried ruby? it does
some neat things!” they would probably scoff, but if I said “what if you
could do assignments in anonymous functions?” I might capture their
interest.

There is a growing community of python malcontents that might be
interested in ruby. They have a lot of really creative syntax ideas, most
of which are ignored by the mainstream python community. I think it would
be of benefit to the ruby community to be aware of some of their interests
and motivations. Some of those programmers might be interested in
contributing to ruby, rather than working on their own independent
python forks, if I can illustrate ways in which ruby meets their
individual needs. To that end, I will probably spend some time looking at
python derivatives to see where the divergences are, and how (if at all)
their python extensions compare to some of ruby’s development idioms.
‘Prothon’ is a good example of a python derivative on my list. I also mean
to show how ruby provides native support for many of the features hacked
into python by Xoltar’s partial, functional, and datastruct libraries.

Interesting.

Ultimately, i’m interested in a flexible and powerful interpreted
language, and what I have seen of ruby’s style indicates a progressive and
intuitive development paradigm that is bold enough to cast aside standards
and cliches to return the power to the user.

Welcome to Ruby-land.

Phil

···

Ryan Paul segphault@sbcglobal.net wrote:

On Tue, 11 May 2004 12:50:24 +0900, James Britt wrote:

Linus Sellberg wrote:

gabriele renzi wrote:

What method do you think is oddly named ? I for one, would say
inject() but using reduce() or fold() is equally
non intuitive for me :slight_smile:

There are a really really nice name for it out there.

Unfortunately, collect are already used.

accumulate might be a better name, but it’s too loooong.

“Ryan Paul” segphault@sbcglobal.net schrieb im Newsbeitrag
news:pan.2004.05.12.19.33.22.639514@sbcglobal.net

> >In python, we have map, filter, and list comprehensions, all of which

can

be used to manipulate lists in very general ways. In order to do
certain
things, python users have to stack multiple functions into map
statements.
Generally, this is actually pretty simple to do, and makes things
somewhat
intuitive. In ruby, there are a multitude of rather oddly named array
functions that have very specific behaviors, most of which can be used
with blocks to concisely describe extremely sophisticated operations.

In ruby there are a lot of Enumerable functions, not array’s :slight_smile:
What method do you think is oddly named ?
I for one, would say inject() but using reduce() or fold() is equally
non intuitive for me :slight_smile:

Its not so much that their names are strange, its the fact that they
exist
at all. In python, lists only have like 8 or 9 functions, and they are
all
pretty standard and self explanatory (append, count, extend, insert,
remove, reverse, and maybe two or three others). Having things like
collect, replace, assoc, and compact built into arrays is something of a
novelty for a python programmer. I’m used to having to do replacement
like
this, for example:
[y for x in listobj if x == z]

Personally, I feel that it is better to have functions that do these
things,

Did you mean to say “methods”? I ask because strictly speaking there are
no functions in Ruby. They are all tied to some instance.

because list comprehensions scale grotesquely, so I prefer the way
ruby does it. Not only does ruby provide a ton of useful functions to
start with, but I can add as many of my own as I want!

Also, the fact that collect doesnt automatically compact really threw me
for a spin. I was using “x.collect {whatever}.compact” until I figured
out
that it is easier to do a reject on the inverse of what I would have put
in a python ‘filter’.

Normally I would first select and then map. That’s more efficient IMHO:

irb(main):015:0> a = %w{a bb ccc}
=> [“a”, “bb”, “ccc”]
irb(main):016:0> a.select {|x| /[1]/ =~ x}.map {|x| “(#{x})”}
=> [“(a)”, “(bb)”]
irb(main):017:0> a.select {|x| x.length > 2}.map {|x| “(#{x})”}
=> [“(ccc)”]

I added a ‘filter’ function to the array class that
fixes this for me.

It can be far easier if your criterion happens to support ===, like Regexp
does. Use #grep:

irb(main):008:0> a = %w{a bb ccc}
=> [“a”, “bb”, “ccc”]
irb(main):009:0> a.grep(/[2]/) {|x| “(#{x})”}
=> [“(a)”, “(bb)”]

You can easily make up your own criterion:

irb(main):010:0> crit = Object.new
=> #Object:0x101a2920
irb(main):011:0> def crit.===(x); x.length > 2; end
=> nil
irb(main):012:0> a.grep(crit) {|x| “(#{x})”}
=> [“(ccc)”]

You can make your life even simpler with:

module Criterion
def self.create(&b)
def b.===(x); call(x);end
b
end
end

irb(main):031:0> a = %w{a bb ccc}
=> [“a”, “bb”, “ccc”]
irb(main):032:0> crit = Criterion.create {|x| x.length > 2}
=> #Proc:0x100c4978@:32(irb)
irb(main):033:0> a.grep(crit) {|x| “(#{x})”}
=> [“(ccc)”]

Additionally, having two different names for the same thing (eg: collect
and map) was initially confusing, but only because i’m not used to such
things. Python would NEVER do that.

Ruby tries to be nice to people coming from different other languages.
Some have map and some have collect. :slight_smile:

Regards

robert
···

On Wed, 12 May 2004 18:04:17 +0000, gabriele renzi wrote:

il Wed, 12 May 2004 16:37:42 GMT, Ryan Paul segphault@sbcglobal.net > > ha scritto::


  1. ab ↩︎

  2. ab ↩︎

Robert wrote:

You can make your life even simpler with:

module Criterion
def self.create(&b)
def b.===(x); call(x);end
b
end
end

irb(main):031:0> a = %w{a bb ccc}
=> [“a”, “bb”, “ccc”]
irb(main):032:0> crit = Criterion.create {|x| x.length > 2}
=> #Proc:0x100c4978@:32(irb)
irb(main):033:0> a.grep(crit) {|x| “(#{x})”}
=> [“(ccc)”]

How is this simpler than

a.select { |x| x.length > 2 }

?

OIC. You’re using the block form of grep to save yourself a map. I don’t
much like it, though, because the filtering predicate is removed from the
place where it’s used, wasting the beuaty of blocks.

Clever, though, and probably useful in some situations (e.g. where you’re
doing lots of filtering and mapping :slight_smile:

Cheers,
Gavin

“Gavin Sinclair” gsinclair@soyabean.com.au schrieb im Newsbeitrag
news:43228.129.78.228.114.1084421428.squirrel@webmail.imagineis.com

Robert wrote:

You can make your life even simpler with:

module Criterion
def self.create(&b)
def b.===(x); call(x);end
b
end
end

irb(main):031:0> a = %w{a bb ccc}
=> [“a”, “bb”, “ccc”]
irb(main):032:0> crit = Criterion.create {|x| x.length > 2}
=> #Proc:0x100c4978@:32(irb)
irb(main):033:0> a.grep(crit) {|x| “(#{x})”}
=> [“(ccc)”]

How is this simpler than

a.select { |x| x.length > 2 }

?

OIC. You’re using the block form of grep to save yourself a map. I
don’t
much like it, though, because the filtering predicate is removed from
the
place where it’s used, wasting the beuaty of blocks.

Yeah, that’s true, although you could do

a.grep( Criterion.create {|x| x.length > 2} ) {|x| “(#{x})”}

or even if you define Criterion as method in Kernel:

a.grep( Criterion {|x| x.length > 2} ) {|x| “(#{x})”}

Clever, though, and probably useful in some situations (e.g. where
you’re
doing lots of filtering and mapping :slight_smile:

Exactly. I thought of a situation where you use this idiom often and you
have Criterion as a lib module that you use over and over again.

I forgot to mention that there is - of course - a shorter ad hoc solution
with #inject. Maybe it’s not as easy to read as others, but it’s more
efficient than select{}.map{} because you do only one iteration. Here it
is:

irb(main):005:0> a = %w{a bb ccc}
=> [“a”, “bb”, “ccc”]
irb(main):006:0> a.inject() {|arr,x| arr << “(#{x})” if /[1]/ =~ x;
arr}
=> [“(a)”, “(bb)”]
irb(main):007:0> a.inject() {|arr,x| arr << “(#{x})” if x.length > 2;
arr}
=> [“(ccc)”]

Regards

robert

  1. ab ↩︎

Or another idea:

require “enumerator”
module Enumerable
def filter(block)
each do |i|
yield i if block.call(i)
end
end
def enum_filter(&block)
Enumerator.new(self, :filter, block)
end
end

(3…20).enum_filter{ |x| x % 2 == 0 }.collect
=> [4, 6, 8, 10, 12, 14, 16, 18, 20]

Kristof

···

On Thu, 13 May 2004 10:22:42 +0200, Robert Klemme wrote:

Yeah, that’s true, although you could do

a.grep( Criterion.create {|x| x.length > 2} ) {|x| “(#{x})”}

or even if you define Criterion as method in Kernel:

a.grep( Criterion {|x| x.length > 2} ) {|x| “(#{x})”}

Clever, though, and probably useful in some situations (e.g. where
you’re
doing lots of filtering and mapping :slight_smile:

Exactly. I thought of a situation where you use this idiom often and you
have Criterion as a lib module that you use over and over again.