[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: auto assign arguments?

Yukihiro Matsumoto

1/19/2007 5:15:00 PM

Hi,

In message "Re: auto assign arguments?"
on Sat, 20 Jan 2007 01:58:06 +0900, "David Chelimsky" <dchelimsky@gmail.com> writes:

|Would you mind providing a brief explanation of your objection? There
|is no Reason for rejection with the old RCR
|(http://oldrcrs.rubypal.com/rejected...) and it would be
|helpful to me (and I'm sure others) to understand why you think this
|is a bad idea.

I thought (and I still think) it is a good idea to separate method
argument and assignment in general. It's convention supported by most
languages, and mixing parameters and assignments gives me impression
of toy-language.

Besides that, I think formal arguments of a method (including their
names) can be seen as part of class API. Allowing instance variables
as formal arguments seems like disclosing the internal issues.

Finally, I admit that the code like this

def initialize(@length)
end

is longer than

def initialize(length)
@length = length
end

but I feel the intention of the latter code is far clearer than the
former.

matz.

7 Answers

David Chelimsky

1/19/2007 5:21:00 PM

0

On 1/19/07, Yukihiro Matsumoto <matz@ruby-lang.org> wrote:
> Hi,
>
> In message "Re: auto assign arguments?"
> on Sat, 20 Jan 2007 01:58:06 +0900, "David Chelimsky" <dchelimsky@gmail.com> writes:
>
> |Would you mind providing a brief explanation of your objection? There
> |is no Reason for rejection with the old RCR
> |(http://oldrcrs.rubypal.com/rejected...) and it would be
> |helpful to me (and I'm sure others) to understand why you think this
> |is a bad idea.
>
> I thought (and I still think) it is a good idea to separate method
> argument and assignment in general. It's convention supported by most
> languages, and mixing parameters and assignments gives me impression
> of toy-language.
>
> Besides that, I think formal arguments of a method (including their
> names) can be seen as part of class API. Allowing instance variables
> as formal arguments seems like disclosing the internal issues.
>
> Finally, I admit that the code like this
>
> def initialize(@length)
> end
>
> is longer than
>
> def initialize(length)
> @length = length
> end
>
> but I feel the intention of the latter code is far clearer than the
> former.

Very helpful. Thanks for the clarification.

Cheers,
David

>
> matz.
>
>

Daniel DeLorme

1/20/2007 6:27:00 AM

0

Yukihiro Matsumoto wrote:
> I thought (and I still think) it is a good idea to separate method
> argument and assignment in general. It's convention supported by most
> languages, and mixing parameters and assignments gives me impression
> of toy-language.

That's interesting. Would you mind sharing your insight on why these should be
separated? To me they seem similar enough to be "merged". I think the only
reason to separate them is because, at the machine-language level, function
arguments are PUSHed onto the stack while assignments are MOVed to memory. So
historically they come from different mechanisms. But if we agree that computer
languages should be designed for humans, not computers, it seems more natural to
view parameters as a specialized case of assignment.

> Besides that, I think formal arguments of a method (including their
> names) can be seen as part of class API. Allowing instance variables
> as formal arguments seems like disclosing the internal issues.

I can see the number of arguments (and in other languages, their type) as part
of the class API, but not their names since those variables' names are local to
the method. True, rdoc exposes those internals in the documentation, but then it
also exposes the instance variables & methods used for default values. For
consistency I think instance variables should be allowed as parameters since
they are allowed as default values. But I acknowledge that consistency may not
be the most important factor to consider here.

I dunno, forbidding instance variables may be the more "correct" approach but I
think allowing them would be more useful. One of the reasons I like ruby is
because it favors usefulness over strict "correctness" (e.g. you can still get
to private methods if you really need it)

just my 2å??

Daniel

David Chelimsky

1/20/2007 11:58:00 AM

0

On 1/20/07, Robert Dober <robert.dober@gmail.com> wrote:
> On 1/19/07, Yukihiro Matsumoto <matz@ruby-lang.org> wrote:
> >
> > Hi,
> >
> > In message "Re: auto assign arguments?"
> > on Sat, 20 Jan 2007 01:58:06 +0900, "David Chelimsky" <
> > dchelimsky@gmail.com> writes:
> >
> > <snip>
> >
> > Besides that, I think formal arguments of a method (including their
> > names) can be seen as part of class API. Allowing instance variables
> > as formal arguments seems like disclosing the internal issues.
>
>
> Yes exactly but by explicit declaration, so
>
> def set_length(@length)
>
> just would be a willful disclosure a little bit like
> attr_writer :length
>

Thinking about this some more - I wasn't proposing this become part of
the API. Nor would I want to see this anywhere besides the
initializer. The proposal is that for initializers (only) you could
define (not reference pre-existing) instance variables:

def initialize(@length)
end

If this were allowed, there would be no need to expose the @ in RDoc.
RDoc could be tweaked to hide that, so you'd still just see:

new(length)

Note that RDoc is already hiding initialize (as an instance method)
and showing you new (as a class method), so this would just be an
addition to that transformation.

So the proposed sugar would only be exposed to the intialize method
and anybody (human or machine) reading the class definition.

David

> But your reasoning is sound of course I feel it more important is the
> unification of
> method and block parameter behaviour which you have achieved in 1.9.
>
> It would be interesting why you allowed instance variables in blocks, maybe
> because blocks are
> not exposing an API?
> I am confusing myself ;)
>
> Finally, I admit that the code like this
> >
> > def initialize(@length)
> > end
> >
> > is longer than
> >
> > def initialize(length)
> > @length = length
> > end
> >
> > but I feel the intention of the latter code is far clearer than the
> > former.
>
>
> I agree the first is a little bit against POLS, I do not know any other
> language where you can
> define instance variables as formal parameters.
> I am sure someone will fill this gap quickly though ;)
>
> matz.
> >
> >
> Cheers
> Robert
>
> --
> "The best way to predict the future is to invent it."
> - Alan Kay
>
>

Kadaitcha Man

3/20/2010 8:16:00 AM

0

"PepsiFreak@teranews.com", thou infected insolent villain. Thy bones are
hollow, impiety has made a feast of thee. Ye swore:

> "Kadaitcha Man" <anon@no.email> wrote in message
> news:98mz75$1g2$x@unlawfully-begotten-red-lighter.co.haiti...
>> "IAAH", thou putrefying fever blister. Snakes, in my heart blood
>> warmed, that sting my heart. Thou Judas, thrice worse than Judas. Ye
>> whistled:
>>
>>> I don't know of any atheist who think the universe created itself out
>>> of nothing.
>>
>> Then how was it created?
>>
>>> I suppose such childish arguments from you are a result of your
>>> evident insecurity in your belief.
>>
>> He was expressing an opinion in the first paragraph, and he was asking
>> a question in the second. What school of debate did you attend that
>> mistakenly taught you to believe opinion and query to be argument?
>
> A creationist diploma mill?

Atheist idiots go through creationist diploma mills? That'd explain a lot.

> Opinions and questions are quite important in arguments, and in debates.

DUHR!

> What kind of delusion makes you think they aren't?

I don't disagree that "opinions and questions are quite important in
arguments, and in debates", but the point that went right over your tiny
pin-head is that opinions and questions are not arguments.

> Besides - these aren't really debates - they are news group posts.

Yah, unfounded opinion A beats unfounded opinion B.

--
I have defined no god. And when I do need to define some god for the
purposes of discussing its nature with atheists I always define the
supposed some god in the very same concrete and arbitrary terms, without
variation:

God = Metaphysical X

Watching you idiot atheists witlessly pinning your own lunatic
assumptions and irrational perceptions onto it then attempting to argue
against your very own deranged Frankenstein-like creation with utterly
b0rked illogic is a never-ending source of great hilarity.

Kadaitcha Man

3/21/2010 3:08:00 AM

0

"Smiler", thou mewling guilty creature. Thou heedless jolthead and
unmannered slave. Ye nagged:

> Kadaitcha Man wrote:
>> "IAAH", thou putrefying fever blister. Snakes, in my heart blood
>> warmed, that sting my heart. Thou Judas, thrice worse than Judas. Ye
>> whistled:
>>
>>> I don't know of any atheist who think the universe created itself out
>>> of nothing.
>>
>> Then how was it created?
>
> First show it was 'created'.

Idiot word-mincing atheist. It was "IAAH" who used the word created, in
"I don't know of any atheist who think the universe created itself out of
nothing."

Remember?

So, while you step up to what you have now made your very own challenge,
I'll just sit here and dole out your just reward to you. Laughter,
derision, scorn, ignominy and pillory.

--
I have defined no god. And when I do need to define some god for the
purposes of discussing its nature with atheists I always define the
supposed some god in the very same concrete and arbitrary terms, without
variation:

God = Metaphysical X

Watching you idiot atheists witlessly pinning your own lunatic
assumptions and irrational perceptions onto it then attempting to argue
against your very own deranged Frankenstein-like creation with utterly
b0rked illogic is a never-ending source of great hilarity.

Kadaitcha Man

3/23/2010 7:30:00 AM

0

"Father Haskell", thou pinch-spotted infidel. A dwarfish thief. Ye
yakked:

> On Mar 22, 3:20??am, Kadaitcha Man <a...@no.email> wrote:
>> "Smiler", thou pox-marked traitorous rout. Thy wit's as thick as a
>> Tewkesbury mustard. Ye chattered:
>>
>>
>>
>>
>>
>> > Kadaitcha Man wrote:
>> >> "Smiler", thou mewling guilty creature. Thou heedless jolthead and
>> >> unmannered slave. Ye nagged:
>>
>> >>> Kadaitcha Man wrote:
>> >>>> "IAAH", thou putrefying fever blister. Snakes, in my heart blood
>> >>>> warmed, that sting my heart. Thou Judas, thrice worse than Judas.
>> >>>> Ye whistled:
>>
>> >>>>> I don't know of any atheist who think the universe created itself
>> >>>>> out of nothing.
>>
>> >>>> Then how was it created?
>>
>> >>> First show it was 'created'.
>>
>> >> Idiot word-mincing atheist. It was "IAAH" who used the word created,
>> >> in "I don't know of any atheist who think the universe created
>> >> itself out of nothing."
>>
>> >> Remember?
>>
>> > Yep. No atheist believes it was created, either by itself out of
>> > nothing, or by a mythical god character.
>>
>> >> So, while you step up to what you have now made your very own
>> >> challenge, I'll just sit here and dole out your just reward to you.
>> >> Laughter, derision, scorn, ignominy and pillory.
>>
>> > Nice sidestep. Now show it was created.
>>
>> That's your job.
>>
>> > But, of course, you can't.
>>
>> I don't need to. For the word 'created', you may substitute the notion
>> of came into existence.
>>
>> Now, explain how it came out of nothing.
>
> Your presumption.

Really, now?

You never heard of the Penrose-Hawking singularity then, hey? According
to Penrose and Hawking, the universe had a beginning, from a singularity.
And guess what! The theorem requires a causality condition.

You will find a proven generalisation of the theory here:
http://www.jstor.org...

Now, about who the presumption belongs to...

--
I have defined no god. And when I do need to define some god for the
purposes of discussing its nature with atheists I always define the
supposed some god in the very same concrete and arbitrary terms, without
variation:

God = Metaphysical X

Watching you idiot atheists witlessly pinning your own lunatic
assumptions and irrational perceptions onto it then attempting to argue
against your very own deranged Frankenstein-like creation with utterly
b0rked illogic is a never-ending source of great hilarity.

Kadaitcha Man

3/24/2010 6:51:00 AM

0

"Father Haskell", thou slovenly theme of all our scorns. Go rot. Ye
regurgitated:

>> "Father Haskell", thou pinch-spotted infidel. A dwarfish thief. Ye
>> yakked:

>>> On Mar 22, 3:20??am, Kadaitcha Man <a...@no.email> wrote:

[the universe]

>>>> Now, explain how it came out of nothing.
>>>
>>> Your presumption.
>>
>> Really, now?
>>
>> You never heard of the Penrose-Hawking singularity then, hey? According
>> to Penrose and Hawking, the universe had a beginning, from a
>> singularity.
>
> The entire mass of everything squeezed down to a tiny point.

Wrong. Wrong. Wrong, and also wrong.

A singularity, in the case of the universe, is where a finite amount of
mass has infinite density and is compressed into zero volume; it is
therefore completely undefined. Zero volume equals what, tardlet?

Really, if you're going to be an atheist, you ought to grasp at least a
bit of basic science and mathematics.

--
I have defined no god. And when I do need to define some god for the
purposes of discussing its nature with atheists I always define the
supposed some god in the very same concrete and arbitrary terms, without
variation:

God = Metaphysical X

Watching you idiot atheists witlessly pinning your own lunatic
assumptions and irrational perceptions onto it then attempting to argue
against your very own deranged Frankenstein-like creation with utterly
b0rked illogic is a never-ending source of great hilarity.