|
Prev: gfortran problem
Next: Generic Programming - What Is the Best Method? (Was: Intelligent macros .vs. BITS)
From: Gerry Ford on 1 Apr 2008 00:20 "Craig Powers" <enigma(a)hal-pc.org> wrote in message news:47f16d7d$0$1732$a726171b(a)news.hal-pc.org... > Craig Dedo wrote: >> >> I would like to throw out a thought question: >> >> What is the best way to implement generic programming and generic >> procedures? What are the trade-offs involved in various approaches? >> What languages use the best approaches? What improvements could be made >> in those approaches? What languages do it badly and what are the >> shortcomings of those approaches? >> >> I'm looking not only for ease and robustness of implementation, but >> also robustness and ease of use in using the generic programming feature >> for developing applications in Fortran. > > My main experience with using generic programming is templates in C++. > Unfortunately, I haven't used them extensively enough to comment on their > major shortcomings, nor have I used other forms of generic programming > enough to comment on the relative advantages and disadvantages of C++. > However, if you were to ask that question in a C++ newsgroup (e.g. > comp.lang.c++.moderated) you would probably get some very good answers > about the plusses and minuses of C++ itself, and you might even get some > good comparitive info from anyone who has used another language with > generic programming features. http://www.stlport.org/resources/StepanovUSA.html The above is an informative link and below is an excerpt. Question: Could you explain to a modest C++ programmer what Generic Programming is, what is the relation of Generic Programming with C++ and STL, and how did you come to use Generic Programming in a C++ context? Answer: Generic programming is a programming method that is based in finding the most abstract representations of efficient algorithms. That is, you start with an algorithm and find the most general set of requirements that allows it to perform and to perform efficiently. The amazing thing is that many different algorithms need the same set of requirements and there are multiple implementations of these requirements. The analogous fact in mathematics is that many different theorems depend on the same set of axioms and there are many different models of the same axioms. Abstraction works! Generic programming assumes that there are some fundamental laws that govern the behavior of software components and that it is possible to design interoperable modules based on these laws. It is also possible to use the laws to guide our software design. STL is an example of generic programming. C++ is a language in which I was able to produce a convincing example. When I first read this a couple weeks ago, I wondered what this looks like in fortran: template <class StrictWeakOrdered> inline StrictWeakOrdered& max(StrictWeakOrdered& x, StrictWeakOrdered& y) { return x < y ? y : x; } and template <class StrictWeakOrdered> inline const StrictWeakOrdered& max(const StrictWeakOrdered& x, const StrictWeakOrdered& y) { return x < y ? y : x; } -- "I am waiting for them to prove that God is really American." ~~ Lawrence Ferlinghetti |