advanced software engineering with c templates
play

Advanced Software Engineering with C++ Templates Administrative - PowerPoint PPT Presentation

Advanced Software Engineering with C++ Templates Administrative Issues Thomas Gschwind <thg at zurich dot ibm dot com> About me Lecturer at Universitt Zrich Researcher at IBM Interests Machine Learning Programming


  1. Advanced Software Engineering with C++ Templates Administrative Issues Thomas Gschwind <thg at zurich dot ibm dot com>

  2. About me § Lecturer at Universität Zürich § Researcher at IBM § Interests • Machine Learning • Programming Languages • Software Engineering § Enjoying to Teach Th. Gschwind. Advanced Software Engineering with C++ Templates. 2

  3. Agenda § Administrative Issues • The name of the game • Schedule • Lectures, Exercises, Exam § The game of the name • Classes, User-Defined Types, and Namespaces • C++ Standard Library: Basic Input and Output, Strings, Containers, Iterators • Templates Primer Th. Gschwind. Advanced Software Engineering with C++ Templates. 3

  4. Prerequisites § Programming Languages • Basic knowledge of object-oriented programming • Some knowledge of C (pointers, memory management helpful) • Alternatively: Java, or Python § For students in the third semester or later Th. Gschwind. Advanced Software Engineering with C++ Templates. 4

  5. The Name of the Game § We look at the C++ Programming Language • The language features and how they can be used • The Standard Library and how it uses the features from C++ • Examples are small and focus on using features of C++ § C++ allows developers to use different programming paradigms • Procedural programming • Object-based programming (templates, static polymorphism) • Object-oriented programming (inheritance, dynamic polymorphism) § Languages Features of Special Interest • Typing • Strong vs. weak typing • Static vs. dynamic typing • Templates • Exception Handling • Standard Library Th. Gschwind. Advanced Software Engineering with C++ Templates. 5

  6. It’s Rude to be Alive When “No One” Wants You § C++ is a C-based language that is infamous for being cryptic • Many C developers find it too high-level and having too much overhead • Java/Python/… developers find it too low-level § Actually there are many Open-Source projects that use C++ • Tensorflow, Tesseract • Mysql • Many KDE applications (The widget library (Qt) is implemented in C++) • Some Gnome applications § C++ provides instructions to influence low-level code generation • Today’s computer consume little power and are blazingly fast • Why would we care? Th. Gschwind. Advanced Software Engineering with C++ Templates. 6

  7. Loads of Applications Requiring C++ Anything requiring loads of CPU § Machine learning • Big Data Management • Analyzing images uploaded to facebook • (identifying problematic content, faces, etc.) Anything to be executed on “small” § microprocessor Arduino UNO: • ATmega@16MHz, 2KB SRAM, 1KB EEPROM, 32KB Flash Raspberry Zero: • Arduino UNO Single core ARM@1GHz, 512MB memory SDK uses C++ Provides 32k Flash Many many more • Th. Gschwind. Advanced Software Engineering with C++ Templates. 7

  8. Embedded Devices § Anything to be executed on battery-driven processors • Your programs takes twice the time • Your battery lasts half as long max. • Power consumption is quadratic to frequency • This is why Android’s dalvikvm is implemented in C++ • Apple chose Objective C for everything § Smartwatches • Today they last 1-4 days depending on vendor • An efficient program really is important • Don’t want to lug around a watch with extra battery Th. Gschwind. Advanced Software Engineering with C++ Templates. 8

  9. More Embedded Devices § Anything to be executed on battery-driven processors • Now imagine we want to move our embedded system around… • Robots, worse, helicopter, quadrocopter, we need to lift our battery as well Th. Gschwind. Advanced Software Engineering with C++ Templates. 9

  10. Introduction § Historically speaking, • C++ is an Algol like programming language (like Pascal, or Java without OO features) • C++ builds on the C language of which it is a superset (except for comments, struct, enum, …) § C++ adds several features to C such as • Inheritance • Templates • Exceptions § C++ supports different programming paradigms • Procedural programming • Object-based programming • Object-oriented programming Th. Gschwind. Advanced Software Engineering with C++ Templates. 10

  11. Topics Covered (approximately) § Lecture 1 • Classes, User-Defined Types, Namespaces • Templates, Template Specialization • Standard Library: Input/Output, Strings, Iterators § Lecture 2 • Traits • Separate Compilation, Makefiles § Lecture 3 • Memory Management • Standard Library Algorithms, Lambda Functions Th. Gschwind. Advanced Software Engineering with C++ Templates. 11

  12. Topics Covered (cont’d) § Lecture 4 • Template Implementations • Tag Dispatching (Compile-Time Algorithm Inference) • Inheritance § Lecture 5 • Liskov Substitution Principle • Exception Handling • Library Initialization § Lecture 6 • Standard Library: Input and Output Formatting • Template Metaprogramming • Repetitorium Th. Gschwind. Advanced Software Engineering with C++ Templates. 12

  13. Organization & Schedule § Announcements and discussions • Announcements: http://www.gschwinds.net/teaching/cpp/ • Discussions: Discussion Forum in OLAT § Approx. 6 lectures, 3 hours each (plus 1 backup) • Fri. 14:45-18:00 BIN-2.A.01 (including 15min break) • For a complete schedule, please check the course web site § Exercise submissions and Exam • Exercises to be presented by randomly selected students in the next lecture • Exam on Fri. Jan. 22, 16:00 online Th. Gschwind. Advanced Software Engineering with C++ Templates. 13

  14. Grading § Exercises handed out after every lecture • Examination in the next lecture • Show your solution to the exercise • Answer questions about your solution and the concepts used in the exercise § Exam at the end of the course • Most likely written (online exam), potentially oral exam • Approx. 50-70% theory, 30-50% practical questions § Grading • Exercises determine 1/3 of the final grade • Exam determines 2/3 of the final grade Th. Gschwind. Advanced Software Engineering with C++ Templates. 14

  15. A Request from the Lecturer § If anything is unclear, you are curious about something, etc. • Please ask a question • This makes the lecture livelier and more interesting (for all including me) § If you find mistakes on the slides • Please point them out; if you are unsure, by email or direct message • Improves the quality of the lecture § I will compare with other programming languages • Comparisons not in the slides are not required for the exam • Of course, I will stress the advantages of C++ (this is a C++ lecture) • Yes, C++ has its downsides, they will be addressed as well • Any language can be used to write good and bad programs Th. Gschwind. Advanced Software Engineering with C++ Templates. 15

  16. Q & A? § Course material? • Slides • Lectures will be recorded and made available § Books? • Bjarne Stroustrup. The C++ Programming Language (3rd Ed.). Addison- Wesley. • Stanley B. Lippman, Josée Lajoie, Barbara E. Moo. C++ Primer (5th Ed.). Addison-Wesley. • Scott Meyers. Effective C++: 55 Specific Ways to Improve Your Programs and Designs Addison-Wesley • Bjarne Stroustrup. A Tour of C++ (2nd Ed.). Addison-Wesley. • There are newer ones too; check out your local bookstore! § Which operating system/C++ compiler? • Any (Mac: xcode; Windows: Cygwin; Linux: cli tools) Th. Gschwind. Advanced Software Engineering with C++ Templates. 16

  17. Advanced Software Engineering with C++ Templates Namespaces, Classes, User-Defined Types Thomas Gschwind <thg at zurich dot ibm dot com>

  18. Classes, User-Defined Types § Motivation § References • Encapsulation § Operators • When and why? § Constant Classes § Declaration & Definition § User-defined conversions § Constructors § const ness § Destructors Th. Gschwind. Advanced Software Engineering with C++ Templates. 18

  19. Classes § Encapsulation • Add structure to the program • Gives class an explicit interface (access to class checked by compiler) • User only needs to know this interface • Hide implementation details § Abstract data types (e.g., stack, vector, map, …) § User-defined types • Allows developers to develop types that mimic primitive types (such as a fraction or complex number data type): fraction x(4,3), y(2); fraction z = x*x + y; Decide which types you want; provide • One of the key differences between a full set of operations for each type. C++ and C (or Java) Bjarne Stroustrup Th. Gschwind. Advanced Software Engineering with C++ Templates. 19

  20. Classes: When are They Needed? § Non OO languages such as C do typedef struct { not provide classes but only int s[256]; int sp; structures or records } Stack; void stack_init(Stack *s) { • Classes simulated with functions s->sp=256; taking the same record (typically) } as first argument void stack_push(Stack *s, int i) { s->s[--s->sp]=i; § Classes are useful for } int stack_pop(Stack *s) { • User defined types return s->s[s->sp++]; • Abstract data types } (e.g., vector, map, …) int stack_empty(Stack *s) { return s->sp==256; • Whenever you have many } functions that operate on the same void main ( int argc, char *argv[]) { data Stack s; stack_init(&s); // use s } Th. Gschwind. Advanced Software Engineering with C++ Templates. 20

Recommend


More recommend