csc 1800 organization of programming languages
play

CSC 1800 Organization of Programming Languages Introduction, - PDF document

CSC 1800 CSC 1800 Organization of Programming Languages Introduction, Welcome & Getting Started 1 Course Overview Welcome! Web site Syllabus Schedule Slides, Reading Assignments Video Recordings Attendance


  1. CSC 1800 CSC 1800 Organization of Programming Languages Introduction, Welcome & Getting Started 1 Course Overview ⚫ Welcome! ⚫ Web site ⚫ Syllabus ⚫ Schedule ⚫ Slides, Reading Assignments ⚫ Video Recordings ⚫ Attendance ⚫ Blackboard – handing in, gradebook, etc. 2 2 1

  2. CSC 1800 Assessment 50% Assignments (questions, tasks, programming) 15% Exam #1 (midterm) 10% Programming language presentation 15% Exam #2 (final) 10% Participation (attendance, class discussion, intellectual contribution to class) 3 3 Class Style ⚫ Lecture ⚫ Demo ⚫ Hand-on Activities ⚫ Problem solving ⚫ Language design & programming ⚫ Presentations ⚫ Blackboard – gradebook, assignments, exams ⚫ Discussion ( Blackboard or Piazza ) – questions & answers 4 4 2

  3. CSC 1800 Goals for Week One ⚫ Names and faces ⚫ Seating chart filled out ⚫ Intro to Programming Languages ⚫ First experiments ⚫ Start homework assignment #1 5 5 INTRODUCTION TO PROGRAMMING LANGUAGES 6 6 3

  4. CSC 1800 Why Study Programming Languages? ⚫ Increased capacity to express ideas ⚫ Improved background for choosing appropriate language ⚫ Increased ability to learn new languages ⚫ Better understanding of the significance of implementation ⚫ Better use of languages that are already known ⚫ Overall advancement of computing 7 7 Programming Domains ⚫ Scientific Applications (Fortran) ⚫ Business Applications (COBOL) ⚫ Artificial Intelligence (LISP, Prolog) ⚫ Systems Programming (C) ⚫ Web Software (HTML, PHP, Java) 8 8 4

  5. CSC 1800 Language Evaluation Criteria ⚫ Readability : the ease with which programs can be read and understood ⚫ Writability : the ease with which a language can be used to create programs ⚫ Reliability : conformance to specifications (i.e., performs to its specifications) ⚫ Portability : moving program from one implementation to another ⚫ Generality : applicability to a wide range of domains ⚫ Well-definedness : completeness of language ⚫ Cost : easy to learn, use, maintain 9 9 Influences on Language Design ⚫ Computer Architecture Languages are developed around the prevalent computer architecture, – known as the von Neumann architecture ⚫ Programming Methodologies – New software development methodologies (e.g., object-oriented software development) led to new programming paradigms and by extension, new programming languages 10 10 5

  6. CSC 1800 The von Neumann Architecture Memory (stor es bot h instructi ans and data) R es ult s of Instructions and data op erations - Arithme ti c and Control i- Input and output devic es logic un it unit Ce ntral pro cess ing unit 11 11 The von Neumann Architecture ⚫ Fetch-execute-cycle initialize the program counter repeat forever fetch the instruction pointed by the counter increment the counter decode the instruction execute the instruction end repeat 12 12 6

  7. CSC 1800 Programming Methodologies Influences ⚫ 1950s and early 1960s: Simple applications; worry about machine efficiency ⚫ Late 1960s: People efficiency became important; readability, better control structures – structured programming – top-down design and step-wise refinement ⚫ Late 1970s: Process-oriented to data-oriented – data abstraction ⚫ Middle 1980s: Object-oriented programming – Data abstraction + inheritance + polymorphism ⚫ Since: Write-once-run-anywhere, rapid devel, long-term maintainability, focus on OOP 13 13 LANGUAGE PARADIGMS & IMPLEMENTATIONS 14 14 7

  8. CSC 1800 Language Categories or Paradigms ⚫ Imperative – Central features are variables, assignment statements, and iteration – Include languages that support object-oriented programming Include scripting languages – Include the visual languages – Examples: C, Java, Perl, JavaScript, Visual BASIC .NET, C++ – ⚫ Functional Main means of making computations is by applying functions to given – parameters Examples: LISP, Scheme – ⚫ Logic Rule-based (rules are specified in no particular order) – Example: Prolog – ⚫ Markup – Markup languages extended to support some programming – Examples: HTML, LaTex, XML 15 15 Implementation Methods ⚫ Compilation – Programs are translated into machine language ⚫ Interpretation – Programs are interpreted by another program known as an interpreter ⚫ Hybrid – A compromise between compilers and interpreters 16 16 8

  9. CSC 1800 Compilation ⚫ Translate high-level program (source language) into machine code (machine language) ⚫ Slow translation, fast execution ⚫ Compilation process has several phases: – lexical analysis: converts characters in the source program into lexical units – syntax analysis: transforms lexical units into parse trees which represent the syntactic structure of program – Semantics analysis: generate intermediate code – code generation: machine code is generated 17 17 Compilation Process lexical ana l yzer LexicaluniU Syntax analyzer Intermediate code generator Op(1m1zatloo (oplional) (and~ntic ,_ ;malyzer) Intermediate M!lthine l nputdala Language Compu1.cr Resulu 18 18 9

  10. CSC 1800 Interpretation ⚫ No translation ⚫ Easier implementation of programs (run-time errors can easily and immediately be displayed) ⚫ Slower execution (10 to 100 times slower than compiled programs) ⚫ Often requires more space ⚫ Now rare for traditional high-level languages ⚫ Significant comeback with some Web scripting languages (e.g., JavaScript, PHP) 19 19 Interpretation Process Source program /Input data Interpreter Results 20 20 10

  11. CSC 1800 PARADIGM EXAMPLES 21 21 How Many Languages? ⚫ There are over 700 programming languages that were developed and used enough to be recognized ⚫ How many languages should you know? ⚫ Good to know: HTML, CSS, JavaScript, Java, C, C++, C#, Python, PHP, Perl, Swift, – Go, R, TypeScript, Shell, PowerShell, Batch, SQL, MATLAB, Ruby, Groovy, Scala, Haskell, Fortran, COBOL 22 22 11

  12. CSC 1800 Factorial ⚫ A factorial of N! an integer N is the product of all integers from 1 to N n! = n x (n - 1) x (n - 2) x (n - 3) x · · · x 3 x 2 x 1 ⚫ For example: 5! = 5 X 4 X 3 X 2 X 1 = 120 23 23 Imperative Languages - C ⚫ Example: a factorial function in C int fact(int n) { int sofar = 1; while (n>0) sofar *= n--; return sofar; } ⚫ Hallmarks of imperative languages: Assignment – Iteration – – Order of execution is critical – Fast, maps easily to hardware instructions 24 24 12

  13. CSC 1800 Functional Languages - ML ⚫ Example: a factorial function in ML fun fact x = if x <= 0 then 1 else x * fact(x-1); ⚫ Hallmarks of functional languages: – Single-valued variables – Heavy use of recursion 25 25 Functional Languages - Lisp ⚫ Example: a factorial function in Lisp (defun fact (x) (if (<= x 0) 1 (* x (fact (- x 1))))) ⚫ Looks very different from ML ⚫ But ML and Lisp are closely related Single-valued variables: no assignment – Heavy use of recursion: no iteration – 26 26 13

  14. CSC 1800 Logic Languages - Prolog ⚫ Example: a factorial function in Prolog fact(X,1) :- X =:= 1. fact(X,Fact) :- X > 1, NewX is X - 1, fact(NewX,NF), Fact is X * NF. ⚫ Hallmark of logic languages Program expressed as rules in formal logic – Also known as "Declarative" languages – 27 27 Object Oriented Languages - Java ⚫ Objects are when you attach the code as close as you can to the data it manipulates ⚫ Paradigm can be considered imperative but data- centered. ⚫ Simple Example: a Java definition for a kind of object that can store an integer and compute its factorial 28 28 14

  15. CSC 1800 Object Oriented Languages - Java public class Factorial { public Factorial() { } public int fact(int n) { int sofar = 1; while (n > 1) sofar *= n--; return sofar; } public static void main(String[] args) { int f = (new Factorial()).fact(5); System.out.println("result: " + f); } } 29 29 Which paradigm? - Forth ⚫ Example: a factorial function in Forth : FACTORIAL 1 SWAP BEGIN ?DUP WHILE TUCK * SWAP 1- REPEAT ; ⚫ A stack-oriented language Postscript is similar – Could be called imperative, but has little in common – with most imperative languages 30 30 15

  16. CSC 1800 Which paradigm? - APL ⚫ Example: a factorial function in APL    X ⚫ An APL expression that computes X’s factorial Expands X it into a vector of the integers 1..X, then multiplies – them all together (You would not really do it that way in APL, since there is a – predefined factorial operator: !X) – Could be called functional, but has little in common with most functional languages 31 31 DEFINING LANGUAGES 32 32 16

  17. CSC 1800 Language Partisans ⚫ Be aware… ⚫ There is a lot of argument about the relative merits of different languages ⚫ Every language has partisans, who praise it in extreme terms and defend it against all detractors ⚫ All languages (programming and otherwise) EVOLVE! 33 33 Language Standards ⚫ The documents that define language standards are often drafted by international committees ⚫ Can be a slow, complicated and rancorous process ⚫ Not many languages preserve backward compatibility over the long-term 34 34 17

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend