About class methods

J

jonathan leonard

Oops. Nevermind the part about losing functionality. However, I think
the discussion of self/super still applies.

--J
 
E

Eero Saynatkari

jonathan said:
Why is the code above unadvisable?

I personally think the idiom is a bit suspect but it could
just be I have not come across the need for it :) The above
merely illustrates that it is quite possible to do that in
ruby; however, another way might lead to a better design.

(Generally, any types of factories are simple in ruby and
the whole duck-typing thing helps, too.)


E
 
G

Gene Tani

Martin said:
jonathan said:
Hmm.. Ok. But, with Ruby, you can still dynamically create subclasses
that aren't singletons and extend them as well as instanciate instances
of them, right? That would provide the flexibility I was referring to
above, but I suppose it would require typing quite a few more
characters. So do I understand correctly that Matz designed the whole
singleton creation mechanism ( << ) as a shorthand for doing more
long-winded dynamic creation/enhancing?

It's not a subclass, it's an anonymous proxy superclass. It goes into
the inheritance chain between the object it extends and the class that
object derived from, like so (assume a is a String):

[String] --- [class << a] --- [a]

Since ruby doesn't have multiple inheritance, you can see why there can
(and need!) only be a single proxy superclass.

martin

How about this old chestnut, which I frankly don't understand:

http://onestepback.org/images/rubyobjects.png
 
J

jonathan

Eero said:
I personally think the idiom is a bit suspect but it could
just be I have not come across the need for it :) The above
merely illustrates that it is quite possible to do that in
ruby; however, another way might lead to a better design.

(Generally, any types of factories are simple in ruby and
the whole duck-typing thing helps, too.)

I don't really see how duck-typing is relevant, but I would assume that
the idiom used above (i.e., 'const_set', 'class_eval', and
'define_method') could be done in an extension factory (rather than
procedurally as above). In other words, you might have a factory called
JumpExtensionFactory which could create any object that can jump (e.g.,
people, animals, monsters, etc.) from a non-jumping object say in a
video game model.

I suppose it would have to calculate the maximum jump height and length
based on other statistics such as leg strength, weight, etc. (which
would presumably have to be attributes the object already has or can
acquire) and the actual jump height and length based on run-time
attributes such as velocity and input force. That is the purpose I can
see for this sort of thing. Is that what you mean by utilizing
factories?

The only real problem I see with this is you really wouldn't want to
create a new object, but rather extend the original one. In other
words, after a type learns to jump, then all objects of that type should
be able to jump (so there's no need to distinguish from a non-jumping
version and the jumping version). So, actually, I would call it an
JumpExtender or a JumpTeacher (instead of JumpExtensionFactory).

(Thinking out loud here). But, hopefully we're closer to the same page
now.

--J
 
D

Dave Howell

By the way . . . has anyone considered a name like "singular"? What
about "ad lib" instead of "ad hoc"?

I've gotta say, though, that I'm partial to the descriptor "eigen".

Well, I'm having a terrible time following the distinction between the
indefinite number of flavors of this difficult-to-name type of method,
but I do know something about naming things. :)

Generally, trying to find an existing term, like 'singleton' or 'ad
hoc', is a good thing, because lets somebody bring pre-constructed
expectations to the process, hopefully saving them time in learning how
this particular thing works.

Unless, of course, different people have different expectations for
that word, or if the thing in question contradicts the expectations in
some way.

If 'simpleton' and 'singleton' are equally applicable to either of two
different cases, as somebody suggested earlier, then these will lead
people to *think* they know what will happen, but there's a 50/50
chance that it will be the other. So that's not a good thing. There
appears to be some concern that "ad hoc" implies something much broader
(?) than this particular usage actually has. That's not a good thing.

If you have a situation where none of the existing reasonable terms
seem like an adequately non-confusing match, then it's actually much
better to use a term that *doesn't* bring a lot of pre-conceived
baggage to the table. If you create a term that's *obviously*
meaningless or ambiguous, then the first-time user knows right away
that they'll have to look it up, instead of erroneously thinking they
know what it does just because of the name. Calling them something like
"intral methods", "uni methods", "anonic methods," or "eigenz" is
better than using a "real" pre-existing word that is a poor fit. "Hmm.
Uni methods. Well, I have a hunch what that might be for, but it isn't
immediately obvious. I'll just have to read more about it to find out
what they actually do."
 
M

Michael Ulm

Dave said:
--snip--

If you have a situation where none of the existing reasonable terms seem
like an adequately non-confusing match, then it's actually much better
to use a term that *doesn't* bring a lot of pre-conceived baggage to the
table.

Well, then there is obviously only one logical choice:

Chunky Bacon Class!

Regards,

Michael

--
Michael Ulm
R&D Team
ISIS Information Systems Austria
tel: +43 2236 27551-219, fax: +43 2236 21081
e-mail: (e-mail address removed)
Visit our Website: www.isis-papyrus.com
 
D

dblack

Hi --

Well, I'm having a terrible time following the distinction between the
indefinite number of flavors of this difficult-to-name type of method, but I
do know something about naming things. :)

Generally, trying to find an existing term, like 'singleton' or 'ad hoc', is
a good thing, because lets somebody bring pre-constructed expectations to the
process, hopefully saving them time in learning how this particular thing
works.

Unless, of course, different people have different expectations for that
word, or if the thing in question contradicts the expectations in some way.

