![]() |
![]() |
|
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? * postscript Example: enscript -o foo.ps ; cat foo.ps ; show foo.ps Example: cat wimpoutBoard.ps ; show wimpoutBoard.ps - C, Ada, Fortran, Pascal, Rexx, ... - Smalltalk, Java, C++, C#, ... - APL; Mathematica; Matlab - javascript, perl, etc; html ? -- no; data. But, .css. - sh/csh, .bat, applescript; scriptable photoshop? Example: cd ~/Unix find \*.ps find \*.ps | grep -i wimpout - a *programmable* calculator. * MS Word "macros" and mailing-list scripts - abacus-instructions ? 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, ======== Example of comparing languages: In Java / 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 in Scheme? syntax: ( ~funcname~ ~expr~ ~expr~ ... ) How to call a function in Java? syntax: ~obj~.~methname~( ~expr~, ~expr~, ...) ~methname~( ~expr~, ~expr~, ...) ~class~.~methname~( ~expr~, ~expr~, ...) new ~className~( ~expr~, ~expr~, ...) ~expr~ ~op~ ~expr~ ~op~ ~expr~ ~array~[~expr~] ~array~[~expr~] = ... Course-info sheet. Knowing a *language* (as opposed to programming) means knowing Syntax, Semantics, Pragmatics. Studying languages: - Syntax -- how to convert to an intermediate form 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; } }
©2008, Ian Barland, Radford University Last modified 2008.Sep.06 (Sat) |
Please mail any suggestions (incl. typos, broken links) to ibarland ![]() |
![]() |