Skip to content
Prev 37135 / 63424 Next

Defining a method that behaves like '$'?

On Fri, Jul 9, 2010 at 2:10 PM, Renaud Gaujoux
<renaud at mancala.cbio.uct.ac.za> wrote:
Even if possible, definitely not desirable. As already mentioned, a:b
is the sequence a to b (as in 0:10), so it's going to look weird to
anyone who hasn't noticed your definition. Also, it looks fairly
meaningless. By which I mean there's no obvious reason why a colon
should do what you want it to do. There's also no obvious reason why a
dollar sign does what it does (whats it got to do with dollars?) but
we've had it for 20 years so we're stuck with it.

 Write a method for your objects and force your users to do a bit more
typing as a trade-off for legibility:

 slot1(a,"toto")

 is a lot more readable than a:toto (assuming you replace 'slot1' with
something meaningful).

 Remember, code is most likely to be written once, and read many times
- so make it easy for readers!

Barry