Re: better way to name optional argument
- From: Gary Scott <garylscott@xxxxxxxxxxxxx>
- Date: Sat, 08 Mar 2008 19:16:51 GMT
Mike wrote:
HiSometimes, the use of optional arguments isn't the best design. A more positive approach might be (depending on what you're really trying to do) to include a "processing type" (or "function code") argument. Optional arguments are more often useful for items which have a default value that works in most cases, but you might want to change it on rare occasion, like an API call to initiate an MDI window that defaults to cover its entire child area but you might optionally want it to be minimized.
I'd like to ask how you name the variable of optional argument?
For an existent subroutine, I'd like to add an optional argument to do
some test:
1a/ integer :: iTEST
if(present(iTEST))then
print *,iTEST,'do some test!'
else
print *,iTEST,'no need to do some test!'
end if
1b/ or
if(iTEST==1)then
print *,iTEST,'do some test!'
else
print *,iTEST,'no need to do some test!'
end if
2a/ logical :: lTEST
if(present(lTEST))then
print *,lTEST,'do some test!'
else
print *,lTEST,'no need to do some test!'
end if
2b/ or
if((lTEST))then
print *,lTEST,'do some test!'
else
print *,lTEST,'no need to do some test!'
end if
I don't know which one is a meaningful one.
It goes much complicated when there are also optional arguments to be
set when optional argument TEST is a must. I'd like to set two
parameters: ipar1,ipar2.
I am also confused how is the best way to set the if ... else ....end
if.
Any suggested example would be very much appreciated.
Mike
--
Gary Scott
mailto:garylscott@sbcglobal dot net
Fortran Library: http://www.fortranlib.com
Support the Original G95 Project: http://www.g95.org
-OR-
Support the GNU GFortran Project: http://gcc.gnu.org/fortran/index.html
If you want to do the impossible, don't hire an expert because he knows it can't be done.
-- Henry Ford
.
- References:
- better way to name optional argument
- From: Mike
- better way to name optional argument
- Prev by Date: Re: better way to name optional argument
- Next by Date: MS Word and "Fortran"
- Previous by thread: Re: better way to name optional argument
- Next by thread: Re: better way to name optional argument
- Index(es):
Relevant Pages
|
|