Programming Paradigms

Similar documents
Programming Paradigms

Programming Paradigms

Functional Programming Lecture 13: FP in the Real World

Programming Paradigms

Programming Paradigms

Anders Møller Michael Schwartzbach Erik Ernst Hans Hüttel

Programming Paradigms

Functional Programming Lecture 1: Introduction

Com S 541. Programming Languages I

8/27/17. CS-3304 Introduction. What will you learn? Semester Outline. Websites INTRODUCTION TO PROGRAMMING LANGUAGES

Programming Languages, Summary CSC419; Odelia Schwartz

15. Functional Programming

Programming Paradigms

CSc 372. Comparative Programming Languages. 2 : Functional Programming. Department of Computer Science University of Arizona

Concepts of Programming Languages

1. true / false By a compiler we mean a program that translates to code that will run natively on some machine.

New Programming Paradigms

Introduction. A. Bellaachia Page: 1

Chapter 1. Preliminaries

Structure of Programming Languages Lecture 5

Chapter 6 Control Flow. June 9, 2015

CPS 506 Comparative Programming Languages. Programming Language Paradigm

BCS THE CHARTERED INSTITUTE FOR IT. BCS Higher Education Qualifications BCS Level 6 Professional Graduate Diploma in IT EXAMINERS' REPORT

Topic 9: Type Checking

Topic 9: Type Checking

Is Functional Programming (FP) for me? ACCU Conference 2008 Hubert Matthews

Outline. Introduction Concepts and terminology The case for static typing. Implementing a static type system Basic typing relations Adding context

INSTITUTE OF AERONAUTICAL ENGINEERING

Concepts of Programming Languages

Programming Languages 2nd edition Tucker and Noonan"

Chapter 15. Functional Programming Languages

General Concepts. Abstraction Computational Paradigms Implementation Application Domains Influence on Success Influences on Design

Why are there so many programming languages? Why do we have programming languages? What is a language for? What makes a language successful?

Course Syllabus. Programming Language Paradigms. Spring - DIS Copenhagen. Semester & Location: Elective Course - 3 credits.

9/21/17. Outline. Expression Evaluation and Control Flow. Arithmetic Expressions. Operators. Operators. Notation & Placement

! Broaden your language horizons! Different programming languages! Different language features and tradeoffs. ! Study how languages are implemented

All you need is fun. Cons T Åhs Keeper of The Code

Introduction to Functional Programming

Programming Paradigms

High-Level Server Side Web Scripting in

BCS THE CHARTERED INSTITUTE FOR IT. BCS Higher Education Qualifications BCS Level 6 Professional Graduate Diploma in IT EXAMINERS' REPORT

Functional Programming. Big Picture. Design of Programming Languages

Introduction to Functional Programming in Haskell 1 / 56

Principles of Programming Languages. Lecture Outline

Refactoring to Functional. Hadi Hariri

Haskell 98 in short! CPSC 449 Principles of Programming Languages

Topic 1: Introduction

Programming Paradigms Written Exam (6 CPs)

3. Functional Programming. Oscar Nierstrasz

Chapter 1. Preliminaries

General Overview of Mozart/Oz

Programming Paradigms

! Broaden your language horizons. ! Study how languages are implemented. ! Study how languages are described / specified

Chapter 1 Preliminaries

Programming Language Pragmatics

Erlang. Joe Armstrong.

JVM ByteCode Interpreter

Chapter 1. Preview. Reason for Studying OPL. Language Evaluation Criteria. Programming Domains

R13 SET Discuss how producer-consumer problem and Dining philosopher s problem are solved using concurrency in ADA.

PROGRAMMING PARADIGMS

Overview. Rationale Division of labour between script and C++ Choice of language(s) Interfacing to C++

Lecture 8: Summary of Haskell course + Type Level Programming

Page # Expression Evaluation: Outline. CSCI: 4500/6500 Programming Languages. Expression Evaluation: Precedence

Executive Summary. It is important for a Java Programmer to understand the power and limitations of concurrent programming in Java using threads.

Haskell Review COMP360

St. MARTIN S ENGINEERING COLLEGE Dhulapally, Secunderabad

Programming Paradigms

Programming Paradigms Written Exam (6 CPs)

CS252 Advanced Programming Language Principles. Prof. Tom Austin San José State University Fall 2013

CS 565: Programming Languages. Spring 2008 Tu, Th: 16:30-17:45 Room LWSN 1106

Stop coding Pascal. Saturday, April 6, 13

