Re: Coding Standards
H <H@r.c> wrote in news:LmPBi.28851$4A1.15145@news-server.bigpond.net.au:
davidsamith@gmail.com wrote:
'Good code' is code that works, is bug free, and is readable and
maintainable. Standards need to be followed for coding. Read more...
http://brsx.co.uk/SWtesting/FAQs/FAQs012.asp
This says to increase maintainability, we should minimise operator
overloading. I'm new at this and confused, I thought operator
overloading (used correctly) aided maintainability and readability?!??
Well, it's a double-edged sword. If you are modeling a mathematical class
where the normal operators are well-known and understood (i.e. complex
arithmetic) then the overloaded operators make a whole lot of sense and in
general are a good thing. However, if you are adding somewhat arbitrary
meaning to the operators like having + sort do a search on a list or
something, then it adds to the confusion level because the '+' symbol
itself offers no clues to the operation being performed and worse it hints
that some sort of additive action is taking place.
Really, there isn't a whole lot of difference between operator overloading
and normal function overloading done badly. What I mean is, it is just as
bad to have a function named 'print' that does a search operation as it is
to abuse the binary operators, at least from a code maintenance aspect.
joe