Ruby Syntax: 'initialize' versus 'init'

While programming with Ruby, I’ve grown to love just how clear and
concise
the language is. (You all already know this of course).

So, why is the object constructor so long? I mean ‘initialize’ could
easily
be replaced with ‘init’ or even just plain ‘new’.

In support of this idea, I’ve noticed that to_string() is written to_s.
The
same is with arrays, integers, and floats.

Even in the Pickaxe book it points out that the spelling of ‘initialize’
as
being a gotcha. ‘Init’ seems simpler, to the point, and harder to
mispell.

Am I missing any major reasoning behind using the term ‘initialize’?
(Besides the fact that is is the status quo)

-Clint

Clint Checketts wrote:

While programming with Ruby, I’ve grown to love just how clear and concise
the language is. (You all already know this of course).

So, why is the object constructor so long? I mean ‘initialize’ could easily
be replaced with ‘init’ or even just plain ‘new’.

In support of this idea, I’ve noticed that to_string() is written to_s. The
same is with arrays, integers, and floats.

I suspect people call to_* more often than they call initialize.

But, poor speller that I am, one of the first gvim macros I wrote to
assist my Ruby hacking was a mapping that turned

defi

into

def initialize( )

end

So it became a non-issue for me.

(The other day I shoulder-surfed as someone coded Ruby using Notepad,
and it was so painful to watch even my hair hurt.)


James B.

“Blanket statements are over-rated”

There is a difference in wrapping to interface to C
new() would usually call rb_obj_call_init(…)
and return the class instance.
initialize() usually would set up data.

Ruby is specially designed to be friendly to use and read.
unix commands, by contrast, would be considered unfriendly,
but quicker to type. ‘initialize’ is within that friendly spirit.

Gerald

Hi,

In message “Re: Ruby Syntax: ‘initialize’ versus ‘init’”
on Sat, 4 Feb 2006 10:50:11 +0900, Clint Checketts
[email protected] writes:

|Am I missing any major reasoning behind using the term ‘initialize’?
|(Besides the fact that is is the status quo)

It can be very critical when the name of initializing method conflicts
with others, so that I chose “initialize” to avoid potential problems.
Besides that, the name was derived from T language (Scheme dialect).

						matz.

Yukihiro M. [email protected] writes:

Besides that, the name was derived from T language (Scheme dialect).
Interesting you mention T, one question I always wanted to ask is:
Did the T object system influence the design of the Ruby object system?
(Or do you wish it did? ;))

Hi,

On 2/4/06, Christian N. [email protected] wrote:

Interesting you mention T, one question I always wanted to ask is:
Did the T object system influence the design of the Ruby object system?
(Or do you wish it did? ;))

No. I’ve heard it was pretty interesting but I didn’t have any chance
to get the detail more than a small article, which mentioned an
intializer named “initialize”.

matz.

Yukihiro M. [email protected] writes:

intializer named “initialize”.
It’s very lightweight and almost trivial. In fact, I once ported it
to Ruby:

http://chneukirchen.org/blog/archive/2005/03/the-t-object-system-in-ruby.html

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs