33
C++ C++ one of the one of the programming programming languages that you languages that you should know should know

C++ one of the programming languages that you should know

Embed Size (px)

Citation preview

Page 1: C++ one of the programming languages that you should know

C++C++one of the programming one of the programming

languages that you should languages that you should knowknow

Page 2: C++ one of the programming languages that you should know

I am Piotr Klos

• some basic Books, forums threads, documentation, source code in C++

• „Design Patterns” by the „band of four”

• „Modern C++ Design” by Andrei Alexandrescu

• A stupid game called „Kartofel”

• Object Oriented Graphical User Interface „PKgui”

• A labyrinth editor, as a part of labyrinth generator

I have read and I recommend: I have written:

Page 3: C++ one of the programming languages that you should know

This presentation is about…

• the theory behind C++

• the advantages and disadvantages of C++

• the significance of C++ in the modern programming

Page 4: C++ one of the programming languages that you should know

What is C++?

• a compiled programming language for general purpose

• object oriented language • based on C => supports procedural

programming• highly developed, standarised, language; its

quality still increases• safe <= strict static type checking• enables generic programming <= templates

Page 5: C++ one of the programming languages that you should know

History of C++

• Bjarne Stroustrup

• first, poor version in 1979 „C with classes”

• ISO standard of C++ from 1998

• growing popularity

• last standard in 2003

• new version, C++ 0x is being developed

Page 6: C++ one of the programming languages that you should know

Object oriented?

• classes • inheritance• polymorphism

main ideas of the object oriented paradigm:

Object-based languages (like Visual Basic or JavaScript) do not have at least one of them.

Page 7: C++ one of the programming languages that you should know

Object oriented?• classes – user defined types of objects with full

rights• correct example (red keywords):

class ClassName { private: OtherClassName b; public: int a; ClassName* c; void f() { cout<<a; } ClassName(){/*a body*/ } ClassName(int arg){ a=arg; } ClassName(ClassName& ){/*a body*/ } ~ClassName(){/*a body*/ } ClassName operator+(ClassName & arg){ return ClassName(a+ arg.a); } friend class OtherClassName;};

Page 8: C++ one of the programming languages that you should know

Object oriented?• have data

