![]() |
![]() |
|
home—info—lectures—exams—hws—archive
Course-info sheet. What makes a programming-language a language? - call a function - loops - can assign variables? - loops (or, goto), as part of language? Which of these functions could we live without? How? What programming languages have you used / heard of? - C, Ada, Fortran, Pascal, Rexx, ... - Smalltalk, Java, C++, C#, ... - APL; Mathematica; Matlab - javascript, perl, etc; html ? -- no; data. But, .css. - postscript: helloWorld.ps and postscript source wimpoutBoard.ps and postscript src - the Unix shell: cd ~/380/Lectures/ find . -name \*.ps -print find . -name \*.ps -print | grep -i wimpout enscript -o foo.ps ; cat foo.ps ; show foo.ps - a *programmable* calculator. - MS Word "macros" and mailing-list scripts - abacus-instructions ? Families of languages: procedural; object-oriented; functional; declarative; scripting(?); math [perhaps 'very-high-level'?] MS Word, game-level-editors [special-purpose "little languages"] For example, let's compare two families that share a lot in common: What is the difference between O.O. and Procedural? name.substring(3,7) vs substring(name,3,7) for class Employee, jo.giveRaise(8.50) vs giveRaise(jo,8.50) The win comes (a) through polymorphism (inheritance) -- you can subclass "special" Employees and refine giveRaise; a procedural approach would have to replace jo.giveRaise(8.50) with if (jo instanceof SpecialEmployee) giveSpecialRaise(jo,8.50) else giveRaise(jo,8.50) and these sorts of changes would have to be made *wherever* the giveRaise method was called. (b) OO also gives a good way of *organizing* code -- a managerial tool so everybody knows where to look for certain code. What makes a program language more *powerful* than another? ("expressive") Is assembly more powerful than Java? Java more powerful than assembly? Church-Turing Thesis: TM = lambda calculus = RAM = abacus = ... caveat: phrase in terms of desired *computation*; while Java doesn't have "change mem location #42BF2" like C does, C doesn't have "set lever17 of Babbage's Analytic Engine three notches forward" ... but that's okay, Knowing a *language* (as opposed to programming) means knowing Syntax, Semantics, Pragmatics. Studying languages: - Syntax -- how to convert to an intermediate form How to choose to represent exact vs inexact numbers, how to specify units e.g. scope of variables, namespaces, ... - Semantics e.g. pass-by-ref vs value, ... - Pragmatics e.g. What features are helpful to what audiences? class Account { int balance; Account() { int balance = 100; } }
Example of comparing languages: Java vs Scheme: 3+4 (+ 3 4) 3+4*5 (+ 3 (* 4 5)) (3+4)*5 (* (+ 3 4) 5) Math.sqrt(25) (sqrt 25) Call a constructor: new Employee("jo", 4.50) vs (make-employee "jo" 4.50) Access the 3rd element of a list `data`: data.get(3) (list-ref data 3) arr[3] (vector-ref arr 3) - How to call a function: Java: obj.meth(...) [also with implicit 'this'] class.meth(...) new ClassName(...) super(...) this(...) a + b (+ a b) !a (not a) arr[i] (vector-ref arr i) compare to List.get(i) arr[i] = ... (vector-set! arr i ...) compare to List.set(i,...) obj.f (widget-f obj) obj.f = ... (set-widget-f! obj ...) - Left with the question: pros/cons of having operators, as distinct from functions? - pro: more natural for human readers - con: a different syntax (harder for compiler-writer; learning?) - con: requires(?) that those characters are reserved - con: 37 operators with 14 levels of precedence: Java precedence table 2.0-1.1 25*(7/25) - Scheme overview: - Values: 2, 3.8, #i3.8, "hello", 'orange, >insert-image; true, false (symbols are like enumerated types) - Placeholders (define a 4.2) (define b 2/3) (define c (+ a b 17)) (define z 2.7) (define ufo >insert-image) - expressions (/ (+ (- b) (sqrt (- (* b b) (* 4 a c)))) (* 2 a))
home—info—lectures—exams—hws—archive
©2009, Ian Barland, Radford University Last modified 2009.Feb.08 (Sun) |
Please mail any suggestions (incl. typos, broken links) to ibarland ![]() |
![]() |