|
-----Original Message----- From: rpg400-l-bounces@xxxxxxxxxxxx [mailto:rpg400-l-bounces@xxxxxxxxxxxx]On Behalf Of Hans Boldt Sent: Friday, October 17, 2003 12:28 PM To: rpg400-l@xxxxxxxxxxxx Subject: Re: The pulse of the Nation (Was: Please vote for Syntax check in /FREE!) Steve Richter wrote: > > In this case the compiler's response is that operator+ is ambiguous. To > clear up the ambiguity, the programmer could be allowed to specify the > return type, that is the full signature of the function: > <char>getMonth(x) + <char>getMonth(y) > Hans thought he had me and said: >But then, what's the difference between coding: > <char>getMonth(x) + <char>getMonth(y) > > and: > > getMonthAsChar(x) + getMonthAsChar(y) > > > eh? in the first version, the explicit return type is only needed if the operator+ is ambiguous. ( and if the procs are only overloaded on primitive return types like char and bin. in practice, one proc may return a string, others would return different data structures. In such a case, operator+ is not ambiguous. ) in the 2nd version, the "AsChar" always has to be typed out and effectively locks in place a dependency ( between the proc and the lhs of the expression ) that could hinder future changes to the code. CharFld = getMonth( x ) ; can be changed later on in the app dev cycle to: DecFld = getMonth( x ) ; // no problem! with less chance of error than: CharFld = getMonthAsChar( x ) ; is changed to: DecFld = getMonthAsChar( x ) ; // possibly not flagged as error // by the compiler. ( hope you dont feal badgered. I'm interested in the subject. ) Anyway, I am thinking that the need for procedure overloading may just be a placeholder for the need for namespaces. Where two procs, in two different include files, are allowed to have the same name because their arguments are different. In such a case, namespaces would be a better way to allow the procs to have the same name: Using overloading to distinguish two procs: PrintOrder( PurchaseOrder_DataStruct ) ; PrintOrder( CustOrder_DataStruct ) ; Better to use namespaces: purchasing::PrintOrder( arg1 ) ; customer::PrintOrder( arg1 ) ; -Steve
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.