Little Things

D

dblack

Hi --

No please. That doesn't match the behavior of any other #foo, #foo! that I
know of. #send and #funcall match what the written methods look like
perfectly.

But #foo/#foo! behaviors don't have to match each other, except at the
very abstract level of one being "dangerous". I've always thought
that including private methods vs. not including them was a good
candidate for dangerous, but Matz didn't agree in this case so I don't
think it will happen.

#send and #funcall sort of match what the written methods *might* look
like (sometimes; not in the case of setter methods, and not for public
methods where you used a receiver) if you called them. It just seems
to me to be a pretty tenuous connection.


David

--
Q. What is THE Ruby book for Rails developers?
A. RUBY FOR RAILS by David A. Black (http://www.manning.com/black)
(See what readers are saying! http://www.rubypal.com/r4rrevs.pdf)
Q. Where can I get Ruby/Rails on-site training, consulting, coaching?
A. Ruby Power and Light, LLC (http://www.rubypal.com)
 
M

Mauricio Fernandez

But #foo/#foo! behaviors don't have to match each other, except at the
very abstract level of one being "dangerous". I've always thought
that including private methods vs. not including them was a good
candidate for dangerous, but Matz didn't agree in this case so I don't
think it will happen.

Actually, in 1.9 you have send, funcall, __send and __send!.
These last ones might disappear at any time, but my hunch is that there's a
chance they'll stay. But it's just the gut feeling of somebody who's been
tracking Ruby 1.9 for a while and has seen features come by and go.

Reading the sources/changelogs periodically can be tiresome, so I've been
maintaining this change summary for some time:

http://eigenclass.org/hiki.rb?Changes+in+Ruby+1.9#l22
 
D

dblack

Hi --

Actually, in 1.9 you have send, funcall, __send and __send!.
These last ones might disappear at any time, but my hunch is that there's a
chance they'll stay. But it's just the gut feeling of somebody who's been
tracking Ruby 1.9 for a while and has seen features come by and go.

Thanks for the update. I really must try to stay more on the edge of
1.9 :)


David

--
Q. What is THE Ruby book for Rails developers?
A. RUBY FOR RAILS by David A. Black (http://www.manning.com/black)
(See what readers are saying! http://www.rubypal.com/r4rrevs.pdf)
Q. Where can I get Ruby/Rails on-site training, consulting, coaching?
A. Ruby Power and Light, LLC (http://www.rubypal.com)
 
A

Alex Fenton

What about:

obj.send:)foo) # will call only public
obj.send!:)foo) # will bypass private/protected, like the current send.

I don't normally weigh in on these discussions, but since it's come up again I'm strongly +1 for this.
reads better then funcall to me, at least.

I know very little lisp, and though the private method == function link makes sense, it's pretty esoteric.

I don't know what I'd expect a funcall method to do ... dial 0800 FUN NOW ?

happy new year
alex
 
M

Marc Heiler

Just one quick comment:

"[...] what could potentially kill the language.
We can have the best language on the Planet, but if the language
features are only accessible to those that are willing to go code-diving
for the answers, then the target audience is going to be slim."

I disagree to the potential of this.
I myself am sometimes annoyed at the lack of any
documentation, this sometimes involve old code - new code
almost always is nicely documented :)

However, only a lack of docu wont stop me from using
ruby. Most naturally because I do not HAVE to use 100%
of the language, and books like the pickaxe really
did help a LOT - IF any docu has to be added, then
i'd look at these things first ;)

- More focus on the C part of Ruby. Its a little bit
difficult to find enough good quality documents about
extending Ruby in C
- Allow only code into stdlib etc.. that has a minimum
docu
- Replacement for ri/rdoc or updating, so many people
rely on it for documenting their code, but the
html frame alone isnt always that appealing, and
ri can sometimes be slow, silly or... well
- Ruby website should offer online docu similar to how
php does. Php as a language is a curse, but the
online docu is rather good. I think ruby should
take up the idea of providing good online docu.

Anyway... just some of my long 2 cc, dont mean
to interrupt! :D
 
T

Trans

Hey matz,

thanks for taking the time to respond to these.
I'd like to see them as separated RCRs, even though the new RCR site
have not seen its successful start-up yet.

If the RCR process gets fixed I would be happy to do some of them.
Right now only two people have submitted RCRs (last I checked) and the
communication on those RCRs is either broken or simply not being used
--I made attempts at emailing on the second --and I sumbitted the first
;-)
The biggest reason we don't have caller binding API is the difficulty
of the implementation under the current interpreter. ko1 once said it
is possible for YARV, so all we need is to design good API. I don't
think of_caller is the best name for it.

