Ruby wish-list

Take care.
-Roger

I wish that ranges could be descending, like
(2000…1950)
and that Range.to_a wouldn’t become obselete, as it seems quite useful
in rails!

Suraj K. wrote:

“foo”.gsub! /o$/, “x” # IMHO, sweet!

“foo”.gsub! %r/o$/, “x” # IMHO, so-so!

“foo”.gsub!(/o$/, “x”) # IMHO, ugly!

Thanks for your consideration.

I wonder if that fact that regex’s always with have two /'s might
help…

Now my own wish. I wish ruby didn’t need ,'s for method parameters.
Why are they always necessary?
foo a b c # as long as a, b, and c aren’t functions, and aren’t
operators, this could parse!
Take care.
-Roger

On Nov 5, 2007, at 3:27 AM, Roger P. wrote:

Another wish list item would be being able to use “a {var_name}”
instead
of “a #{var_name}” I hate that extra pound, as it reminds me of
perl :slight_smile:

“a %s” % var_name

a @ http://codeforpeople.com/

On Nov 5, 2007, at 1:28 PM, Roger P. wrote:

I wonder if that fact that regex’s always with have two /'s might
help…

probably not - unless you wanted to introduce ';'s to ruby too:

cfp:~ > cat a.rb
x = 1

result =
x / 4 * 2 /
42
p result

def x(*re) ‘forty-two’ end

result =
x / 4 * 2 /
42
p result

result =
x(/ 4 * 2 /)
42
p result

cfp:~ > ruby a.rb
0
0
“forty-two”

a @ http://codeforpeople.com/

On 11/6/07, Roger P. [email protected] wrote:

Take care.
-Roger

I wish… that Range.to_a wouldn’t become obselete, as it seems quite useful
in rails!

Assuming you mean Range#to_a (i.e. an instance rather that class
method) I don’t think it’s becoming obsolete.

There was talk some time ago when Matz changed 1.9 to use to_splat
instead of to_a that ranges wouldn’t be splatted, e.g.

a = *(1…3)

In 1.8 this sets a to [1,2,3] whereas at one time in 1.9 it was to
have set it to [(1…3)].

But testing with a fairly recent irb1.9 this seems to be one of the
changes which has been backed out of 1.9.


Rick DeNatale

My blog on Ruby
http://talklikeaduck.denhaven2.com/

I wish… that Range.to_a wouldn’t become obselete, as it seems quite useful
in rails!

Assuming you mean Range#to_a (i.e. an instance rather that class
method) I don’t think it’s becoming obsolete.

It throws warnings as deprecated, for some reason. I like it!

And my latest wish
variables that can end in ?
Oh wishing star…
Take care all!
-Roger

probably not - unless you wanted to introduce ';'s to ruby too:

cfp:~ > cat a.rb
x = 1

result =
x / 4 * 2 /
42
p result

Dang that does seem ambiguous then. Ahh well.

My latest wish is that
unexpected $end, expecting kEND

would say something less cryptic–like "unexpected $end (end of file)
expected word “end” "

Hello,

On Sun, Nov 11, 2007 at 03:13:07PM +0900, Roger P. wrote:

And my latest wish
variables that can end in ?

Mmm I’d like that too.

Regards,

On Nov 11, 2007 1:13 AM, Roger P. [email protected] wrote:

I wish… that Range.to_a wouldn’t become obselete, as it seems quite useful
in rails!

Assuming you mean Range#to_a (i.e. an instance rather that class
method) I don’t think it’s becoming obsolete.

It throws warnings as deprecated, for some reason.

I don’t think so:

