Date post: | 01-Nov-2015 |
Category: |
Documents |
Upload: | bhavyaa-singh |
View: | 215 times |
Download: | 0 times |
cs7100(Prasad)L1Intro*Systematic Development of Programming Languages
L1Intro
cs7100(Prasad)L1Intro*Orthogonal ParametersConceptual view (Model of Computation)imperative, functional, relational,...Level of abstraction (Model of Implementation)problem domain...machine
Computational Task : I/O relation to be implemented
L1Intro
cs7100(Prasad)L1Intro*1. Customized Digital Computer OjIkOkTask jTask kRig different circuit for each task
L1Intro
cs7100(Prasad)L1Intro*von Neumann showed the existence of a Universal Machine (hardware) that can be customized using control inputs to carry out different tasks.Software is the encoding of the task to control this machine.
2. Stored Program Computingencoding(Tj)IjOj
L1Intro
cs7100(Prasad)L1Intro*Imperative LanguagesModel of ComputationALU + Memory + Input + Output(von Neumann architecture)Levels of Abstraction (Human Interface)Machine Language Binary Representation of the taskAssembly LanguageSymbolic Representation of the task
L1Intro
Assembly LanguageUse symbols instead of binary digits to describe fields of instructions.Every aspect of machine visible in program:One statement per machine instruction.Register allocation, call stack, etc. must be managed explicitly.No structure: everything looks the same.10101100100000100000000000010101ADDIR4R221ADDI R4,R2,21 cs7100(Prasad)L1Intro*
L1Intro
cs7100(Prasad)L1Intro*Pros and Cons of Assembly LanguageAvoids Absolute Addressingrelocatable, reusable/shareableUses Symbolic Namesreadable Low-level programming wastes effort in coding a solution rather than solving a problem.Difficult to build and maintain large programs.
L1Intro
cs7100(Prasad)L1Intro*High-level LanguageProvides notation to describe problem solving strategies rather than organize data and instructions at machine-level. Improves programmer productivity by supporting features to abstract/reuse code, and to improve reliability/robustness of programs.Requires a compiler.
L1Intro
cs7100(Prasad)L1Intro*
Levels of Abstraction
Problem Domain (stacks, tables)Machine (char, int)C++(Class Hierarchies) Java/C#/Scala/Python/Scheme/ClojureAdaCPascal Assembly Language(ADTs)(arrays)
L1Intro
cs7100(Prasad)L1Intro*Evolution of Programming Languages FORTRAN ( FORmula TRANslator) Goals : Scientific Computations Efficiency of execution Compile-time storage determination Features : Symbolic Expressions Subprograms Absence of Recursion
COBOL Goal: Business Application Features : Record/Structure; File Handling
L1Intro
cs7100(Prasad)L1Intro*Evolution of Programming Languages ALGOL- 60 (ALGOrithmic Language)Goals : Communicating AlgorithmsFeatures : Block Structure (Top-down design) Recursion (Problem-solving strategy) BNF - Specification
LISP (LISt Processing) Goals : Manipulating symbolic information Features : List Primitives Interpreters / Environment
L1Intro
cs7100(Prasad)L1Intro*ProblemsNot rugged wrt typographical errorsDo 10 I = 1.20 I5 = I5 + 1 vs vsDo 10 I = 1,20 I5 = IK + 1Remedy: Use spaces to delimit tokens, Declare before useUnintended CoercionI > J and falseRemedy: Type checking
L1Intro
cs7100(Prasad)L1Intro* Evolution of Programming Languages Pascal Goal : Structured Programming, Type checking, Compiler writing. Features : Rich set of data types for efficient algorithm design E.g., Records, sets, ... Variety of readable single-entry single-exit control structures E.g., for-loop, while-loop,... Efficient Implementation Recursive descent parsing
L1Intro
cs7100(Prasad)L1Intro*Programming in the LargePrograms no longer monolithic. Developed by a team of programmers.Code sharing and reuse very important.Correctness, reliability, and robustness essential.Data Abstraction / Encapsulation / Strong TypingAda, CLU, Modula etc.
L1Intro
cs7100(Prasad)L1Intro* Other LanguagesFunctionalCommon LISP, Scheme, ClojureML, HaskellLogic PrologObject-orientedSmalltalk, SIMULA, Modula-3, OberonC++, Eiffel, Ada-95, Java, C#HybridPython, Ruby, Scala Application specific languages and tools
L1Intro
cs7100(Prasad)L1Intro*Scripting vs Systems Programming LanguagesDesigned for gluing applications : flexibilityInterpreted Dynamic typing and variable creation Data and code integrated : meta-programming supportedExamples: PERL, Tcl, Python, Ruby, PHP, Scheme, Visual Basic, etc. Designed for building applications : efficiencyCompiledStatic typing and variable declaration Data and code separated : cannot create/run code on the flyExamples: PL/1, Ada, Java, C, C++, C#, Scala, etc.
L1Intro
cs7100(Prasad)L1Intro*(contd)Does application implement complex algorithms and data structures?Does application process large data sets (>10,000 items)?Are application functions well-defined, fixed?If yes, consider a system programming language.Is the main task to connect components, legacy apps?Does the application manipulate a variety of things?Does the application have a GUI?Are the application's functions evolving rapidly?Must the application be extensible?Does the application do a lot of string manipulation?If yes, consider a scripting language.
L1Intro
cs7100(Prasad)L1Intro* Jython (for convenient access to Java APIs)I:\tkprasad\cs7100>jython>>> import javax.swing as swing>>> win = swing.JFrame("Welcome to Jython")>>> win.size = (200, 200)>>> win.show()>>> ^Z
L1Intro
cs7100(Prasad)L1Intro*Java vs Jython
map = new HashMap();map.put("one",new Integer(1));map.put("two",new Integer(2));map.put("three",new Integer(3));
System.out.println(map.get("one"));
list = new LinkedList();list.add(new Integer(1));list.add(new Integer(2));list.add(new Integer(3));
map = {"one":1,"two":2,"three":3}
print map ["one"]
list = [1, 2, 3]
L1Intro
cs7100(Prasad)L1Intro*(contd)
for i in list:
(* iterator *)
newList = [function(i) for i in oldList]
(* list comprehension *)
for (Iterator i; i.hasNext();) { i.next(); }
List newList = ArrayList()for (Iterator i; i.hasNext();) { Object obj = i.next(); newList.add(function(obj))}
L1Intro
cs7100(Prasad)L1Intro*Functional Programming in Jython
apply(lambda x,y : x*y, (10, 20))# 200map(lambda x,y: x + y, [[1,2],[a]], [[3],[b]])# [[1, 2, 3], [a, b]]reduce(lambda x,y: x + y, [1,2,3], 100)# 106filter(lambda x: x > 0, range(10,-5,-3))# [10, 7 , 4, 1]
L1Intro
cs7100(Prasad)L1Intro*Meta-programming in JythonDynamic code evaluationprint eval ([1,3] + range(6,10,3))# [1, ,3, 6, 9]x = 2 + 3jexec x = 5, x + x#(5, (4+6j)
L1Intro
cs7100(Prasad)L1Intro*import java.lang as langimport javax.swing as swingimport java.awt as awt
names = ["Groucho", "Chico", "Harpo"]quotes = {"Groucho": "Say the secret word", "Chico": "Viaduct?", "Harpo": "HONK!"}
def buttonPressed(event): field.text = quotes[event.source.text]
def exit(event): lang.System.exit(0) def createButton(name): return swing.JButton(name, preferredSize=(100,20), actionPerformed=buttonPressed) Java functionality through Jython
L1Intro
cs7100(Prasad)L1Intro* win = swing.JFrame("Welcome to Jython", size=(200, 200),windowClosing=exit)
win.contentPane.layout = awt.FlowLayout( )
field = swing.JTextField(preferredSize=(200,20))win.contentPane.add(field)
buttons = [createButton(each) for each in names]
for eachButton in buttons: win.contentPane.add(eachButton)
win.pack( )win.show( )
L1Intro
Current TrendMultiparadigm languages Functional constructs for programming in the small Focus on conciseness and correctnessObject-Oriented constructs for programming in the largeFocus on programmer productivity, robustness and code evolutionExample languagesOlder: Python, Ruby Recent: Scala, F# cs7100(Prasad)L1Intro*
L1Intro
cs7100(Prasad)L1Intro*Scheme (dialect of LISP)Recursive definitionsSymbolic computation : List ProcessingHigher-order functionsDynamic type checkingFunctional + Imperative featuresAutomatic storage managementProvides a uniform executable platform for studying, specifying, and comparing languages.
L1Intro
cs7100(Prasad)L1Intro*Standard ML and ScalaStrongly typed languagestatic type inferenceSML supports polymorphic typesSupports Abstract Data Types and ModulesHigher-order functionsPattern matchingcf. Prolog, list-processing in Scheme
L1Intro
Java vs Scala//Java - what we're used to seeing
public String buildEpochKey(String... keys) {StringBuilder s = new StringBuilder("elem") for(String key:keys) { if(key != null) { s.append(".") s.append(key) } } return s.toString(). toLowerCase()}cs7100(Prasad)L1Intro*
L1Intro
Java vs Scala//Scala def buildEpochKey(keys: String*): String = { ("elem" +: keys) . mkString(".") . toLowerCase}
println(buildEpochKey("aBcDeF"))cs7100(Prasad)L1Intro*
L1Intro
***************Typing: the degree to which the meaning of information is restricted in advance of its use.*Reference: John Ousterhout, Sun Microsystems, Inc.Scripting: Higher Level Programming for the 21st Century*Using interpreter for rapid prototyping Comparing Systems Programming Language (Java) with Scripting language (Python/Jython) on the same baseline (Java APIs)*Observe construction of lists, maps, call backs, lack of explicit type declarations, etc*Observe constructors, list comprehension, loops, and the translation of dynamically typed language into a statically typed language etc
Run using: jython < demo.jy*The language we use for programming in CS7100.*Meta-Language: Another candidate for specification of languages. (History: Denotational Semantics, LCF)+: means add the item before the +: to the item after itfilter filters a collection based on the closure after it. Filter will pass each item into the closure. If the closure returns true, the item will be added to the new collection, otherwise it won't._ in a closure is a shortcut for saying the first parameter passed inmkString is Scala's version of join. mkString also has a variant that takes delimiters.toLowerCase is just that. A call on the string that is the result of mkString-----------------------// scala eg.scala==================http://www.simplyscala.com/==================def buildEpochKeyN(keys: String*): String = { keys filter(_ != null) mkString(".") toLowerCase}buildEpochKeyN()buildEpochKeyN("abc","pqr","x")
def buildEpochKey(keys: String*): String = { ("elem" +: keys) . mkString(".") . toLowerCase}buildEpochKey("abc","pqr","x")
buildEpochKey: (keys: String*)Stringres0: String = elem.abc.pqr.x
*