Really? By simply passing a block I can pass the binding of the caller.
I suppose passing a hidden block is too heavy though?
By the way, YARV was committed in the Subversion trunk yesterday.
w00t!

Could you describe what this change give you? Removing class method
does not allow local variables to be named 'class'. Besides that I
don't like the name "object_class", which is too vague for me. class
of an object? a class object? an object which is a class? whatever.
Maybe because I see many combination of "something id" but not
"something class", besides "business class" etc.

The main thing is that it creates an exception b/c we are forced to use
a reciever, eg. self.class, so it can't be called as a "function" nor
made private. No other method is like that. Also I don't see why we
can't use it as a local var. Isn't the conflict with class<<obj
notation? Probably the parser should see /class\s+<</ as a whole unit,
which I think would allow for the var. But if you ask me the whole
"class << obj" notaton is yuk anyway. It visually clashes with Array#<<
and I'd much prefer someting like 'obj.meta_eval' -or-
'obj.singleton_eval'.
|* Allow a comma between the two <code>alias</code> arguments --getting
|an error on that is really annoying. Actually why is <code>alias</code>
|a keyword? Why have both <code>#alias_method</code> and
|<code>alias</code>? I have always been told that keywords were to be
|avoided.

Are you proposing comma between alias arguments, or removal of the
alias keyword?

Well, both. First and foremost however is the option of a comma. What
good reson is there for getting getting a sytax error here?

As for makeing alias a real method, that seems like a good idea. it
would allow us to use 'alias' as a var too.

If it possible to get rid of an exception and have things still work
fine, then it's a good thing, isn't it?
|* <code>String#resc</code> as an inversion of
|<code>Regexp.escape(string)</code> and <code>String#to_re</code> as an
|inversion of <code>Regexp.new(string)</code>.

Why?

It's much more concise. Take a simple example:

re = /^#{user_input}/

We need to escape it:

re = /^#{Regexp.escape(user_input)}/

vs.

re = /^#{user_input.resc}/

The to_re, just goes hand in hand with resc, since they both regular
expresions --maybe resc should be to_resc, but tersness is especially
useful with it so I suggest resc instead.
|* I'm dying here from remove_method hacks without
|<code>#instance_exec</code>. This has to rank in the top three "little
|things" that have been talked about forever, and it isn't that hard to
|implement. So what's holding it up?

We have it in 1.9.

Yea! But why not a 1.8 serious. It's an additon it won't break
anything. Correct me if I'm wrong, but I fear we won't see anything
from 1.9 in production for almost 2 years.
|* Close the closures. Writing DSLs is great, but have you noticed they
|all share the same closure? Have a way to reset the closure with some
|sort of special block notation would shore-up this danger hole. Maybe:
|
|<pre>
| a = 1
| dosomething do! |x|
| p a #=> error
| end
|</pre>

I am not sure what you meant here. Could you elaborate (maybe in a
separate post)? Does any other language address this issue?

Okay. I will post separately.
We have send, funcall, __send, __send! in 1.9. Do we need more?

So we have the functionality. But can you tell me with a straight face
those are great method names?

Peronally, I really think you should get rid of __shadow methods
wherever you can. All it indicates is that the original method's name
is too common, so is likely to be overridden. And that's the reason I
suggest #object_send. All methods starting with object_ or instance_
are special. They are meta-programming methods and as such need to
stand aside in some fashion to avoid being overridden easily. This
consistancy is the beauty of it.
In short, you are asking for the alias for Module#===, right?
I don't see any good reason for it, where we can call

myobject.instance_of?(MyClass)

but the good name for it would help accepting the proposal.

Yes. that's right. But I learned that it is better to ask the class if
you want to know the "truth". Sometimes the object might need to lie
--eg. as a proxy. I guess the most obvious name is:

MyClass.class_of?(myobject)
|* Oh, and lets not forget the forever arguable method name for (class
|<< self; self; end). But please give us something concise.

Yes, the name is the biggest obstacle now.

#supercalifragilisticexpialidocius

Almost anything is better than nothing at this point.... okay maybe not
THAT, but you get my point.
|No doubt there other little things left unmentioned, and obviously some
|are more important than others. But in any case, it's clearly striking
|that after hearing for so long about many such well-accepted "little
|things", that Ruby has yet to take them in. I have a silly theory about
|this actually --as odd as it may seem. The 1.9 version is the last on
|the chain before 2.0 b/c matz is against using double-digit minor
|numbers, eg 1.10. So we're is stuck with 1.9 as his test bed for 2.0.
|Since 1.8 can only increment by teeny, these "little things", being not
|little enough, can't make it in. Hence Ruby is being held back by a
|version number policy!!! I think Matz just needs to get on with it (hey
|look forward to 3.0!) or just lossen the version policy constraints.