shadowfax:~/Documents/terralien/dltsolutions/enrollnow rick$ ruby1.9 -v
ruby 1.9.0 (2007-10-25 patchlevel 0) [i686-darwin8.10.2]
shadowfax:~/Documents/terralien/dltsolutions/enrollnow rick$ ruby1.9
-we ‘(1…3).to_a’
shadowfax:~/Documents/terralien/dltsolutions/enrollnow rick$ ruby1.9
-we ‘p (1…3).to_a’
-e:1: warning: (…) interpreted as grouped expression
[1, 2, 3]
shadowfax:~/Documents/terralien/dltsolutions/enrollnow rick$ ruby1.9
-we ‘p((1…3).to_a)’
[1, 2, 3]


Rick DeNatale

My blog on Ruby
http://talklikeaduck.denhaven2.com/

“unless you wanted to introduce ';'s to ruby too:”

Hopefully a mandatory ; on the end of each line, as is the case with
perl,
will NEVER appear in Ruby … but then again who would wish for bad
stuff :wink:

“variables that can end in ?”

I dont like this, mostly because we can use method calls such as
dragon.hungry?

And I would not want to have a variable inside the dragon that
has something like … i dont know

hungry? = true

I’d rather have a variable that would state
is_hungry = true

instead and then query if the dragon is hungry by using either
is_hungry? or hungry?

(By the way, an accessor_read that can query variables with ? on the end
would
be nice in std ruby too… I am not complaining at all, ruby is so
flexible,
I already use this for my code and i love it, like @file.readable? that
queries a “special” reader accessor… i think it reads nicer than
@file.readable but this is just my opinion)

But I know what i would like to REALLY have:

  • real keyword arguments in 2.0

:slight_smile:

Roger P. wrote:

  • real keyword arguments in 2.0

:slight_smile:

and the ability to parse .25 as a float, instead of 0.25 :slight_smile:

  • real keyword arguments in 2.0

:slight_smile:

Not sure what those are.

My latest wish, oh wishing star…

(I think something in osx does this)

begin_funcion_name param1 keep_going_function_name param2 end

so you can have your function calls read really like English

run_if_queue_below 24 every 24 seconds

yeah :slight_smile:
Stay well.
-Roger

On Nov 15, 2007 11:48 AM, Suraj K. [email protected] wrote:

workaround obsolete:
Thanks for your consideration.
I would think that you would want to maintain the ? behavior across
the board. In other words, it should return TrueClass or FalseClass
objects.

Todd

Todd B. wrote:

I would think that you would want to maintain the ? behavior across
the board. In other words, it should return TrueClass or FalseClass
objects.

Why? In Ruby, anything that is neither nil nor false is the same as
true… I cannot express how many thousands of times this convention
has simplified my code and eased my life! Furthermore, like method
aliases, this convention falls in line with Ruby’s TIMTOWDI philosophy.

So, forcing question-mark methods to return only ‘true’ and ‘false’
feels far too restrictive and seems to follow a
there’s-only-one-way-to-do-it philosophy IMHO.

Marc H. wrote:

(By the way, an accessor_read that can query variables with ? on the end
would be nice in std ruby too… I am not complaining at all, ruby is so
flexible, I already use this for my code and i love it, like @file.readable?
that queries a “special” reader accessor… i think it reads nicer than
@file.readable but this is just my opinion)

Do you mean that attr_accessor treats symbols with a question mark
differently by creating a “symbol_without_question=” writer method and a
“symbol_with_question” reader method? For example:

class Foo
attr_acessor :readable? # defines Foo#readable= and Foo#readable?
end

f = Foo.new
f.readable? #=> nil
f.readable = 99
f.readable? #=> 99

This would be very useful, because it would make the following
workaround obsolete:

class Foo
attr_writer :readable # only defines Foo#readable=

def readable?
  @readable
end

end

Oh wishing star, here is another wish for you! :slight_smile:
Thanks for your consideration.

Suraj K. wrote:

So, forcing question-mark methods to return only ‘true’ and ‘false’
feels far too restrictive and seems to follow a
there’s-only-one-way-to-do-it philosophy IMHO.

Forcing would be bad, but there is the convention that foo? returns true
vs. false, not something vs. nil.

