I AO 10: Principles of Programming Languages Introduction and course organization Achim Blumensath blumens@fi.muni.cz Faculty of Informatics, Masaryk University, Brno Warm-up: A Quiz What does this program do? ++++++++++ [ >+++++++>++++++++++>+++>+«« - ] >++. >+. +++++++ . . +++. >++.«+++++++++++++++. >. +++.------.--------.>+.>. Warm-up: A Quiz What does this program do? ++++++++++[>+++++++>++++++++++>+++>+««- ] >++. >+. +++++++ . . +++. >++.«+++++++++++++++. >. +++.------.--------.>+.>. Prints "Hello World!" Warm-up: A Quiz What does this program do? ++++++++++[ -]>++.>+.+++++++ ..+++.>++. Prints "Hello World!" Brainfuck (1993) • Turing-complete programming language • tape containing numbers (inc/dec), a data pointer (1/r), input/output, conditional jump • compiler of size 100 bytes known to exist (moreinfo: http://en.wikipedia.org/wiki/Brainf uck) Before high-level programming languages ... APPLE COMPUTER CO, |:IIi.St.5itt!S2 I8 add ClC Al f2 3^ 3 E5 FT ado] LDAf" m;. xf**; 75 0=t 3 £7 9 5 CA ocx ics F7 bpl addi G# RTS #6 £3 ■ ASl>J&IGN (fl) zfr 21? r l JSR Aft5WAP^3J2) 3^ 2H *1 AB 5 WAP 8 iTC^Ml IE 05 &pl asswapir-p»5; 3/f 10 St M 3*T EG ?l INCC061 &N frf^) 3r/» 38 AftSwAPl sec 3ic A2 £* swap lox **0*< SWA PI STYf^E-l, x 32V f •* s~ Y(//>c l-t, a ^5 0i 37 5 ca oex 3ZT t)i? t- 3 ■ &ne 5 WAPt - R1S 32C C6 rs norm 1 i!5 c Clear C4ffu, Indfx for 3-Vy-V* A<*d A^a^cd i t --ill' PL popularity TIOBE Programming Community Index Source: www.tiobe.com 30 2002 2004 2006 2008 2010 2012 2014 2016 Desirable language features Desirable language features simplicity orthogonality clear (and defined) semantics ease of use easy to learn clean and readable syntax expressive power support for many paradigms and coding styles strong safety guarantees produces fast code compilation speed reduced memory usage good library and tool chain support standardisation and documentation interoperability with other languages hardware and system independence support for hardware and system programming Coding style choices Coding style choices • readability: the code is easy to understand • reliability: the program does what it is supposed to • maintainability: it is easy to fix bugs and add new features • efficiency: the program runs fast Programming paradigms Programming paradigms • procedural: program is structured as a collection of procedures/functions • imperative: list of commands • functional: expressions that compute a value • declarative: describe what you want to compute, not how • object-oriented: objects communicating via messages • data-oriented: layout of your data in memory • reactive: network of components that react to events Programming paradigms • procedural: program is structured as a collection of procedures/functions • imperative: list of commands • functional: expressions that compute a value • declarative: describe what you want to compute, not how • object-oriented: objects communicating via messages • data-oriented: layout of your data in memory • reactive: network of components that react to events Which one to use ? Programming paradigms procedural: program is structured as a collection of procedures/functions imperative: list of commands functional: expressions that compute a value declarative: describe what you want to compute, not how object-oriented: objects communicating via messages data-oriented: layout of your data in memory reactive: network of components that react to events Which one to use ? Choose the right tools for the job! Programming paradigms • procedural: program is structured as a collection of procedures/functions • imperative: list of commands • functional: expressions that compute a value • declarative: describe what you want to compute, not how • object-oriented: objects communicating via messages • data-oriented: layout of your data in memory • reactive: network of components that react to events Which one to use ? Choose the right tools for the job! Multi-paradigm languages The more paradigms your language support, the more tools you have in your toolbox. Why study programming languages and paradigms ? The study of language features and programming styles helps you to • choose a language most appropriate for a given task; • think about problems in new ways; • learn new ways to express your ideas and structure your code (=> more tools in your toolbox); • read other peoples code; • learn new languages faster (you only need to learn a new syntax); • understand the design/implementation decisions and limitations of a given language, so you can use it better: • You can choose between alternative ways of expressing things. • You understand more obscure features. • You can simulate features not available in this particular language. Aspects of programming languages Syntax - the structure of programs. Describes how the various constructs (statements, expressions,...) can be combined into well-formed programs. Semantics - the meaning of programs. Tells us what behaviour we can expect from a program. Pragmatics - the use of programming languages. In which way is the language intended to be used in practice? What are the various language constructions good for? Aspects of programming languages Syntax - the structure of programs. Describes how the various constructs (statements, expressions,...) can be combined into well-formed programs. PA008 Compiler Construction, IB005/IA006 Formal Languages Semantics - the meaning of programs. Tells us what behaviour we can expect from a program. IA Oil Programming Language Semantics Pragmatics - the use of programming languages. In which way is the language intended to be used in practice? What are the various language constructions good for? This course! Course organisation Lectures • Thursday, 10:00, A318 • language: English • video recordings will be available on IS • some slides and lecture notes (in progress) will also be made available Examination • final written exam • in English • k and z completion possible Prerequisites • no formal requirements • knowledge of at least one of C/C++/Java • knowledge of at least one functional language (Haskell, • knowledge of object-oriented programming (OOP) • the more languages you know the better © Study materials Course information, additional resources • https://is.muni.cz/auth/el/1433/jaro2016/IA010/ index.qwarp • Rosettacode rosettacode.org Books • P. V. Roy, S. Haridi, Concepts, Techniques, and Models of Computer Programming, ist ed., MIT Press, 2004. • R. W. Sebesta, Concepts of Programming Languages, 10th ed., Addison-Wesley, 2012. • Programming language pragmatics, (Ed. M. L. Scott) 3rd ed. Oxford, Elsevier Science, 2009. Topics covered • brief history of programming languages • names, bindings, scope • types, type checking, type inference • data abstraction: abstract data types • control flow • subprograms (functions, methods,...) • exceptions • object-oriented programming • concurrency • functional programming