Syntax sugar: treating an object like a method

> > I'm not sure what the canonical definition of syntactic
> > is, but
> > I don't think that I think this is exactly that.
> In my book, syntactic sugar is when you have a more
> concise/readable syntax that is equivalent to a more
> fundamental (and longer) syntax. So by that definition,
all of
> the operators that equate to methods are syntactic sugar.
> think this thing I'm talking is similar to adding another
> operator.

I think the key element is that syntax sugar should shorten
the syntax,
but should _not_ have the side-effect of making two very
similar pieces
of well-known code to behave differently - which is what it
looks like
in this case.

I guess you are referring to the fact that "calling" an object
(using a would the "null" method) looks similar to calling a
method. You would have to figure out which is which. You'd
get an error now by "calling" an object, so there would be no
compatibility issue.

From that qualification I guess a simple method call with no
args (or parens) would not be syntactic sugar to you since it
also looks like a local variable. I still consider it sugar,
but I guess you don't.

> > > 1. Allow a null/default method to be defined in a class
> > that
> > > the syntax "obj(*args,&block)" could be used. obj
could be
> > any
> > > expression yielding a object. When you try to treat
> > > object as a method passing arguments and/or attaching a
> > code
> > > block to it, the null/default method would be called.
> > was
> > > thinking "@" would be a good name for this method -
> > "+@"
> > > and "-@". Here are a few example uses:
> > >
> > > * klass(*args) : you alias the null method to "new" so
> > > this would be equivalent ot*args). I tend
> > forget
> > > the ".new" more often than I'd like to admit.
> >
> > Forgetting .new is a weak reason for making it optional.
> > would be
> > hard to argue that calling to create a new
> > MyClass object
> > is arcane or hard to get the hang of.
> I know it is weak. But, it did seem to prod me to develop
> idea a little more - because the vast majority of time the
> thing you do with a class is call new.

I'd agree that most users will just want most of
the time, but
it's pretty standard amongst languages these days and helps
distinguish that "yeah, he's creating a new instance of the
there". Beyond that, what if I actually wanted a handle on
the class and
to assign the class to a variable. Do we add syntax for that

> > > * (str) = value : this could default to "replace" for
> > > objects that respond to it (or if you use evil.rb -
> > "become")
> > >
> > > * (mutable) += value : now the real += can be
> > for
> >
> > += is already the real +=. It's not the C or Perl +=,
> > it's the
> > real Ruby +=.
> Correct. "real" was the wrong word. How about "in-place"?
> normal += in Ruby creates a new object whereas this one
> modifies an object in-place.

Following our already established "in-place" method naming
it'd actually be "=!" which would make me mistake it for "!="
way too
often. And the subtle parentheses around the variable is way

In short, I don't see a great need for these,

There definitely is not a great need for this syntax since it
just makes some code more concise (and maybe prettier). That's
why I call it sugar.

and I think the
differences are too subtle and will lead to everyone
scratching their
heads wondering why their code is behaving so oddly...

I won't argue with that.

Discover Yahoo!
Stay in touch with email, IM, photo sharing and more. Check it out!