Image credits: http://xkcd.com/353/
CS 354: Programming Languages Alark Joshi Copyright 2009 Addison-Wesley. All rights reserved.
Contact Information Email: alarkjoshi@boisestate.edu Course Website: o http://cs.boisestate.edu/~alark/cs354 Office: MEC 302A Office Hours: o Monday, Friday : 10-11am o Tuesday, Thursday: 3-4pm o Doodle poll
TA Information Teaching Assistant Nathan Riskey o nathanriskey@u.boisestate.edu o Graduate Student o Work experience Office hours: To be announced soon
Administrivia Roll call sheet going around Please sign and note your team assignment Piazza instead of a mailing list o https://piazza.com/boisestate/fall2012/compsc i354 o Better at managing responses, replies, helping each other through assignments, homework, projects etc.
Textbook & Resources Concepts of Programming Languages by Richard Sebesta, Addison Wesley publishing, 9th Edition, 2009. Course Wiki: o cs354.pbworks.com o Collaborative resource o Feel free to edit and improve
Why study languages/programming languages? Look to the person sitting next to you Introduce yourself Make the longest list of reasons you can think of in 2 minutes Longest list in class wins! Go!!! I will call on you to share from your list
Reasons from Sebesta 1. Increased capacity to express ideas 2. Improved background for choosing appropriate languages 3. Increased ability to learn new languages 4. Better understanding of the significance of implementation 5. Better use of languages that are already known 6. Overall advancement of computing
Grade Breakdown Quizzes 21% Interpreter assignment 15% Programming assignments 15% Homework 14% Final project - 35% o Create a website for a programming language o Work on a project using that programming language
Final Project P1 - Website for learning a new language: weebly, pbworks or any other P2 - Create a detailed manual or YouTube video with details regarding installation, IDE setup and other relevant issues P3 - include 10/15 examples of increasing difficulty to teach a novice about that programming language
Final Project P4 - Update website with a comprehensive list of relevant resources, books, tutorials, videos, etc. P5 - Propose 3 projects to me (and anonymous reviewers) - We pick one for you to implement by the end of the semester P6-5-min presentation in the class about your project and what you propose to do
Final Project P7 - Incorporate feedback from anonymous reviewers to improve your website P8 In-class presentation (25-mins) Final grade of the project based on o Quality of the website o Ability to follow along for reviewers o Quality of final project o Relevant documentation
Anonymous reviewers Each student and some external software partners will serve as anonymous reviewers Code review for programs and final project Monthly reports on the quality of the website and the status of the project as described on the website
Programming Assignments Interpreter assignments o V1 and V2 worth 15% Three language related assignments o C# - 5% Assignment available Due 10 th Sept o Python - 5% o Scheme/ML/Haskell - 5%
Team-Based Learning Long Lectures have been shown to produce significant reduction in understanding as the lecture progresses Team-based learning o Apply o Question o Reflect upon and o Discuss content in a group
TBL Quizzes Each quiz will be taken first as an individual Same quiz will be taken as a team o Instant feedback for the team TBL quizzes individual vs team performance Quizzes 21% of the final grade o Quiz 1 - Chapter 1 of Sebesta on 5 th Sept
Team Assignments Teams assignments are going around Please meet your team now! o Buzz Lightyear o Dory o Merida o Nemo o Remy o Sulley o Wall-E
Languages 1. Python 2. Javascript 3. CUDA 4. Lua 5. Haskell 6. C++ 7. Ruby 8. Actionscript 9. Objective-C 10. Perl 11. Processing 12. Lisp 13. Matlab 14. R Image credits: http://xkcd.com/519/
Language Evaluation Criteria Course objective #6: o Evaluate a language on the basis of the various features which it supports. How would you evaluate a language? Think-pair-share (2-2-2) o 2 mins to think of metrics you would use o 2 mins to share it with your partner/team o 2 mins to share with the class
Language Evaluation Criteria Readability Writability Reliability Cost
Readability The ease with which programs can be read and understood
Evaluation Criteria: Readability Overall simplicity o A manageable set of features and constructs o Minimal feature multiplicity o Minimal operator overloading Orthogonality o A relatively small set of primitive constructs can be combined in a relatively small number of ways o Every possible combination is legal
Evaluation Criteria: Readability Data types o Adequate predefined data types Syntax considerations o Identifier forms: flexible composition o Special words and methods of forming compound statements o Form and meaning: self-descriptive constructs, meaningful keywords
Writability The ease with which a language can be used to create programs
Evaluation Criteria: Writability Simplicity and orthogonality o Few constructs, a small number of primitives, a small set of rules for combining them Support for abstraction o The ability to define and use complex structures or operations in ways that allow details to be ignored Expressivity o A set of relatively convenient ways of specifying operations o Strength and number of operators and predefined functions
Reliability Conformance to specifications (i.e., performs to its specifications)
Evaluation Criteria: Reliability Type checking o Testing for type errors Exception handling o Intercept run-time errors and take corrective measures
Evaluation Criteria: Reliability Aliasing o Presence of two or more distinct referencing methods for the same memory location Readability and writability o A language that does not support natural ways of expressing an algorithm will require the use of unnatural approaches, and hence reduced reliability
Evaluation Criteria: Cost Training programmers to use the language Writing programs (closeness to particular applications) Compiling programs Executing programs Language implementation system: availability of free compilers Reliability: poor reliability leads to high costs Maintaining programs Image credits - http://xkcd.com/303/
Evaluation Criteria: Others Portability o The ease with which programs can be moved from one implementation to another Generality o The applicability to a wide range of applications Well-definedness o The completeness and precision of the language s official definition
Influences on Language Design Computer Architecture o Languages are developed around the prevalent computer architecture, known as the von Neumann architecture Program Design Methodologies o New software development methodologies (e.g., object-oriented software development) led to new programming paradigms and by extension, new programming languages
The von Neumann Architecture
The von Neumann Architecture Fetch-execute-cycle (on a von Neumann architecture computer) initialize the program counter repeat forever fetch the instruction pointed by the counter increment the counter decode the instruction execute the instruction end repeat
Computer Architecture Influence Well-known computer architecture: Von Neumann Imperative languages, most dominant, because of von Neumann computers o Data and programs stored in memory o Memory is separate from CPU o Instructions and data are piped from memory to CPU o Basis for imperative languages Variables model memory cells Assignment statements model piping Iteration is efficient
Programming Methodologies Influences 1950s and early 1960s: Simple applications; worry about machine efficiency Late 1960s: People efficiency became important; readability, better control structures o structured programming o top-down design and step-wise refinement Late 1970s: Process-oriented to data-oriented o data abstraction Middle 1980s: Object-oriented programming o Data abstraction + inheritance + polymorphism
Language Categories Imperative o Central features are variables, assignment statements, and iteration o Include languages that support object-oriented programming o Include scripting languages o Include the visual languages o Examples: C, Java, Perl, JavaScript, Visual BASIC.NET, C++ Functional o Main means of making computations is by applying functions to given parameters o Examples: LISP, Scheme, ML, F#
Language Categories Logic o Rule-based (rules are specified in no particular order) o Example: Prolog Markup/programming hybrid o Markup languages extended to support some programming o Examples: JSTL, XSLT, LaTeX
2-2-2 Language Design Trade-Offs Reliability vs. cost of execution o Example: Java demands all references to array elements be checked for proper indexing, which leads to increased execution costs Readability vs. writability o Example: APL provides many powerful operators (and a large number of new symbols), allowing complex computations to be written in a compact program but at the cost of poor readability Writability (flexibility) vs. reliability o Example: C++ pointers are powerful and very flexible but are unreliable
Implementation Methods Compilation o Programs are translated into machine language; includes JIT systems o Use: Large commercial applications Pure Interpretation o Programs are interpreted by another program known as an interpreter o Use: Small programs or when efficiency is not an issue Hybrid Implementation Systems o A compromise between compilers and pure interpreters o Use: Small and medium systems when efficiency is not the first concern
Layered View of Computer The operating system and language implementation are layered over machine interface of a computer
Compilation vs. Interpretation Compilation vs. interpretation o not opposites o not a clear-cut distinction Pure Compilation o The compiler translates the high-level source program into an equivalent target program (typically in machine language), and then goes away:
Compilation vs. Interpretation Pure Interpretation o Interpreter stays around for the execution of the program o Interpreter is the locus of control during execution
Compilation vs. Interpretation Interpretation: o Greater flexibility o Better diagnostics (error messages) Compilation o Better performance
Compilation vs. Interpretation Common case is compilation or simple pre-processing, followed by interpretation Most language implementations - mixture of both compilation and interpretation
Compilation Compilation does NOT have to produce machine language for some sort of hardware Compilation is translation from one language into another, with full analysis of the meaning of the input
Compilation Compilation entails semantic understanding of what is being processed; pre-processing does not A pre-processor is a program that processes its input data to produce output that is used as input to another program (usually compiler) A pre-processor will often let errors through. A compiler hides further steps; a preprocessor does not
Compilation vs. Interpretation Implementation strategies: o Preprocessor Removes comments and white space Groups characters into tokens (keywords, identifiers, numbers, symbols) Expands abbreviations in the style of a macro assembler Identifies higher-level syntactic structures (loops, subroutines)
Compilation vs. Interpretation Implementation strategies: o Library of Routines and Linking Compiler uses a linker program to merge the appropriate library of subroutines (e.g., math functions such as sin, cos, log, etc.) into the final program:
Compilation vs. Interpretation Implementation strategies: o Post-compilation Assembly Facilitates debugging (assembly language easier for people to read) Isolates the compiler from changes in the format of machine language files (only assembler must be changed, is shared by many compilers)
Compilation vs. Interpretation Implementation strategies: o The C Preprocessor (conditional compilation) Preprocessor deletes portions of code, which allows several versions of a program to be built from the same source
Compilation vs. Interpretation Implementation strategies: o Source-to-Source Translation (C++) C++ implementations based on the early AT&T compiler generated an intermediate program in C, instead of an assembly language:
Compilation vs. Interpretation Implementation strategies: o Compilation of Interpreted Languages The compiler generates code that makes assumptions about decisions that won t be finalized until runtime. If these assumptions are valid, the code runs very fast. If not, a dynamic check will revert to the interpreter.
Compilation vs. Interpretation Implementation strategies: o Dynamic and Just-in-Time Compilation In some cases a programming system may deliberately delay compilation until the last possible moment. o Lisp and Prolog invoke the compiler on the fly, to translate newly created source into machine language
Compilation vs. Interpretation o Dynamic and Just-in-Time Compilation The Java language definition defines a machine-independent intermediate form known as byte code. Byte code is the standard format for distribution of Java programs. The main C# compiler produces.net Common Intermediate Language (CIL), which is then translated into machine code immediately prior to execution.
Compilation vs. Interpretation Compilers exist for some interpreted languages, but they aren't pure: o selective compilation of compilable pieces and extra-sophisticated pre-processing of remaining source. o Interpretation of parts of code, at least, is still necessary for reasons above. Unconventional compilers o text formatters o silicon compilers o query language processors
von Neumann Bottleneck Connection speed between a computer s memory and its processor determines the speed of a computer Program instructions often can be executed much faster than the speed of the connection; the connection speed thus results in a bottleneck Known as the von Neumann bottleneck; it is the primary limiting factor in the speed of computers
Robot Programming In groups of 2/3 select a robot and a robot master The Dictionary contains a list of commands that a robot understands Invent new commands
Robot Programming The goal is for the robot to go through a maze, move an object and reach the end Your sub-group will write a program that will be followed by the robot Every time you write a program, you hand it over to the robot who will follow the instructions Use a blank sheet of paper for every program 10 mins
Robot Game Analysis You invented a programming language to program a fictional robot o The commands you used/invented are the commands for your new programming language o The commands were executed by your robot o At times you didn t get the expected result which you found out by running the robot o Debugging and Re-execute