Re: pros and cons of user-defined types



Bart Vandewoestyne wrote:
Hello all,


Because of an email of a collegue of mine, i started to ask
myself questions about the benefits and disadvantages of using
user-defined types.

Suppose you have the situation where you have a procedure with
lots and lots of arguments. Then i think it is good programming
style to group related arguments into user-defined types. And
for as far as I know, this 'making code more readable' is the main
benefit of replacing the large argument list by a smaller
argument list consisting of arguments of user-defined types.

My question is however: does this replacement also have a
drawback? In what way can it be disadvantageous to replace a
large argument list by something smaller consisting of
user-defined type arguments?

The only disadvantage that I could possibly think of is speed.
Whether that should be 'compilation speed' and/or 'execution speed',
I'm not quite sure...

Am I right that compilation and/or execution speed would be the only disadvantage(s) here? Or are there other possible disadvantages?

Having gone this route (using derived types for most stuff) the only disadvantage I routinely encounter is the simple make-work of writing the code to handle the derived type operations (allocate, destroy, etc) and their I/O (in my case both netcdf and "binary"). I overcame that with a tool that writes about 90% of the code and I tailor the remainder by hand.

Compilation speed is not an issue for me (but I know it is for others).

In my case, trying to measure execution speed in some meaningful sense has proven difficult enough that I don't really consider it until the application code I write ends up in the final application (radiative transfer model in a data assimilation system). Of course, I pay attention to the usual details that affect speed when designing/writing code, and I profile it also, but the maintainability and adaptability of the code is more important to me. If/when the NWP guys tell me the code is too slow, I make it faster -- and that's a lot easier to do when the source code is malleable; thanks in part to the judicious use of derived types.

cheers,

paulv
.



Relevant Pages

  • pros and cons of user-defined types
    ... style to group related arguments into user-defined types. ... benefit of replacing the large argument list by a smaller ... argument list consisting of arguments of user-defined types. ... Or are there other possible disadvantages? ...
    (comp.lang.fortran)
  • Re: pros and cons of user-defined types
    ... Because of an email of a collegue of mine, ... myself questions about the benefits and disadvantages of using ... style to group related arguments into user-defined types. ... argument list consisting of arguments of user-defined types. ...
    (comp.lang.fortran)
  • Re: pros and cons of user-defined types
    ... style to group related arguments into user-defined types. ... Am I right that compilation and/or execution speed would be the only disadvantagehere? ... Or are there other possible disadvantages? ... If you have a routine with many tens of arguments, certainly changing that to a single structure with sensible names can make it clearer what that routine is doing. ...
    (comp.lang.fortran)
  • Re: pros and cons of user-defined types
    ... Then i think it is good programming ... style to group related arguments into user-defined types. ... Or are there other possible disadvantages? ... like the data being plotted and a single array of parameters. ...
    (comp.lang.fortran)