Serving the Quantitative Finance Community

 
User avatar
Cuchulainn
Posts: 20254
Joined: July 16th, 2004, 7:38 am
Location: 20, 000

Modern & Effective C++ design ideas

May 28th, 2014, 8:55 am

Quotestd::heterogenous<Shape*> means that it contains only 1 type: pointers to a Shape. It's not heterogenous, it's how you do it now with the list (the list is not heterogenous)IMO the exact opposite is true.Shape* s = new AnyDerived();Quotestd::heterogenous<Rectangle, Circle, Square > means that it contains elements that can be one of 3 typesstd::heterogenous<Rectangle*, Circle*, Square* > means that it contains pointers to elements that can be one of 3 typesDon't like this (hard-coded).What's the rationale here?
Last edited by Cuchulainn on May 27th, 2014, 10:00 pm, edited 1 time in total.
 
User avatar
Cuchulainn
Posts: 20254
Joined: July 16th, 2004, 7:38 am
Location: 20, 000

Modern & Effective C++ design ideas

May 28th, 2014, 9:16 am

Quoteif you do *this* Shape* p1 = new Circle();Shape* p2 = new Rectangle();then before you know it your program will crash somewhere *run-time* because you've mixed up p1 and p2 while getting confused of keeping track of the types you're casting about. If you use type-safety then the program won't compile because of that mistake. That's the design that most(?) OO systems are built (and CAD for sure). People do not mix up p1 and p2 and systems don't crash. C'mon. Quotetype-safety & efficiency. You will always have a finite set of types that you have coded. When you compile you program you will include those types e.g. via header files. The set of types you use is finite and known compile-time.I think you see this as stuff like cdf() and pdf() in Boost. But this is not the same kind of problem, really.My Visitor solution with CRTP is type safe and efficient but is not flexible enough for CAD applications. Plan B: GOF Visitor.
Last edited by Cuchulainn on May 27th, 2014, 10:00 pm, edited 1 time in total.
 
User avatar
Cuchulainn
Posts: 20254
Joined: July 16th, 2004, 7:38 am
Location: 20, 000

Modern & Effective C++ design ideas

May 28th, 2014, 9:32 am

Quotetype-safety & efficiency. Tradeoff is reduced functionality. It is a constrained optiminisation problem. You can't have all three.
 
User avatar
Cuchulainn
Posts: 20254
Joined: July 16th, 2004, 7:38 am
Location: 20, 000

Modern & Effective C++ design ideas

May 28th, 2014, 11:05 am

QuoteOriginally posted by: outrunQuoteOriginally posted by: Cuchulainn2. hmm, a lot of maintenance. In my CAD I have about 20-30 different kinds of drivers.So each shape has 20-30 member functions?NO^2Shapes have minimal functionality. Visitor basics. Extra func in drivers. This old stuff (still works) show the idea of Rotate + STATE!
Last edited by Cuchulainn on May 27th, 2014, 10:00 pm, edited 1 time in total.
 
User avatar
Cuchulainn
Posts: 20254
Joined: July 16th, 2004, 7:38 am
Location: 20, 000

Modern & Effective C++ design ideas

May 28th, 2014, 11:17 am

Quotestruct MyBase {};struct MyInt : MyBase {int i; };struct MyDouble : MyBase {double d; };std::list<MyBase *> container;for (unsigned i=1; i<10; ++i) {container.push_back( new MyInt() );container.push_back( new MyDouble() );}.. that's horrible inefficient. Nobody will want to use that code. Instead we need something like:According to you. 90% of developers use this approach. Propose: Use Shape* to keep on a single example, instead of context switchng.
 
User avatar
Cuchulainn
Posts: 20254
Joined: July 16th, 2004, 7:38 am
Location: 20, 000

Modern & Effective C++ design ideas

May 28th, 2014, 11:22 am

QuoteOriginally posted by: outrunI also want to know if you have 20-30 driver member functions for each shape? I've just given the answer: Shape classes have minimal functionality.
 
User avatar
Cuchulainn
Posts: 20254
Joined: July 16th, 2004, 7:38 am
Location: 20, 000

Modern & Effective C++ design ideas

May 28th, 2014, 11:24 am

QuoteOriginally posted by: outrun.. my point about generality and *all* those efficiency issues is valid. I can rename MyBase* to Shape* and it's all te same.Also this
 
User avatar
Cuchulainn
Posts: 20254
Joined: July 16th, 2004, 7:38 am
Location: 20, 000

Modern & Effective C++ design ideas

May 28th, 2014, 11:26 am

QuoteOriginally posted by: outrunAccording to you 90% of developers use this approach. ..not in my pool of professional coders.Not my opinion, just what I have seen. And it's well-known.Has your 'pool' published any work to show the others how to do it?
Last edited by Cuchulainn on May 27th, 2014, 10:00 pm, edited 1 time in total.