class ClassName { private: OtherClassName b; /// public: int a; /// ClassName* c; /// void f() { cout<<a; } ClassName(){/*a body*/ } ClassName(int arg){ a=arg; } ClassName(ClassName& ){/*a body*/ } ~ClassName(){/*a body*/ } ClassName operator+(ClassName & arg){ return ClassName(a+ arg.a); } friend class OtherClassName;};

Page 9: C++ one of the programming languages that you should know

Object oriented?• data of in-build types

class ClassName { private: OtherClassName b; public: int a; /// ClassName* c; void f() { cout<<a; } ClassName(){/*a body*/ } ClassName(int arg){ a=arg; } ClassName(ClassName& ){/*a body*/ } ~ClassName(){/*a body*/ } ClassName operator+(ClassName & arg){ return ClassName(a+ arg.a); } friend class OtherClassName;};

Page 10: C++ one of the programming languages that you should know

Object oriented?• data of user defined types

class ClassName { private: OtherClassName b; /// public: int a; ClassName* c; void f() { cout<<a; } ClassName(){/*a body*/ } ClassName(int arg){ a=arg; } ClassName(ClassName& ){/*a body*/ } ~ClassName(){/*a body*/ } ClassName operator+(ClassName & arg){ return ClassName(a+ arg.a); } friend class OtherClassName;};

Page 11: C++ one of the programming languages that you should know

Object oriented?• pointers, references, arrays, pointers to

pointers, references to arrays of pointers, etc.

class ClassName { private: OtherClassName b; public: int a; ClassName* c; /// void f() { cout<<a; } ClassName(){/*a body*/ } ClassName(int arg){ a=arg; } ClassName(ClassName& ){/*a body*/ } ~ClassName(){/*a body*/ } ClassName operator+(ClassName & arg){ return ClassName(a+ arg.a); } friend class OtherClassName;};

Page 12: C++ one of the programming languages that you should know

Object oriented?• behaviour of objects : member functions,

which process object data easily or do whatever you need

class ClassName { private: OtherClassName b; public: int a; ClassName* c; void f() { /// cout<<a; /// } /// ClassName(){/*a body*/ } /// ClassName(int arg){ a=arg; } /// ClassName(ClassName& ){/*a body*/ } /// ~ClassName(){/*a body*/ } /// ClassName operator+(ClassName & arg){ /// return ClassName(a+ arg.a); /// } /// friend class OtherClassName;};

Page 13: C++ one of the programming languages that you should know

Object oriented?• an ordinary function(prints the value of a)

class ClassName { private: OtherClassName b; public: int a; ClassName* c; void f() { /// cout<<a; /// } /// ClassName(){/*a body*/ } ClassName(int arg){ a=arg; } ClassName(ClassName& ){/*a body*/ } ~ClassName(){/*a body*/ } ClassName operator+(ClassName & arg){ return ClassName(a+ arg.a); } friend class OtherClassName;};

Page 14: C++ one of the programming languages that you should know

Object oriented?• constructors and copy constructors

class ClassName { private: OtherClassName b; public: int a; ClassName* c; void f() { cout<<a; } ClassName(){/*a body*/ } /// ClassName(int arg){ a=arg; } /// ClassName(ClassName& ){/*a body*/ } /// ~ClassName(){/*a body*/ } ClassName operator+(ClassName & arg){ return ClassName(a+ arg.a); } friend class OtherClassName;};

Page 15: C++ one of the programming languages that you should know

Object oriented?• destructors

class ClassName { private: OtherClassName b; public: int a; ClassName* c; void f() { cout<<a; } ClassName(){/*a body*/ } ClassName(int arg){ a=arg; } ClassName(ClassName& ){/*a body*/ } ~ClassName(){/*a body*/ } /// ClassName operator+(ClassName & arg){ return ClassName(a+ arg.a); } friend class OtherClassName;};

Page 16: C++ one of the programming languages that you should know

Object oriented?• overloaded operators

• ClassName x(3),y(4); x=x+y; /*x.a==7*/

class ClassName { private: OtherClassName b; public: int a; ClassName* c; void f() { cout<<a; } ClassName(){/*a body*/ } ClassName(int arg){ a=arg; } ClassName(ClassName& ){/*a body*/ } ~ClassName(){/*a body*/ } ClassName operator+(ClassName & arg){ /// return ClassName(a+ arg.a); /// } /// friend class OtherClassName;};

Page 17: C++ one of the programming languages that you should know

Object oriented?• member protection

• avoiding bugs and useless file dependencies

class ClassName { private: /// OtherClassName b; public: /// int a; ClassName* c; void f() { cout<<a; } ClassName(){/*a body*/ } ClassName(int arg){ a=arg; } ClassName(ClassName& ){/*a body*/ } ~ClassName(){/*a body*/ } ClassName operator+(ClassName & arg){ return ClassName(a+ arg.a); } friend class OtherClassName;};

Page 18: C++ one of the programming languages that you should know

Object oriented?• selective member protection

class ClassName { private: /// OtherClassName b; public: /// int a; ClassName* c; void f() { cout<<a; } ClassName(){/*a body*/ } ClassName(int arg){ a=arg; } ClassName(ClassName& ){/*a body*/ } ~ClassName(){/*a body*/ } ClassName operator+(ClassName & arg){ return ClassName(a+ arg.a); } friend class OtherClassName; ///};

Page 19: C++ one of the programming languages that you should know

Object oriented?• inheritance

• NextClassName contains members of ClassName

class NextClassName :public ClassName ///{ int d; float z;};

Page 20: C++ one of the programming languages that you should know

Object oriented?

• exception handling• constancy of objects• inlining• easy to use dynamic memory allocation• namespaces• operator overloading• encapsulation• run-time type identification

Other OO-friendly idioms in C++ standard:

Page 21: C++ one of the programming languages that you should know

Object oriented?

• to reflect the real world

• to reflect any beeings that exist only in our imagination

• to reflect any technical beeings in computer architecture

OO, uniform, easy to use, in-build tools are used:

OO paradigm is very powerful !

Page 22: C++ one of the programming languages that you should know

Examples of C++ code:

• literally everything at Microsoft• software by Adobe Systems• Google search engine• Apple OS X• Havoc physics engine• Metrowerks tools• Mozilla Firefox• most of big games

Page 23: C++ one of the programming languages that you should know

Is C++ Perfect?

• does not support multi-threading

• does not have delegates

• does not reflect some of design patterns – (more abstract beeings that cannot be defined as objects)

most of C++ programmers complain, because C++:

Page 24: C++ one of the programming languages that you should know

Is C++ Perfect?

• many C++ libraries have it

• C++ 0x will fix it

• so far no uniform multi-threaded support

multi-threaded support:

Page 25: C++ one of the programming languages that you should know

Is C++ Perfect?

• many C++ libraries implement them

• C++ 0x may fix it

• no uniform delegates

delegates:

Page 26: C++ one of the programming languages that you should know

Is C++ Perfect?

• design pattern – named and formally described solution for a complicated problem

support for design patterns:

What are design patterns?

Page 27: C++ one of the programming languages that you should know

Is C++ Perfect?

• you can easily implement some of them using objects

• also some C++ libraries implement some of them

• those solutions are reusable

• but not very elegant and easy to use

• it will not change

support for design patterns:

Page 28: C++ one of the programming languages that you should know

Is C++ Perfect?

• problems with dependencies between behaviours of objects

• theese cannot be defined only in terms of objects

• difference between set of notions used in project and structures written in code

• code does not reflect context of problem• OO paradigm does not reflect worlds !!!

support for design patterns:

Page 29: C++ one of the programming languages that you should know

C++ is not perfect.

• we cannot easily translate some projects to a code with C++

• because C++ is an OO language

• solution for this: aspect-oriented languages*

*AO paradigm – introduced recently by Gregor Kiczales; there are already languages like AspectJ or AspectC++ which use it; visit http://www.cs.ubc.ca/~gregor/

Page 30: C++ one of the programming languages that you should know

Why C++ is so popular?

• you can compile C code in C++

• so you can use old C libraries in C++

• so C++ supports linear, procedural, object-based programming, object oriented programming and data abstraction

• compiled C++ code is very efficient

• probably the most general purpose language in the world

Page 31: C++ one of the programming languages that you should know

general purpose…

• so there is a big community

• so there are very many C++ libraries!

• so there is a competition

• so quality of code is very high

• so the quality of C++ standard is growing to meet the requirements

• other important reason…

Page 32: C++ one of the programming languages that you should know

generic programming in C++

• templates – way of programming abstractions

• compiler generates similar parts of code instead of a programmer

• big C++ community produces a lot of template libraries

• examples: STL, Boost, Loki, others• ready solutions for complicated problems• fast, easy, safe and efficient programming

Page 33: C++ one of the programming languages that you should know

conclusion

• C++ is powerful

• C++ and further versions will be used for a long time

• C++ influenced Java, C#, PHP, ADA95 etc.

• probably will influence others in the future

• it is worth to know