ruby wish-list

A

ara.t.howard

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

Roger Pack

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" "
 
R

Rick DeNatale

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

Roger Pack

I wish... that Range.to_a wouldn't become obselete, as it seems quite useful
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
 
R

Rick DeNatale

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

Marc Heiler

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


"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

:)
 
R

Roger Pack

* real keyword arguments in 2.0

:)

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 :)
Stay well.
-Roger
 
S

Suraj Kurapati

Marc said:
(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! :)
Thanks for your consideration.
 
T

Todd Benson

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! :)
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
 
S

Suraj Kurapati

Todd said:
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.
 
J

James Britt

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

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 Britt

"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)
 
T

Tomas Pospisek's Mailing Lists

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
 
R

Rick DeNatale

Suraj Kurapati wrote:

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
 
S

Sean O'Halpin

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! :)
Thanks for your consideration.

Here you go (wouldn't use it myself though):

class Module
# get a unique alias
method_name = '__attr_accessor__#{rand(123456789)}__#{Time.now.to_i}'
alias_method method_name, :attr_accessor

define_method :attr_accessor do |name|
name = name.to_s
if name[-1] == ??
sname = name[0..-2]
attr_writer sname
define_method "#{name}" do
instance_variable_get "@#{sname}"
end
else
send(method_name, name)
end
end
end


class Foo
attr_accessor :readable?
attr_accessor :bar
end

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

f.bar = 42 # => 42

Regards,
Sean
 
T

Todd Benson

There is no such convention in Ruby.

No convention in Ruby, but in Ruby programmers.
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

I didn't know this acquired the euphemism "cargo-culting". I still
thought it was called "script kiddies". I must be getting old :)
--
Rick DeNatale

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

Todd
 
J

James Britt

Todd said:
No convention in Ruby, but in Ruby programmers.

Right. And in a TIMTOWTDI language is can amount to the same thing.
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.

Exactly. Yes, there are exceptions, and yes that can be handy, but
(culturally speaking) treating foo? as an attribute accessor is probably
a mistake because you may be relying on a quirk of implementation.

Since *every* method could be used as a boolean value, the use of '?'
should be reserved to expressed a particular meaning, i.e., all this
method assures you is that you'll get a return value than can be
interpreted as true or false, and is not meant to be an object accessors.

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


Yes, thank you. I meant not simply true (i.e., something that is not
nil), but "only" true (and not some particular object you are relying on
to have a secondary value).



--
James Britt

"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)
 

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

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,015
Latest member
AmbrosePal

Latest Threads

Top