If 'simpleton' and 'singleton' are equally applicable to either of two
different cases, as somebody suggested earlier, then these will lead people
to *think* they know what will happen, but there's a 50/50 chance that it
will be the other. So that's not a good thing. There appears to be some
concern that "ad hoc" implies something much broader (?) than this particular
usage actually has. That's not a good thing.

If you have a situation where none of the existing reasonable terms seem like
an adequately non-confusing match, then it's actually much better to use a
term that *doesn't* bring a lot of pre-conceived baggage to the table. If you
create a term that's *obviously* meaningless or ambiguous, then the
first-time user knows right away that they'll have to look it up, instead of
erroneously thinking they know what it does just because of the name. Calling
them something like "intral methods", "uni methods", "anonic methods," or
"eigenz" is better than using a "real" pre-existing word that is a poor fit.
"Hmm. Uni methods. Well, I have a hunch what that might be for, but it isn't
immediately obvious. I'll just have to read more about it to find out what
they actually do."

A couple of problems with that, in this particular case:

First, there's an existing term (singleton method/class) that's under
review by Matz, with input from the community. That means that
calling them "potato-peel classes", or whatever, not only adds
confusion but short-circuits a process that's already underway and
that promises to result in a decision and clarification.

Second, you can't read more about the thing if you don't know what
it's called. All this renaming just adds an extra layer of having to
learn about the history of ruby-talk, as well as the features of the
Ruby language, in order to know what people are talking about in the
first place. The advantages of this elude me. I think the community
would be well advised not to assume that the world's interest in
keeping track of who uses which home-made synonym for "singleton
class" is unlimited.


David
 
J

jonathan leonard

Dave said:
Generally, trying to find an existing term, like 'singleton' or 'ad
hoc', is a good thing, because lets somebody bring pre-constructed
expectations to the process, hopefully saving them time in learning how
this particular thing works.

I believe, and there is a slight chance that I'm wrong, that the terms
simpleton and singleton are synonymous.

--J
 
J

jonathan leonard

Dave said:
If 'simpleton' and 'singleton' are equally applicable to either of two
different cases, as somebody suggested earlier, then these will lead
people to *think* they know what will happen, but there's a 50/50
chance that it will be the other. So that's not a good thing.

Well, I think 'simpleton' and 'singleton' are synonymous terms (about
98% sure of that if this were a lifeline). But, the problem would
remain if singleton isn't a good fit to begin with. I actually think
singleton is a good fit and therefore so is simpleton.

--J
 
J

jonathan

unknown said:
This seems to be some kind of play on words. "Simpleton" is not an
appropriate serious word for a language feature.

Yea, I agree there is some word playing going on (it may be kinda like
releasing a virus into the wild). Some of what the search turned up was
making fun of the singleton pattern by calling it simpleton (and the
rest could have been accidental misuses). However, I could have sworn
that I saw this word used in a more legitimate place (such as a lecture
or textbook). If I run across a more authoritative source, I'll share
it.

Nevertheless, I have to disagree with your 'serious' requirement for
words for language features in general and, in particular, concerning
simpleton. Take for instance, 'duck typing'. And, I see nothing wrong
with simpleton either, if there were an actual language construct which
fit the word; although, I admit, it might not fit for 'singleton' as
much as I initially thought.

However, if you expand your search, you can find people refering to code
modules as simpletons, based on the fact that they have a limited,
simple set of functionality (check out this page for instance):

http://www.roxie.org/knownspace/api_design.html

and it does seem to fit their architecture.

--J
 
L

Logan Capaldo

--Apple-Mail-9--492653464
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain;
charset=UTF-8;
delsp=yes;
format=flowed


I think you're laboring under a misunderstanding.

Please see http://dictionary.reference.com/search?q=3Dsimpleton

Just for comparision:
singleton |=CB=88si ng g=C9=99lt=C9=99n| |=CB=8Cs=C9=AA=C5=8Bg=C9=99lt(=C9=
=99)n| |=CB=8Cs=C9=AA=C5=8Bg(=C9=99)lt(=C9=99)n|
noun
a single person or thing of the kind under consideration : splitting =20
the clumps of plants into singletons.
=E2=80=A2 [often as adj. ] a child or animal born singly, rather than =
one of =20
a multiple birth : singleton boys.
=E2=80=A2 (in card games, esp. bridge) a card that is the only one of =
its =20
suit in a hand.
=E2=80=A2 Mathematics & Logic a set that contains exactly one element.
ORIGIN late 19th cent.: from single , on the pattern of simpleton.






--Apple-Mail-9--492653464--
 
J

jonathan

Logan said:
Just for comparision:
singleton |ˈsi ng gəltən| |ˌsɪŋgəlt(ə)n| |ˌsɪŋg(ə)lt(ə)n|
noun
a single person or thing of the kind under consideration : splitting
the clumps of plants into singletons.
• [often as adj. ] a child or animal born singly, rather than one of
a multiple birth : singleton boys.
• (in card games, esp. bridge) a card that is the only one of its
suit in a hand.
• Mathematics & Logic a set that contains exactly one element.
ORIGIN late 19th cent.: from single , on the pattern of simpleton.

What is the source of this definition? This could be my vindication. :)

--J
 

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,773
Messages
2,569,594
Members
45,125
Latest member
VinayKumar Nevatia_
Top