Do Languages Matter? Lecture 1: Overview. Why Article. Do Languages Matter? Why choose C vs C++ vs Java vs Python...!

Similar documents
Why a New Language? Seeking Grace: a New Object-Oriented Language for Novices. OO Teaching Frustrations. Java Problems. Java is 20 years old in 2015

CS558 Programming Languages

CS558 Programming Languages

More Examples. Lecture 24: More Scala. Higher-Order Functions. Control Structures

CS558 Programming Languages

CS558 Programming Languages

Programming Languages and Techniques (CIS120)

CS 11 java track: lecture 1

Where do we go from here?

Semantic Analysis. How to Ensure Type-Safety. What Are Types? Static vs. Dynamic Typing. Type Checking. Last time: CS412/CS413

Closures. Mooly Sagiv. Michael Clarkson, Cornell CS 3110 Data Structures and Functional Programming

Question No: 1 ( Marks: 1 ) - Please choose one One difference LISP and PROLOG is. AI Puzzle Game All f the given

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

Types. What is a type?

CS412/CS413. Introduction to Compilers Tim Teitelbaum. Lecture 17: Types and Type-Checking 25 Feb 08

Syntax Errors; Static Semantics

22c:111 Programming Language Concepts. Fall Types I

Semantic Analysis. Outline. The role of semantic analysis in a compiler. Scope. Types. Where we are. The Compiler Front-End

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

