Download presentation
Presentation is loading. Please wait.
Published byAlan Jesse Parsons Modified over 9 years ago
1
cs784(Prasad)L1Intro1 Systematic Development of Programming Languages
2
cs784(Prasad)L1Intro2 Orthogonal Parameters u Conceptual view ( Model of Computation ) »imperative, functional, relational,... u Level of abstraction ( Model of Implementation ) »problem domain »... »machine –Computational Task : I/O relation to be implemented
3
cs784(Prasad)L1Intro3 1. Customized Digital Computer Oj Ij Ik Ok Task j Task k Rig different circuit for each task
4
cs784(Prasad)L1Intro4 u von Neumann showed the existence of a Universal Machine (hardware) that can be customized using control inputs to carry out different tasks. u Software is the encoding of the task to control this machine. 2. Stored Program Computing encoding(Tj) IjOj
5
cs784(Prasad)L1Intro5 Imperative Languages u Model of Computation »ALU + Memory + Input + Output (von Neumann architecture) u Levels of Abstraction (“ Human Interface ”) –Machine Language »Binary Representation of the task –Assembly Language »Symbolic Representation of the task
6
Assembly Language u Use symbols instead of binary digits to describe fields of instructions. u 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. 10101100100000100000000000010101 ADDIR4R221 ADDI R4,R2,21
7
cs784(Prasad)L1Intro7 Pros and Cons of Assembly Language u Avoids Absolute Addressing »relocatable, reusable/shareable u Uses Symbolic Names »readable Low-level programming wastes effort in coding a solution rather than solving a problem. u Difficult to build and maintain large programs.
8
cs784(Prasad)L1Intro8 High-level Language u Provides 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. u Requires a compiler.
9
cs784(Prasad)L1Intro9 Levels of Abstraction Problem Domain (stacks, tables) Machine (char, int) C++ (Class Hierarchies) Java/C#/Scala/Python/Scheme Ada C Pascal Assembly Language (ADTs) (arrays)
10
cs784(Prasad)L1Intro10 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
11
cs784(Prasad)L1Intro11 Evolution of Programming Languages ALGOL - 60 (ALGOrithmic Language) Goals : Communicating Algorithms Features : Block Structure (Top-down design) Recursion (Problem-solving strategy) BNF - Specification LISP (LISt Processing) Goals : Manipulating symbolic information Features : List Primitives Interpreters / Environment
12
cs784(Prasad)L1Intro12 Problems u Not rugged wrt typographical errors Do 10 I = 1.20 I5 = I5 + 1 vs vs Do 10 I = 1,20 I5 = IK + 1 –Remedy: Declare before use u Unintended Coercion I > J and false –Remedy: Type checking
13
cs784(Prasad)L1Intro13 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
14
cs784(Prasad)L1Intro14 Programming in the Large u Programs no longer monolithic. Developed by a team of programmers. u Code sharing and reuse very important. u Correctness, reliability, and robustness essential. –Data Abstraction / Encapsulation / Strong Typing »Ada, CLU, Modula etc.
15
cs784(Prasad)L1Intro15 Other Languages u Functional »Common LISP, Scheme »ML, Haskell u Logic »Prolog u Object-oriented »Smalltalk, SIMULA, Modula-3, Oberon »C++, Java, C#, Eiffel, Ada-95 u Hybrid »Python, Ruby, Scala u Application specific languages and tools
16
cs784(Prasad)L1Intro16 Scripting vs Systems Programming Languages u Designed for gluing applications : flexibility u Interpreted u Dynamic typing and variable creation u Data and code integrated : meta-programming supported u Examples: PERL, Tcl, Python, Ruby, PHP, Scheme, Visual Basic, Scala, etc. u Designed for building applications : efficiency u Compiled u Static typing and variable declaration u Data and code separated : cannot create/run code on the fly u Examples: PL/1, Ada, Java, C, C++, C#, Scala, etc.
17
cs784(Prasad)L1Intro17 (cont’d) u Does application implement complex algorithms and data structures? u Does application process large data sets (>10,000 items)? u Are application functions well-defined, fixed? If yes, consider a system programming language. u Is the main task to connect components, legacy apps? u Does the application manipulate a variety of things? u Does the application have a GUI? u Are the application's functions evolving rapidly? u Must the application be extensible? u Does the application do a lot of string manipulation? If yes, consider a scripting language.
18
cs784(Prasad)L1Intro18 Jython (for convenient access to Java APIs) I:\tkprasad\cs784>jython Jython 2.1 on java1.4.1_02 (JIT: null) Type "copyright", "credits" or "license" for more information. >>> import javax.swing as swing >>> win = swing.JFrame("Welcome to Jython") >>> win.size = (200, 200) >>> win.show() >>> ^Z
19
cs784(Prasad)L1Intro19 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]
20
cs784(Prasad)L1Intro20 (cont’d) 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)) }
21
cs784(Prasad)L1Intro21 Functional Programming in Jython apply(lambda x,y : x*y, (10, 20)) # 200 map(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) # 106 filter(lambda x: x > 0, range(10,-5,-3)) # [10, 7, 4, 1]
22
cs784(Prasad)L1Intro22 Meta-programming in Jython u Dynamic code evaluation print eval (“[1,3] + range(6,10,3)”) # [1,,3, 6, 9] x = 2 + 3j exec “x = 5, x + x” #(5, (4+6j)
23
cs784(Prasad)L1Intro23 import java.lang as lang import javax.swing as swing import 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
24
cs784(Prasad)L1Intro24 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( )
25
Current Trend u Multiparadigm languages –Functional constructs for programming in the small »Focus on conciseness and correctness –Object-Oriented constructs for programming in the large »Focus on programmer productivity and code evolution u Example languages –Older: Python, Ruby, –Recent: Scala, F#, etc cs784(Prasad)L1Intro25
26
cs784(Prasad)L1Intro26 Scheme (dialect of LISP) u Recursive definitions u Symbolic computation : List Processing u Higher-order functions u Dynamic type checking u Functional + Imperative features u Automatic storage management –Provides a uniform executable platform for studying, specifying, and comparing languages.
27
cs784(Prasad)L1Intro27 Standard ML and Scala u Strongly typed language –static type inference –SML supports polymorphic types u Supports Abstract Data Types and Modules u Higher-order functions u Pattern matching –cf. Prolog, list-processing in Scheme
28
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() } cs784(Prasad)L1Intro28
29
Java vs Scala //Scala def buildEpochKey(keys: String*): String = { ("elem" +: keys) filter(_ != null) mkString(".") toLowerCase } cs784(Prasad)L1Intro29
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.