realbasic-nug
[Top] [All Lists]

Re: Overloaded Operators

To: REALbasic NUG <realbasic-nug at lists dot realsoftware dot com>
Subject: Re: Overloaded Operators
From: Phil Mobley <phil at mobleybros dot com>
Date: Tue, 30 Nov 2004 12:41:12 -0800
Delivered-to: realbasic-nug at lists dot realsoftware dot com
References: <BDD0D861 dot 5C5FF%mars at realsoftware dot com> <0535FFB8-4308-11D9-B971-000393101B4A at mobleybros dot com> <a0620070bbdd27ef41871 at [10 dot 10 dot 13 dot 6]>
On Nov 30, 2004, at 11:52 AM, Joseph J. Strout wrote:

Function Operator_Add(x As Integer) As Rational

  Return Me + Operator_Convert(x)

End Function

Not with that exact syntax, but there is no reason you shouldn't have a private function that converts an integer to a Rational, which you can call from both your Operator_Convert and your Operator_Add methods (as well as anywhere else you need to do that conversion).

Of course if efficiency matters, you'll probably want to complexify your code enough to special-case the addition of an integer with a rational anyway. You can still have the AddRight methods call the Add methods though, since addition in this case is commutative.

At this point I am much more concerned with taking good advantage of code simplification to reduce the chance of hard-to-catch bugs. Having *one* method to take care of the actual math operation (no matter what the data type is) would help tremendously in this even at the cost of a little performance.

_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>

<Prev in Thread] Current Thread [Next in Thread>