1 / 21

Generatív programozás

Generatív programozás. Porkoláb Zoltán ELTE Általános Számítástudományi Tanszék gsd@inf.elte.hu. ECOOP 2001. Generative Programming (Czarnecky, Eisenecker) Aspect-Oriented Programming (Gregor Kitzales) Feature Interaction in Composed Systems (Jim Coplien)

rich
Télécharger la présentation

Generatív programozás

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Generatív programozás Porkoláb Zoltán ELTE Általános Számítástudományi Tanszék gsd@inf.elte.hu

  2. ECOOP 2001 Generative Programming (Czarnecky, Eisenecker) Aspect-Oriented Programming (Gregor Kitzales) Feature Interaction in Composed Systems (Jim Coplien) Advance Separation of Concerns (...) Multiparadigm Programming in OO Languages (Smaragdakis)

  3. Generic Programming • Fordítás idejű típusellenőrzés • Automatikus példányosítás • Hatékony ( vs. Reflection ) • Egyszerű (?) • negatív variancia: template specializáció • (Paraméteres) Polymorfizmus

  4. GP - Standard Template Library • A. Stepanov, D. Musser • ADA, C++, JAVA (Pizza, GJ, Collection) • C++ Standard Template Library • tárolók (containers) • algoritmusok • bejárók (iterators) • Az ISO C++ standard része (1997)

  5. Standard Template Library Find Iterator Vector Merge Iterator Iterator List

  6. GP - OO együttműködés • C++ Standard Library (!= STL) • Interfész-méret csökkentése • Template specializáció template <class CharType, class Attr=char_traits<CharType>, class Allocator=allocator<T>> class basic_string { … }; typedef basic_string<char> string;

  7. Aspect-Oriented Programming • Probléma - gyenge modularitás: • erőforrásmegosztás • hibakezelés • hatékonyság, optimalizáció • Megoldás - a határok átlépése: • az elszórt szempontok összegyűjtése (aspect) • szövőgép (weaver) a végső kód elkészítéséhez

  8. AOP - OO Példa Rendszerállapot vizsgálata A rendszer: public class Variable { private int v; public Variable() { v = 0; } public int getV() { return v; } public void setV(int v) { this.v = v; } }

  9. AOP - Monitoring Cél: Minden változást írjunk ki • ne módosítsuk (kézzel) az eredeti kódot • kerüljük a futási idejű költségeket Megoldás: • producer-observer patternintrospection - metódhívások eltérítése

  10. AOP - Aspect aspect Trace { advise * Variable.*(..) { static before { System.out.println("Entering " + thisJoinPoint.methodName + " v=" + thisObject.v); } static after { System.out.println("Exiting " + thisJoinPoint.methodName + " v=" + thisObject.v); } } }

  11. AOP - A szövőgép public class Variable { private int v; public Variable() { v = 0; } public int getV() { int thisResult; System.out.println("Entering "+"getV"+" v="+this.v); thisResult = v; System.out.println("Exiting "+"getV"+" v="+this.v); return thisResult; } public void setV(int v) { System.out.println("Entering "+"setV"+" v="+this.v); this.v = v; System.out.println("Exiting "+"setV"+" v="+this.v); } }

  12. AOP - OO együttműködés • Kódismétlés csökkentése • Természetes OO tervezés alkalmazható valós, nagy rendszerekre • Aspect -eket tetszőleges nyelven írhatunk • korlát: a szövőgép

  13. Domain-specifikus nyelvek • Külső: TeX, SQL • Beágyazott: C++ template • Összeépíthető komponens: Intentional prog. Célorientált, specializált nyelv, valamely feladat megoldására

  14. A template technika korlátai template <class T> class Container { // ... void insert( T x) { ... } void sort() { if (x < y )... } // ... }; Csak a hivatkozott template-ek példányosulnak!

  15. Concept checking template <class T> void sort() { SortHelper< StaticIsA<T,LessThanComparable<T> >::valid>::doIt(); // ... }; Szabadon definiálható hibaüzenetek

  16. Mixin template <class Super> class Mixin : public Super { // ... }; Bázisoszály: fordítási paraméter OO + GP együttműködése

  17. template <class Super> class Mixin : public Super // ... }; class Base_virt { virtual void f(); }; class Base_novirt { void f(); }; Mixin<Base_virt> x; Mixin<Base_novirt> y;

  18. template <class Graph> class Counting : public Graph { int nodes_visited, edges_visited; public: Counting():nodes_visited(0),Graph(){} node succ_node(node v) { ++nodes_visited(node v); return Graph::succ_node(v); }; edge succ_edge(edge e) { ++edges_visited(edge e); return Graph::succ_edge(e); }; };

  19. Expression template template <int i> struct Fib { enum {RET=Fib<n-1>::RET + Fib<n-2>::RET}; }; template <> struct Fib<0> { enum {RET=0}; }; template <> struct Fib<1> { enum {RET=1}; };

  20. Template metaprogramming • 2 szintű nyelvtan • Statikus - template • Turing-teljes nyelvet képez • Dinamikus • Lefordítja • Futtatja www.oonumerics.org Blitz++

  21. Összegzés Régi és új paradigmák együttélése multi-paradigm programming Előnyök: • OO: kiforrott elvek, általános használhatóság, nagy-léptékű rendszerek, jó modularitás • GP: testreszabott, domain-specifikus, magasan automatizált kódgyártás

More Related