Haskell: From Basic to Advanced. Part 2 Type Classes, Laziness, IO, Modules

Functional Programming

LECTURE 18. Control Flow

Contents. Chapter 1 SPECIFYING SYNTAX 1

CS 11 Haskell track: lecture 1

Introducing Wybe a language for everyone

Robot Programming with Lisp

Functional Programming

6.001 Notes: Section 6.1

Program Abstractions, Language Paradigms. CS152. Chris Pollett. Aug. 27, 2008.

! Non-determinacy (unspecified order) Maria Hybinette, UGA 2. 1 Landin adding sugar to a language to make it easier to read (for humans)

Overview. Rationale Division of labour between script and C++ Choice of language(s) Interfacing to C++ Performance, memory

G Programming Languages - Fall 2012

Programmiersprachen (Programming Languages)

CMSC 330: Organization of Programming Languages

Organization of Programming Languages (CSE452) Why are there so many programming languages? What makes a language successful?

What Is Computer Science? The Scientific Study of Computation. Expressing or Describing

Functional Programming in Embedded System Design

Welcome to. Instructor Marc Pomplun CS 470/670. Introduction to Artificial Intelligence 1/26/2016. Spring Selectivity in Complex Scenes

CS 314 Principles of Programming Languages

What is a programming language?

What is a compiler? Xiaokang Qiu Purdue University. August 21, 2017 ECE 573

Functional Languages. Hwansoo Han

The Prolog to Mercury transition guide

CS 415 Midterm Exam Spring 2002

documenting programs, including: A traditional, command line interactive top level.

Functional Programming Language Haskell

Type Theory meets Effects. Greg Morrisett

Quick announcement. Midterm date is Wednesday Oct 24, 11-12pm.

Transcription:

PP 2017/18 Unit 18 Summary of Basic Concepts 1/13 Programming Paradigms Unit 18 Summary of Basic Concepts J. Gamper Free University of Bozen-Bolzano Faculty of Computer Science IDSE

PP 2017/18 Unit 18 Summary of Basic Concepts 2/13 Basic Concepts of Programming Languages Programming languages are artificial languages designed to communicate with computers Provide most powerful human-computer interface There are thousands of different languages, which are more or less appropriate for different problems Can be classified according to programming paradigms and abstraction level There are many similarities to natural languages, e.g., syntax, semantics Syntax determines whether a programm is well-formed Semantic determines the meaning of lanugage concepts/programs, and can be defined in different ways (operational, aximoatic, denotational semantics) Type system in a programming language is needed to organize data and helps to check the correctness of programs Different forms of type checking, all having pros and cons Weak typing vs. strong typing Static vs. dynamic type checking Type casting

PP 2017/18 Unit 18 Summary of Basic Concepts 3/13 Imperative and Object-oriented Paradigm Imperative paradigm is the oldest programming paradigm, based on von Neumann architecture Assignment statement is a central element, assigning values to memory locations Program consists of sequence of statements that change the program state Procedural programming is a refinement that makes it easier to write complex programs Machine languages were the earliest imperative languages, followed by FORTRAN and ALGOL Abstract Data Types is a further extension of imperative programming Data and operations are encapsulated into a bundle (information hiding) This hides the underlying represenation and implementation Object-oriented paradigm extends ADTs Classes are blueprints for objects that encapsulae both data and operations Objects exchange messages Provides encapsulation, information hiding, inheritance, and dynamic dispatching

PP 2017/18 Unit 18 Summary of Basic Concepts 4/13 Object-oriented Programming with Ruby/1 Design goal of Ruby: simplicity and productivity of the programmer Ruby is a pure object-oriented language, treating objects in a consistent way Ruby is a strongly typed language, but applies dynamic type checking Supports duck typing, and is therefore very flexible when it comes to substitutability Exact class of object is less relevat, but what methods/operations can be performed counts Comparable to interfaces, e.g., in Java Some nice features not present in other languages: rich set of methods on arrays, code blocks that can be passed as paraemters to methods, modules, mixins (i.e., modules included in class definitions), accessor methods that can have the same name as variables Programmers can be very productive using Ruby, can be used like a scripting language Comes with a very successful web development framework: Ruby on Rails The original Twitter implementation was done in Ruby

PP 2017/18 Unit 18 Summary of Basic Concepts 5/13 Object-oriented Programming with Ruby/2 Performance: Ruby is not the most efficient language All the flexibility makes it difficult to compile programs Concurrent programming is difficult to do (with a state-based language) Type Safety: duck typing makes it harder to debug code that has type errors in it

