Full Transcript

SEN227 Programming Languages Course Outline 1 Chocolate Cake Receipt  Materials:  1/2 cup butter  4 ounce bittersweet chocolate  2 eggs  2 egg yolks  1/4 cup white sugar  2 teaspoons all purpose flour  Step:  Preheat oven to 450°F.  Heat butter and chocolate until chocolate is alm...

SEN227 Programming Languages Course Outline 1 Chocolate Cake Receipt  Materials:  1/2 cup butter  4 ounce bittersweet chocolate  2 eggs  2 egg yolks  1/4 cup white sugar  2 teaspoons all purpose flour  Step:  Preheat oven to 450°F.  Heat butter and chocolate until chocolate is almost melted.  Beat eggs, yolks and sugar until light colored and thick.  Mix chocolate and butter, and slowly pour into egg mixture, stirring constantly. Stir in flour until just combined.  Pour batter into molds and bake for 6 to 7 minutes. Invert molds on plates, let sit 15 seconds, and unmold. Serve with whipped cream. 2 A Receipt Is Like a Program Receipt:  Receipt tells you how to make a chocolate cake  Has inputs (butter, eggs, chocolate, flour, sugar) & output (chocolate cake)  Define a procedure  Instruct how processors (oven, mixer) process inputs to generate output  Can be expressed in different languages Program:  You tell a computer how to do a computation  Has inputs and outputs    Define a procedure (algorithm) Instruct how processors process inputs to generate outputs Can be expressed in different languages 3 Questions  Given two languages, how do they differ in expressing the same receipt/algorithm?  Which language is better?  How to evaluate “goodness” of languages?  Why are there so many different languages?  What is “programming language” anyway?  Why does a programming language have so many different features?  How are these features implemented? … Topics of this course 4 A Programming Language Is …  An artificial language designed to express computations or algorithms that can be performed by a computer -Wikipedia  A language is a means of expressing your thoughts to others  In the case of PL, it is a means of expressing your thoughts (algorithms) to a computer  Natural languages such as Chinese and English are not used because they cannot be easily translated into machine language executable by the computer  Keywords: expressiveness, implementation 5 Why PL Important? A language is a framework for problemsolving  It may facilitate or hinder your thoughts and, thus, the abilities to solve problems  It may help you make fewer mistakes How to  Example: tense and gender, e.g. choose PL? “He was doing great!” in English  Example: a C language that supports only static and global variables  no malloc()  How to implement hash table? linked list? (Ref.: John Mitchell, http://www.stanford.edu/class/cs242) 6 Important to Know PL by Trend (TIOBE Programming Community) 7 TIOBE 8 Important to Know PL by Trend  Increasing use of type-safe languages: Java, C#, …  Scripting languages for web applications with increasing client-side functionality  More on expressing algorithms than syntax  Runtime environment and virtualization with continuous compilation, analysis, and checking  More program analysis abilities: automated error detection and recovery (Ref.: John Mitchell, http://www.stanford.edu/class/cs242) 9 Important to Know PL by Tradeoffs Factors influencing programming language  Expressiveness:  Application domains  Programming methods: multiprogramming, interactive systems,…  Implementation: efficiency  Computer architecture, OS, toolchain, library  Every convenience has its cost; must recognize cost of presenting an abstract view of machine  Understand trade-offs in programming language design (Ref.: M. Sirjani, http://ut.ac.ir/classpages/ProgrammingLanguages 10 PL as a Course  What is not  Do not teach you a programming language  Do not teach you how to program  What is  Introduce fundamental concepts of programming languages  Discuss design issues of various language constructs  Examine design/implementation choices for these constructs  Compare design alternatives  Need to be familiar in at least one PL 11 Why Study PL?  To improve your ability to develop effective algorithms and to use your language  O-O features, recursion  Call by value, call by reference  To allow a better choice of PL  Increased ability to learn new languages  To make it easier to design a new language  To understand significance of implementation  E.g. the efficiency of a recursive function 12 Textbook  Concepts of Programming Languages, Robert W. Sebesta, 9th Edition, Addison Wesley, 2009  Describing Syntax and Semantics  Names, Bindings, and Scopes  Data Types  Expressions and Assignment  Control Structures  Subprograms  Abstract Data Types, Encapsulation  Concurrency  Exception Handling and Event Handling  Functional and Logic Programming Languages 13