Generative Programming aka Modern C++
Just curious how many shops are using this template heavy method of development? If you are using it, is it limited to making use of Boost or are you retooling to move full bore in this direction?
Curious Dev Manager
Friday, April 23, 2004
If your project needs to be heavily data-driven at runtime, the template-heavy approach may be detrimental since it can easily cause you to make things more code-driven than you might prefer (I'm not saying it _has_ to be that way, but that's the path of least resistance unfortunately).
But more importantly, this kind of approach tends to make build times skyrocket. Even if you use tools like IncrediBuild, they'll only help your compile times; linking will still be extremely painful. If your development style is predicated on rapid iteration, going template crazy is the worst thing you can possibly do for your productivity.
All this policy-oriented "Modern C++ Design" template stuff may be cool/new/whatever, but it has some very pragmatic ramifications which affect projects that are either large, require rapid iterative turnaround, or both. Caveat emptor.
BadgerBadgerBadger
Friday, April 23, 2004
That response was spot on... I think it is a nice idea and sometimes very elegant an interesting (sometimes not). But I would be very surprised if anyone goes full bore on these techniques in a real software shop which actually ships regularly.
It is basically only useful when you need code that is both maximally flexible and maximally efficient. If you just want flexible code, do things at runtime rather than at compile time (which is basically the point of modern C++, to do as much calculation as possible at compile time). If you need maximally efficient code, you're better off optimizing what you need rather than optimizing everything.
It also tends to trades off space efficiency for time efficiency, which is not always what you want either.
Roose
Friday, April 23, 2004
We are using Boost and a bit of Loki, the Loki stuff could probably be replaced by boost::mpl now...., but anyway.
It's about using common sense, use it when and where it is useful.
Let it complement what you currently do.
On the current project we are using Lambda, Regex, Spirit, Smart Pointers, MPL, Date Time, Formating, Any, Utility and Function Pointers.
It's all useful stuff, compile times do get larger, but you tend to catch errors at compile time, rather than runtime.
Also you sometimes have to stop over zealous programmers attempting to write incomprehencible compile time code, but this is something they probably have a tendancy to do anyway.
So in summary, it's worked great for us :), just be careful.
Craig
Friday, April 23, 2004
BTW, this is a large scale commercial Telco product.
Which is in it's second shipping version.
Craig
Friday, April 23, 2004
All of the "template metaprogramming" described in modern cpp design, the boost libraries (notably boost::mpl), etc. isn't really geared towards run of the mill application programing. What it IS geared toward is writing libaries to be used by said applications.
If you aren't writing a library of some sort, then you won't see need these intricacies. Just use the libraries and be happy. That being said, it is nice to have the option to create some powerful libraries of your own, just do so out of need.
Another time to consider using advanced template techniques is anytime you are considering writing or buying a wizard or code generator. In most situations I've seen where a code generator was required, either the language was weak or the libraries were weak.
Tito
Friday, April 23, 2004
Hm, that is a good way to say it... basically only use it for libraries. Libraries are the prime example of code where you need to be maximally efficient and maximally flexible. You are willing to trade off development time for efficiency and flexibility, because the library is supposed to be reused and thus save you development time in the future.
But typical application code does not need any of those techniques (nor have I really seen any application code that uses them).
Roose
Friday, April 23, 2004
We are starting to use it heavily in for applications (MPL and all) in a commercial programming context. What this means in our shop is that our application frameworks (mostly server-side) have been rewritten to be generative.
It is too early to tell if this has been a good move, we are still building out the frameworks. Compile times have definitely gone up, but server development isn't nearly as iterative as UI work. We do spend some time fighting the compiler as well (MSVC 7.1) -- including modifying designs to be more "compilable."
Just trying to get a sense for how far out on the bleeding edge we are. Seems like we are pretty far out there from the other responses.
Curious Dev Manager
Saturday, April 24, 2004
While the technique may be OK (or cool or elegant or whatever) the problem is in finding people that understand the technique.
For an average company that hires average programmers it's probably not a good idea to use cutting edge techniques.
Jorel on Software
Saturday, April 24, 2004
To " Curious Dev Manager "
I'm curious, what kind of uses are you finding for MPL?
Craig
Saturday, April 24, 2004
If it is an embedded telco product than it is likely
your memory requirements will go through the
roof.
son of parnas
Sunday, April 25, 2004
We primarily use MPL to define and operate on variable parameter lists when we want type safety. For example, we use it describe both the parameters and the result set for our stored procedure execution library.
Curious Dev Manager
Sunday, April 25, 2004
What advantage do you gain over using tuples?
Craig
Sunday, April 25, 2004
I used templates and STL on a project 4 years back. That was crossplatform on Sun and Windows. That was when everyone issuing guidelines "not to use STL" for cross platform project.
We went ahead anyway. We used templates for all collections and iterators. It was a success. Primarily because writing a good collection class like vector, map etc. is difficult. So if you getting something tuned for your platform why not use it.
In fact, we actually improved the runtime performance of some algorithms by switching from vectors to stl maps.
About compile times, my observation is compile times are affected more by indescriminate #includes. (esp headers files including headers including header ...). Even you are using header guards (#ifndef, #define , #endif), still compiler has to parse the .h files everytime (and throw it away from second time). Just by being desciplined in #includes cut down our project compilation time quite a lot.
So my advice use template. But make sure that your team has atleast 1 or 2 guys who understand templates. Its very easy to shot yourself in foot when you are using templates.
Nitin Bhide
Tuesday, April 27, 2004
Recent Topics
Fog Creek Home
|