IA010: Principles of Programming Languages Introduction 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 (l/r), input/output, conditional jump ▸ compiler of size 100 bytes known to exist Before high-level programming languages … Now … C C++ Java C# Ada Python PHP JavaScript VisualBasic Perl Haskell OCaml F# Scheme … Scala Rust Go Swift Now … C C++ Java C# Ada Python PHP JavaScript VisualBasic Perl Haskell OCaml F# Scheme … Scala Rust Go Swift A zoo of programming languages Now … C C++ Java C# Ada Python PHP JavaScript VisualBasic Perl Haskell OCaml F# Scheme … Scala Rust Go Swift A zoo of programming languages Can we somehow categorise them? How do we choose one? Profanity is the one language all programmers know best. Anon. Language popularity TIOBE index, January 2017, www.tiobe.com Language popularity 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 ▸ usability by non-programmers ▸ … Kinds of software Kinds of software ▸ business applications ▸ office software, graphics software ▸ server software ▸ video games ▸ number crunching ▸ phone apps ▸ control software for embedded devices ▸ scripts, utilities 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 Which language/paradigm/coding style is the best? Which language/paradigm/coding style is the best? Choose the right tools for the job! Which language/paradigm/coding style is the best? Choose the right tools for the job! ⇒ the more tools available, the better Which language/paradigm/coding style is the best? Choose the right tools for the job! ⇒ the more tools available, the better ⇒ need to be familiar with many styles and paradigms Which language/paradigm/coding style is the best? Choose the right tools for the job! ⇒ the more tools available, the better ⇒ need to be familiar with many styles and paradigms Multi-paradigm languages The more paradigms your language support, the more tools you have in your toolbox. State of the art ▸ functional programming, dependent types: Idris ▸ linear types, borrow checker: Rust ▸ imperative programming, error handling: Zig ▸ imperative programming, design by contract: Dafny,Whiley ▸ module system: SML, Ocaml ▸ declarative programming: Mercury ▸ object-oriented programming: Scala ▸ concurrency: Go, Pony (list somewhat biased and certainly incomplete) 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, PA037 Compiler Project, IB005/IA006 Formal Languages Semantics the meaning of programs. Tells us what behaviour we can expect from a program. IA011 Programming Language Semantics, IA014 Advanced Functional Programming 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 ▸ Wednesday, 16:00, A318 ▸ language: English ▸ slides, lecture notes, and source code can be found in IS ▸ video recordings will also be made available there Examination ▸ final written exam, in English ▸ k and z completion possible Prerequisites ▸ no formal requirements ▸ knowledge of at least one programming language ▸ some basic knowledge of H������ helpful ▸ the more languages you know the better Study materials Books (only somewhat relevant) ▸ P. V. Roy, S. Haridi, Concepts, Techniques, and Models of Computer Programming, 1st 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 ▸ a brief history of programming languages ▸ expressions and functions ▸ types, type checking, type inference ▸ state and side-effects ▸ modules ▸ control-flow ▸ declarative programming ▸ object-oriented programming ▸ concurrency