PP 2017/18 Unit 18 Summary of Basic Concepts 6/13 Recursion Recursion is just a different kind of loop, but as expressive as loops Some programming languages are haevily based on recursion, others do not offer recursion at all Two important steps in writing recursive programs Base cases Termination Often recursion allows you to write elegant code With the right language, it is even efficient Tail recursion is important to make recursive programs efficient In tail recursion, the recursive call is the last statement before the function terminates, i.e., after returning from the recursive call no other statements need to be executed Therefore, no information need to be stored on the stack

PP 2017/18 Unit 18 Summary of Basic Concepts 7/13 Logic Programming in Prolog/1 Prolog is a declarative programming language based on first-order logic Specifies what to compute and not how to do it A Prolog program/knowledge base consists of facts and rules Evaluating a Prolog program means to prove a goal Thereby, key concepts are instantiation, (pattern) matching, and backtracking Prolog uses recursion instead of loops Lists and structures are two very important data structures The cut operator allows to stop backtracking Should be used with care A better programming style is to replace it by negation Generate and test is a very common programming pattern

PP 2017/18 Unit 18 Summary of Basic Concepts 8/13 Logic Programming in Prolog/2 The box model shows the execution of a Prolog program Has four ports: CALL, EXIT, REDO, FAIL Debugger shows the program execution according to the box model trace provides an exhausitive tracing mode debug allows to jump to spy points set by the spy predicate Accumulators are frequently needed to collect intermediate results when traversing structures or lists Helpful to make programs tail-recursive Sorting is an important operation Generalized insertion sort, which allows to pass a sorting predicate Constructing structures with the =.. (univ) operator needed Another frequent and powerful operation is mapping structures and lists General map-functions can be used (second-order functions) read and write predicates for simple interactive programs

PP 2017/18 Unit 18 Summary of Basic Concepts 9/13 Logic Programming in Prolog/3 Prolog has a steeper learning curve compared to other languages Fairly focused niche applications, not really a practical general-purpose language Mainly used in application areas, such as artificial intelligence, natural language processing, and databases There are scalability issues, the basic matching strategy used by Prolog is computationally expensive Has problems to process large data sets It is not as declarative as it seems at first glance If you want to write efficient Prolog programs, you have to know what is going on behind the scenes

PP 2017/18 Unit 18 Summary of Basic Concepts 10/13 Functional Programming in Haskell/1 Haskell is a pure functional language, providing referential transparency function give the same output for the same input functions have no side effects a variable can only be assigned a value once The type system (strong/static) prevents you from making a lot of mistakes Nevertheless, it is quite flexible when it comes to extending it with user-defined types Haskell offers a lot in terms of expressiveness, yielding very concise code Hasekell uses curried functions in combination with partial evaluation of functions, i.e., internally, functions have only one input parameter; functions with multiple input parameters are decomposed into a sequence of partial functions, each having one parameter It is easier to show the correctness of your programs, due to the pure functional style

PP 2017/18 Unit 18 Summary of Basic Concepts 11/13 Functional Programming in Haskell/2 Haskell does lazy evaluation, which gives you an additional tool for writing programs efficiently Lazy evaluation supports to work with infinite lists: only those (finite) parts are evaluated that are actually needed and only when they are needed Haskell supports list comprehension, a powerful way to specify lists The pure functional paradigm also has a price: dealing with messy real-world situations such as IO and state is not easy Haskell has a steep learning curve, i.e., it takes a while to learn how to wield the power of Haskell This may also explain the fact that the Haskell community is relatively small

PP 2017/18 Unit 18 Summary of Basic Concepts 12/13 Concurrent Programming in Erlang/1 The shared-nothing, message-passing process model is very powerful when it comes to implementing concurrency Concurrency means any execution order (e.g., parallel or serial) without compromising the correctness of the program Erlang offers a lot in terms of reliability and fault tolerance Controlled crash Erlang was developed with the aim to achieve industrial-strength high performance Erlang processes run on a virtual maching that automatically adapts to the underlying hardware Runs on as many cores/machines as available Language supports some powerful features of functional and logic-oriented languages e.g., pattern matching, optimized for tail-recursion OTP provides a lot of functionality to make it easier to implement concurrent applications

PP 2017/18 Unit 18 Summary of Basic Concepts 13/13 Concurrent Programming in Erlang/2 The syntax of the language is a weird mix of Prolog with functional language constructs thrown in While Erlang shines when it comes to concurrency, programming simpler (serial) things tend to be harder than in other languages