If a foo? method happens to be returning something other than TrueClass,
and you start depending on that quirk, you run the risk that a later
version of that method returns some other non-nil/non-false object.

It’s similar to the use of foo!. You don’t have to use the bang only
when your method is doing something destructive, but you’d be foolish
not to follow the conventions.


James B.

“Programs must be written for people to read, and only incidentally
for machines to execute.”

  • H. Abelson and G. Sussman
    (in "The Structure and Interpretation of Computer Programs)

On Fri, 16 Nov 2007, Roger P. wrote:

My latest wish, oh wishing star…

(I think something in osx does this)

begin_funcion_name param1 keep_going_function_name param2 end

so you can have your function calls read really like English

run_if_queue_below 24 every 24 seconds

def begin_funcion_name( param1, qualifier1, param2, qualifier1) {
}

run_if_queue_below 24, :every, 24, :seconds

On Nov 15, 2007 5:30 PM, James B. [email protected] wrote:

Suraj K. wrote:

So, forcing question-mark methods to return only ‘true’ and ‘false’
feels far too restrictive and seems to follow a
there’s-only-one-way-to-do-it philosophy IMHO.

Forcing would be bad, but there is the convention that foo? returns true
vs. false, not something vs. nil.

There is no such convention in Ruby.

If a foo? method happens to be returning something other than TrueClass,
and you start depending on that quirk, you run the risk that a later
version of that method returns some other non-nil/non-false object.

There ARE cases in the ruby language where a x? returns something
other than true or false

defined?(a) # => nil
a = 1
defined?(a) # => “local-variable”

By the way, you really meant true instead of TrueClass right?

The real danger is that you start testing ‘truth’ with expressions
like x == true or x == false. As long as you don’t do that and simply
use the value in conditional expressions like
if x …
x ? … : …
and the like you’ll be fine.

You rarely need an actual true/false value in Ruby.

For more on this see
http://www.therailsway.com/2007/8/1/dangers-of-cargo-culting


Rick DeNatale

My blog on Ruby
http://talklikeaduck.denhaven2.com/

On Nov 15, 2007 5:28 PM, Rick DeNatale [email protected] wrote:

There is no such convention in Ruby.

No convention in Ruby, but in Ruby programmers.

If a foo? method happens to be returning something other than TrueClass,
and you start depending on that quirk, you run the risk that a later
version of that method returns some other non-nil/non-false object.

There ARE cases in the ruby language where a x? returns something
other than true or false

Yes, that’s great! No forcing, but just realizing that for your code
to work with others’ requires some establishment of convention. Ruby
is a weird and happy monster that way. You can do almost anything
with it, but then when you want to do something with it, you start
setting down ground rules in order to play well with others.

defined?(a) # => nil
a = 1
defined?(a) # => “local-variable”

By the way, you really meant true instead of TrueClass right?

Well, that’s kind of just semantics. James may have meant an instance
of TrueClass, but didn’t word it that way.

a=nil
(a==a).class
#=> TrueClass

The real danger is that you start testing ‘truth’ with expressions
like x == true or x == false. As long as you don’t do that and simply
use the value in conditional expressions like
if x …
x ? … : …
and the like you’ll be fine.

You rarely need an actual true/false value in Ruby.

To newbies, this statement doesn’t make much sense, but I do
understand where you’re coming from. Newbies should definitely learn
that in a conditional, thinks are not always what they seem (and I
love it!).

a = 1
b = 2
a if b

For more on this see
http://www.therailsway.com/2007/8/1/dangers-of-cargo-culting

I didn’t know this acquired the euphemism “cargo-culting”. I still
thought it was called “script kiddies”. I must be getting old :slight_smile:


Rick DeNatale

My blog on Ruby
http://talklikeaduck.denhaven2.com/

Todd

run_if_queue_below 24 every 24 seconds

def begin_funcion_name( param1, qualifier1, param2, qualifier1) {
}

run_if_queue_below 24, :every, 24, :seconds


Clever. I like it.
-Roger