Computer Components. Software{ User Programs. Operating System. Hardware

CS 61C: Great Ideas in Computer Architecture. Lecture 2: Numbers & C Language. Krste Asanović & Randy Katz

Two Types of Types. Primitive Types in Java. Using Primitive Variables. Class #07: Java Primitives. Integer types.

Agenda. CS 61C: Great Ideas in Computer Architecture. Lecture 2: Numbers & C Language 8/29/17. Recap: Binary Number Conversion

The Compiler So Far. CSC 4181 Compiler Construction. Semantic Analysis. Beyond Syntax. Goals of a Semantic Analyzer.


CS/ENGRD 2110 FALL Lecture 2: Objects and classes in Java

Lecture 16: Static Semantics Overview 1

Lecture 1: Course Introduction

JavaScript: Introduction, Types

CSc 372 Comparative Programming Languages

Monty Python and the Holy Grail (1975) BBM 101. Introduction to Programming I. Lecture #03 Introduction to Python and Programming, Control Flow

CS558 Programming Languages

CS558 Programming Languages

Programming Languages: Lecture 11

CS 314 Principles of Programming Languages

CSCI 2212: Intermediate Programming / C Review, Chapters 10 and 11


SEMANTIC ANALYSIS TYPES AND DECLARATIONS

Closures. Mooly Sagiv. Michael Clarkson, Cornell CS 3110 Data Structures and Functional Programming

Object-oriented programming. and data-structures CS/ENGRD 2110 SUMMER 2018

The Pyth Language. Administrivia

CS558 Programming Languages Winter 2018 Lecture 4a. Andrew Tolmach Portland State University

G Programming Languages Spring 2010 Lecture 4. Robert Grimm, New York University

COS 140: Foundations of Computer Science

CS61C Machine Structures. Lecture 3 Introduction to the C Programming Language. 1/23/2006 John Wawrzynek. www-inst.eecs.berkeley.

Final-Term Papers Solved MCQS with Reference

Static Semantics. Lecture 15. (Notes by P. N. Hilfinger and R. Bodik) 2/29/08 Prof. Hilfinger, CS164 Lecture 15 1

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

COSE212: Programming Languages. Lecture 3 Functional Programming in OCaml

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

BM214E Object Oriented Programming Lecture 4

Lecture 1: Course Introduction

SAMS Programming A/B. Lecture #1 Introductions July 3, Mark Stehlik

CS 251 Intermediate Programming Methods and Classes

CS61C : Machine Structures

G Programming Languages Spring 2010 Lecture 6. Robert Grimm, New York University

CS 360: Programming Languages Lecture 12: More Haskell

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

CS 231 Data Structures and Algorithms, Fall 2016

Ruby: Introduction, Basics

Programming Languages and Techniques (CIS120)

Organization of Programming Languages CS 3200/5200N. Lecture 09

CS152 Programming Language Paradigms Prof. Tom Austin, Fall Syntax & Semantics, and Language Design Criteria

So what does studying PL buy me?

Lecture 09. Ada to Software Engineering. Mr. Mubashir Ali Lecturer (Dept. of Computer Science)

Compilers. Prerequisites

Functional Programming and Haskell

Review Chapter 6 in Bravaco. Short Answers 1. This type of method does not return a value. a. null b. void c. empty d. anonymous

Programming in C. What is C?... What is C?

Programming in C UVic SEng 265

G Programming Languages - Fall 2012

COP4020 Programming Assignment 1 - Spring 2011

Equivalent Notations. Higher-Order Functions. (define (f x y) ( body )) = (define f (lambda (x y) ) ) Anonymous Functions.

Lecture 7: Type Systems and Symbol Tables. CS 540 George Mason University

Programming in C. What is C?... What is C?

Algebraic data types. The case against null

CS321 Languages and Compiler Design I Winter 2012 Lecture 13

Announcements. Java Review. More Announcements. Today. Assembly Language. Machine Language

Example: Haskell algebraic data types (1)

Org Comp Refs Typ vro Prop Deleg Attrib Version Part. Introduction Part I. Radu Nicolescu Department of Computer Science University of Auckland

CMSC 330: Organization of Programming Languages. OCaml Imperative Programming

Programming with Math and Logic

Concepts of Programming Languages

LECTURE 3. Compiler Phases

Functional Programming Lecture 1: Introduction

IA010: Principles of Programming Languages

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

CSE450. Translation of Programming Languages. Lecture 11: Semantic Analysis: Types & Type Checking

Chapter 8 ( ) Control Abstraction. Subprograms Issues related to subprograms How is control transferred to & from the subprogram?

CS 360: Programming Languages Lecture 10: Introduction to Haskell

Chapter 5 Names, Binding, Type Checking and Scopes

CS312: Programming Languages. Lecture 21: JavaScript

NOTE: Answer ANY FOUR of the following 6 sections:

CS1 Lecture 3 Jan. 22, 2018

Types and Type Inference

Evolution of Programming Languages

Homework #3 CS2255 Fall 2012

CS 251 Intermediate Programming Methods and More

Java Bytecode (binary file)

LECTURE 17. Expressions and Assignment

Transcription:

Do Languages Matter? Why choose C vs C++ vs Java vs Python... Lecture 1: Overview CSC 131 Fall, 2014 Kim Bruce What criteria to decide? Scenarios: - ios app - Android App - Web App - Mac App - Windows app - System software - Scientific App - Scripting Do Languages Matter? Why Article Impact on programming practice SIGPLAN Education Board documents Learn widely-applicable design & implementation techniques Creating new domain specific languages or virtual machines Learning new computational models and speeding language learning Choosing the right language

Provide Abstractions PL s & Software Development Data Abstractions: - Basic data types: ints, reals, bools, chars, pointers - Structured: arrays, structs (records), objects - Units: Support for ADT s, modules, packages Control Abstractions: - Basic: assignment, goto, sequencing - Structured: if...then...else, loops, functions - Parallel: concurrent tasks, threads, message-passing Development process: - requirements - specification - implementation - certification or validation - maintenance Evaluate languages based on goals Goals of Some older PL s PL Choice Languages & their goals: - BASIC - quick development of interactive programs - Pascal - instruction - C - low-level systems programming - FORTRAN, Matlab - number-crunching scientific What about large-scale programs? - Ada, Modula-2, object-oriented languages Languages designed to support specific software methodologies. Language affect way people think about programming process. Hard for people to change languages if requires different way of thinking about process.

Paradigms or whatever you want to call them History of PL s Not crisp boundaries - Procedural - Functional - Logic or Constraint-programming - Object-oriented Machine language Assembly language High-level language Single highly-trained programmer Teams of programmers History of PLs Course Goals ve C Scheme Objective C Self Javascript Newer: Scala, Dart, Rust, NewSpeak, Swift, Grace, Pyret Upon completion of course should be able to: - Quickly learn programming languages, & how to apply them to effectively solve programming problems. - Rigorously specify, analyze, & reason about the behavior of a software system using a formally defined model of the system s behavior. - Realize a precisely specified model by correctly implementing it as a program, set of program components, or a programming language.

Administrivia Administrivia Web page at - http://www.cs.pomona.edu/classes/cs131/ Text by Mitchell: being revised now If needed, get account at - https://www.dci.pomona.edu/account-bin/ account_request.php - Do it early Recommended: - CS 81, Computability and Logic For computability and parsing Homework - Generally due every week on Thursday night. Posted on Friday - All homework must be turned in electronically Prefer Tex ed, but can scan in if want to write up by hand... but must be legible On-Line Discussions Grace Will be on Piazza You will receive an invitation later this week. - Do not throw it away You can ask and answer questions on-line. - TA s and I will monitor and respond. New language designed for teaching novices - Under development at Pomona, Portland State, and Victoria University, Wellington, NZ - Several published papers, nearly complete implementations Goal: Integrate current ideas in programming languages into a simple, general-purpose language aimed at novices.

Why New Language for Novices? Existing Languages Woefully Out-of-date Most popular languages too complex & lowlevel. Complexity necessary for professionals, but... - Accidental complexity of language can overwhelm essential complexity. - Minimize language complexity so can focus on programming/design complexity. C (1972), C++ (1983), Python (1989), Java (1994) History of pedagogical languages: - Basic, Logo, Pascal -... but not recently# - Miniworlds different: Alice, Karel the Robot, Greenfoot Java Problems public static void main(string [] args) Primitives versus objects, == versus equals Flawed implementation of generics Static versus instance on variables & methods float versus double versus int versus long 19 >>> class aclass: """A simple example class""" val = 47 def f(self): return 'hello world' >>> x = aclass() >>> x.value = 17 >>> x.val 47 >>> x.f() 'hello world' Python Problems 20 disappearing self? uncaught typos no information hiding Fine for scripting, but not large-scale software development

What if we could have: Hello World in Grace: Low syntactic overhead of Python, but with information hiding consistent method declaration & use required variable declarations optional (& gradual) type-checking direct definition of objects first-class functions print "hello world" 21 22 Objects def mysquare = object { var side := 10 Consistent method area { indenting is side * side required# But no method stretchby(n) { semicolons. side := side + n Defaults: #instance variables and constants are confidential (protected), methods are public# Annotations can override the defaults 23 Objects contain declarations definitions: - def x:number = 17 variables: - var y: String := hello methods: - method m(w:number,z:string) -> Done {... types: - type Point = {x -> Number y -> Number... Types are optional

Typed Objects type Square = { area -> Number stretchby(n:number) -> Done like Void def mysquare:square = object { var side:number := 10 method area -> Number { side * side method stretchby(n:number) -> Done { side := side + n 25 Classes Classes take parameters and generate objects class square.withside(s:number) -> Square { var side:number := s method area -> Number { side * side method stretchby(n:number) -> Done { side := side + n print "Created square with side {s" Type annotations can be omitted or included 26 Or Object w/factory Method def square = object { method withside(s:number) -> Square { object{ var side:number := s method area -> Number { side * side method stretchby(n:number)-> Done { side := side + n print "Created square with side {side" 27 What is type of square? Blocks Syntax for anonymous functions def double = {n -> n * n double.apply(7) // returns 49# // block is implicitly object w/apply method def nums = alist.from(1)to(100) def squares = nums.map {n -> n * n Blocks can take 0 or more parameters 28 function multipart method names

Blocks block, evaluated repeatedly Blocks make it simple to define new control structures as methods while {boolexp do { somestuff squares.foreach {n -> if (n.iseven) then {print n boolean expression, evaluated once Parentheses can be dropped if argument bounded by { or # No parens needed for parameterless methods Running Grace Compilers generating C or Javascript Use web-based editor/compiler at http://www.cs.pomona.edu/~kim/ minigrace 29 Grace on the Web Go to: http://www.cs.pomona.edu/~kim/minigrace/ Click on New at top to start new program (& choose name) or click on Upload Build button under edit window will compile code. When changes to Run press to execute Error messages not great yet. Right-click (& Save link as ) to save. Avoid Hoare s Billion Dollar Mistake No built-in null Accessing uninitialized variable is error Replace null by: sentinel objects, or error actions 32

Sentinel Objects A real object, tailored for the situation, e.g.: def emptylist = object { method asstring {"<emptylist>" method do(action) { method map(function) {self method size {0 name for object # being defined Sentinel Objects Simplifies code, eliminates testing for null class alist.cons(value, taillist) { method asstring {"({head:{tail)" method head {value boolean method tail {taillist expression, no conditional evaluated code method do(action) { once action.apply(head) tail.do(action) method map(function) { alist.cons(function.apply(head), tail.map(function)) method size {1 + tail.size Error Actions Grace encourages the use of blocks to specify error actions or default values: var x := table.at(key)ifabsent{ return unknown(key) Pattern Matching Provides type-safe switch/case match(myval) case{ n: Number -> "The number {n seen" case{ s: String -> "The string "++s++" seen" case{ true: Boolean -> "This is true" 35 36

Variant Types def absent = object {... type OptionNumber = Number singleton(absent) var x: OptionNumber := table.lookup(key) match(x) case {x':number ->... x'... case {_ -> return unknown(key) Questions? val: A B iff val:a or val:b Allows elimination of null 37