Digits that we have many (hey, we could have 9 more major releases!)

Good! :)
are not the reason. Expected screams from all over the world suspends
incompatibility and behavior changing for 1.8.

Yet most of these have no backward compatability issues --I guess
that's really my main point with "Little things"

Thanks and happy new year,
T.
 
D

Devin Mullins

Trans said:
The main thing is that it creates an exception b/c we are forced to use
a reciever, eg. self.class, so it can't be called as a "function" nor
made private. No other method is like that.
Actually, two classes of method names come to mind:
- Those that share a name with a keyword (class, when, def, etc.)
- Setter methods (/=$/, that is)

There's an exception for the latter -- when private, they can be called
with self as an explicit receiver.

Neither defending the behavior nor arguing for a change... just playing
Mr. Fact Checker (or Mr. Obvious, depending on your POV).

Devin
 
T

Trans

Devin said:
Actually, two classes of method names come to mind:
- Those that share a name with a keyword (class, when, def, etc.)

That's a good point. Although 'when', 'def' and others aren't also
built-in methods. And in a private context at least, no one is going to
readily use them as such.
- Setter methods (/=$/, that is)

There's an exception for the latter -- when private, they can be called
with self as an explicit receiver.

True. An expection I never liked, but it's neccessary, and at least
it's a very simple pattern.
Neither defending the behavior nor arguing for a change... just playing
Mr. Fact Checker (or Mr. Obvious, depending on your POV).

facts == good

Thanks,
T.
 
S

Simen Edvardsen

I was a bit surprised about Matz mention of the little things in his
last <a
href="http://www.rubyist.net/~matz/slides/rc2006/mgp00017.html">ketynote</a>.
Little things can make all the difference! In fact, long time Rubyists
have been waiting a long for some important "little" things. Here's
some of the things on my little list....
[...]

When we're talking about little things, I've got one suggestion as
well. Python has the nice trick that you can call any object like a
function by simply overriding the __call__ method. Something like that
would be nice to have in Ruby as well. When you call an object with
the normal syntax, the fallback could be the #call method or some
such. Then it'd be possible to do this:

def some_method(&proc)
proc("Hello")
proc "Hello"
proc 1, 2, 3
end

I admit that having a separate function namespace means that we can
have ice syntax for method calls with no parens, but something like
this would permit some cool tricks.
 
A

ara.t.howard


++

-a
--=20
if you find yourself slandering anybody, first imagine that your mouth is
filled with excrement. it will break you of the habit quickly enough. - th=
e
dalai lama
 
D

dblack

---2049402039-1457112532-1167861056=:30963
Content-Type: MULTIPART/MIXED; BOUNDARY="-2049402039-1457112532-1167861056=:30963"

This message is in MIME format. The first part should be readable text,
while the remaining parts are likely unreadable without MIME-aware tools.

---2049402039-1457112532-1167861056=:30963
Content-Type: TEXT/PLAIN; charset=X-UNKNOWN; format=flowed
Content-Transfer-Encoding: QUOTED-PRINTABLE

Hi --

=20
On Thu, 4 Jan 2007, [ISO-8859-1] Paulo K=F6ch wrote:
=20
On 2006/12/31, at 07:38, Rob Sanheim wrote:
obj.send:)foo) # will call only public
obj.send!:)foo) # will bypass private/protected, like the current sen= d.

+1
=20
++
=20
-a
--
if you find yourself slandering anybody, first imagine that your mouth i= s
filled with excrement. it will break you of the habit quickly enough. -
the
dalai lama
=20
=20
It is not frequent that I dare not do agree with Gurus like Ara (1) but I
have a very strong feeling that the ! suffix should indicate an object
inplace change instead of the object not being touched, as e.g. in sub vs= =2E
sub! (2) etc.
I feel it is not a good idea to define send! as mentioned above.

! doesn't mean the object changes; it means that the method is a
"dangerous" version of the same method without the !. The idea is
that send! is "dangerous" in the sense that it will break through the
private-method barrier, while send will not.


David

