J
jonathan leonard
Oops. Nevermind the part about losing functionality. However, I think
the discussion of self/super still applies.
--J
the discussion of self/super still applies.
--J
jonathan said:Why is the code above unadvisable?
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
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.)
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".
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, 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."
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.
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.
unknown said:I think you're laboring under a misunderstanding.
Please see http://dictionary.reference.com/search?q=simpleton
I don't think so.
see:
http://foreigndispatches.typepad.com/dispatches/2005/10/the_simpleton_d.html
or do a google search for 'simpleton design pattern' for many others.
unknown said:This seems to be some kind of play on words. "Simpleton" is not an
appropriate serious word for a language feature.
I don't think so.
I think you're laboring under a misunderstanding.
Please see http://dictionary.reference.com/search?q=3Dsimpleton
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.
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.