--=20
Q. What is THE Ruby book for Rails developers?
A. RUBY FOR RAILS by David A. Black (http://www.manning.com/black)
(See what readers are saying! http://www.rubypal.com/r4rrevs.pdf)
Q. Where can I get Ruby/Rails on-site training, consulting, coaching?
A. Ruby Power and Light, LLC (http://www.rubypal.com)
---2049402039-1457112532-1167861056=:30963--
---2049402039-1457112532-1167861056=:30963--
 
D

dblack

Hi --

(2) OT but still interesting I feel it might be a good convention that any
method changing the object should have a ! suffix, would make
programs much more readable, don't you think?

No. I would not want to see pop turned into pop! or << turned into
<<! and so forth.


David

--
Q. What is THE Ruby book for Rails developers?
A. RUBY FOR RAILS by David A. Black (http://www.manning.com/black)
(See what readers are saying! http://www.rubypal.com/r4rrevs.pdf)
Q. Where can I get Ruby/Rails on-site training, consulting, coaching?
A. Ruby Power and Light, LLC (http://www.rubypal.com)
 
T

Trans


Come on guys. Has anyone read my critique? You can "plus one" til the
cow's come home, but you totally ignore the issues. Show me you know
something about the issue, tell me _why_. Otherwise your +1's are
littel more than cooy feelings.

Do you understand that #send is tantamount to a keyword?

T=2E
 
D

dblack

Hi --

Hey matz,

thanks for taking the time to respond to these.


If the RCR process gets fixed I would be happy to do some of them.
Right now only two people have submitted RCRs (last I checked) and the
communication on those RCRs is either broken or simply not being used
--I made attempts at emailing on the second --and I sumbitted the first
;-)

Can you tell me what happened when you tried the email? Did you
subscribe to it at the site? If something's wrong, I can't fix it
unless I hear about it. If people are just not using the site much,
that's not the same as its being broken.


David

--
Q. What is THE Ruby book for Rails developers?
A. RUBY FOR RAILS by David A. Black (http://www.manning.com/black)
(See what readers are saying! http://www.rubypal.com/r4rrevs.pdf)
Q. Where can I get Ruby/Rails on-site training, consulting, coaching?
A. Ruby Power and Light, LLC (http://www.rubypal.com)
 
A

ara.t.howard

Come on guys. Has anyone read my critique? You can "plus one" til the
cow's come home, but you totally ignore the issues. Show me you know
something about the issue, tell me _why_. Otherwise your +1's are
littel more than cooy feelings.

Do you understand that #send is tantamount to a keyword?

yes. but it's only keword-like without a receive and

send! 'private_method'

is fine since

private_method

is fine too.

-a
--=20
if you find yourself slandering anybody, first imagine that your mouth is
filled with excrement. it will break you of the habit quickly enough. - th=
e
dalai lama
 
D

dblack

Hi --

You are right especially for operators <<!, looks terrible but would be
necessary if one wanted to follow the rationale.
I feel it would be nice to have it, but I agree such a paradigm change
cannot take place anymore in a mature language.

All that said I really like the idea of seeing in a method call if an object
changes or not, look for example at C++, the information is in the
declaration "const" would it not be much better in the usage, e.g. in the
method call?

You can generally tell from the semantics of the method name. For
example, Array#pop has no possible non-destructive meaning. (A
non-destructive pop would just be array[-1] with an incomprehensible
name.) There are a couple of cases where you do have to learn it...
like the fact that Array#delete is destructive but String#delete
isn't.

Similarly, if you follow the "dangerous" idea, you can infer that
gsub! is a destructive gsub, since that's pretty much the only
"dangerous" thing a gsub operation can do.
Coming back to Tom's idea of do! vs do, to be consistent we would need a {!
vs {, no? and we are not talking methods anymore.

So #send! and do! ? maybe not.

do isn't a method, though; it's a keyword. I don't think we're going
to get (or want) ! on keywords.


David

--
Q. What is THE Ruby book for Rails developers?
A. RUBY FOR RAILS by David A. Black (http://www.manning.com/black)
(See what readers are saying! http://www.rubypal.com/r4rrevs.pdf)
Q. Where can I get Ruby/Rails on-site training, consulting, coaching?
A. Ruby Power and Light, LLC (http://www.rubypal.com)
 
D

dblack

Hi --

(A non-destructive pop would just be array[-1] with an incomprehensible
name.)

Array#last

OK; it would just be Array#last with an incomprehensible name :)

What I was getting at was that there's no point having pop and pop!
since a non-destructive method called "pop" makes no sense.


David

--
Q. What is THE Ruby book for Rails developers?
A. RUBY FOR RAILS by David A. Black (http://www.manning.com/black)
(See what readers are saying! http://www.rubypal.com/r4rrevs.pdf)
Q. Where can I get Ruby/Rails on-site training, consulting, coaching?
A. Ruby Power and Light, LLC (http://www.rubypal.com)
 

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

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top