Microsoft PowerPoint - Week 06 - Programming Languages

Document Sample
Microsoft PowerPoint - Week 06 - Programming Languages Powered By Docstoc
					                                                                                          Announcements
                                                   Programming
                                                     Languages        ! Monday evening GBA section has been shut down
                                                                         " If you were assigned to this section, please find a
                                                                           different section
                                                                         " If you cannot attend a different section, please contact
                                                                           one of the TAs


                                                                      ! Monday March 3 (next week) there will be a
                                                                        combination help-with-project/pizza session in
                                                            Week 6
                                                                        place of the 12:20 sections
                                               CS 212 – Spring 2008
                                                                         " Keep an eye on the website for further information




                         FORTRAN                                                                 ALGOL
! Initial version developed in     ! Example code                                                       ! Sample code
  1957 by IBM                         C       SUM OF SQUARES                                            comment Sum of squares
                                              ISUM = 0                                                  begin
                                              DO 100 I=1,10                                                 integer i, sum;
                                              ISUM = ISUM + I*I
                                                                                                            for i:=1 until 10 do
                                          100 CONTINUE
                                                                                                               sum := sum + i*i;
                                                                      ! ALGOL                           end
                                   ! FORTRAN introduced many
                                                                        = ALGOrithmic Language          ! ALGOL 60 included
                                     of the ideas typical of
                                     programming languages            ! Developed by an                  recursion
                                                                        international committee            " Pro: Makes it easy to
                                      "   Assignment
                                                                      ! First version in 1958 (not           design clear, succinct
                                      "   Loops
                                                                        widely used)                         algorithms
                                      "   Conditionals
                                                                                                           " Con: Too hard to
                                      "   Subroutines                 ! Second version in 1960
                                                                                                             implement; too inefficient
                                                                        (widely used)




                            COBOL                                                      Simula & Smalltalk
! COBOL =                          ! COBOL included the idea of       ! These languages introduced
  COmmon Business Oriented           records (a single data             and popularized Object
  Language                           structure with multiple           Oriented Programming
! Developed by the US                fields, each field holding a      (OOP)
  government (about 1960)            value)                              " Simula was developed in
    " Design was greatly                                                   Norway as a language for
      influenced by Grace                                                  simulation (late 60s)
      Hopper                                                             " Smalltalk was developed at
                                                                           Xerox PARC in the 70s
! Goal: Programs should look
  like English
    " Idea was that anyone                                            ! These languages included
      should be able to read and                                         " Classes
      understand a COBOL                                                 " Objects
      program                                                            " Subclasses & Inheritance
                                     Java                                        Programming Languages at Cornell
! Developed by Sun                                                          ! Some of the languages used in Cornell’s CS Dept
  Microsystems; first                                                           " Java
  released in 1995                                                                  # 100, 211, 212
                                                                                    # Many of the upper level courses
                                                                                " C, C++, C#
! Java includes                                                                     # Many of the upper level courses (networks, distributed computing)
    " Assignment statements,                                                    " Matlab
      loops, conditionals from                                                      # 100M, numerical analysis courses
      FORTRAN (but Java uses                                                    " ML
      syntax from C)                                                                # Functional programming
                                                                                    # 312, logic-related courses
    " Recursion from ALGOL
                                                                                " SQL
    " Fields from COBOL                                                             # Query language for databases
    " OOP from Simula &                                                             # 432, database-related courses
      Smalltalk                                                             ! Fortran, C, C++, Matlab are used widely in Engineering
                                                                            ! SAS (originally, Statistical Analysis System) is used in various
                                                                              courses around campus




   Some Other Programming Languages                                            Some Other Programming Languages
! (from a Yahoo list)                                                       ! (from a Yahoo list)
  ABC, ActiveX, Ada, AMOS, APL, AppleScript, Assembly, awk,                   ABC, ActiveX, Ada, AMOS, APL, AppleScript, Assembly, awk,
  BASIC, BETA, C and C++, C#, Cecil, Cilk, CLU, COBOL, ColdC,                 BASIC, BETA, C and C++, C#, Cecil, Cilk, CLU, COBOL, ColdC,
  cT, Curl, Delphi, Dylan, Dynace, Eiffel, Forth, Fortran, Guile,             cT, Curl, Delphi, Dylan, Dynace, Eiffel, Forth, Fortran, Guile,
  Haskell, Icon, IDL, Infer, Intercal, J, Java, JavaScript, JCL,              Haskell, Icon, IDL, Infer, Intercal, J, Java, JavaScript, JCL,
  JOVIAL, Limbo, Lisp, Logo, M - MUMPS, Magma, ML, Modula-                    JOVIAL, Limbo, Lisp, Logo, M - MUMPS, Magma, ML, Modula-
  2, Modula-3, Oberon, Obliq, Occam, OpenGL, Pascal, Perl,                    2, Modula-3, Oberon, Obliq, Occam, OpenGL, Pascal, Perl,
  PL/I, Pop, PostScript, Prograph, Prolog, Python, Rexx, Ruby,                PL/I, Pop, PostScript, Prograph, Prolog, Python, Rexx, Ruby,
  SAS, Sather, Scheme, ScriptEase, SDL, Self, SETL,                           SAS, Sather, Scheme, ScriptEase, SDL, Self, SETL,
  Smalltalk, SQL, Tcl/Tk, TOM, Verilog, VHDL, VRML, Visual,                   Smalltalk, SQL, Tcl/Tk, TOM, Verilog, VHDL, VRML, Visual,
  Visual Basic, Z                                                             Visual Basic, Z




Portion of a Computer Languages History from http://www.levenez.com/lang/
                                                                                                So Many Languages

                                                                            ! Formula Translation (FORTRAN) in 1954 led to…
                                                                                " Over 2000 computer languages


                                                                            ! How many languages in use today?
                                                                                " Difficult to say
                                                                                " Legacy software (using outdated languages) is everywhere


                                                                            ! Why can’t we just use one language?
     Evolution of Programming Languages                                              Evolution of Programming Languages, Cont’d
 ! 1940s, early 1950s                          ! Late 1950s                         ! 1960s                              ! 1970s
      " Machine Language                          " High level languages               " APL                                " C
           # Computation can be                   " Fortran                                # Array programming                    # Designed specifically for
             “mechanized”                             # Compiled code can be               # Functional programming                 systems programming
 ! 1950s                                                efficient code                       style                          " Smalltalk
      " Assembly language                         " Cobol                              " PL/1                                     # First “pure” object-
                                                      # Idea of structures/fields          # IBM attempt to combine                 oriented programming
           # Programs should be
             human-readable                                                                  best of Fortran & Cobol        " Prolog
                                                  " Lisp
                                                      # List as the central data       " Simula                                   # First logic programming
                                                        structure                          # Designed for doing                     language
                                                      # Programs as lists                    discrete event simulation      " ML
Here is a language so far ahead of its time,                                               # Introduced object-                   # Functional programming
                                                  " Algol 60
that it was not only an improvement on its                                                   oriented programming
                                                      # Popularized recursion                  concepts
predecessors, but also on nearly all its
successors.                                           # Formal specification of
   - C. A. R. Hoare commenting on Algol 60              language syntax
                                                      # Lexical scoping rules




   Evolution of Programming Languages, Cont’d                                          Classifying Programming Languages
 ! 1980s                                       ! 1990s
      " C++                                       " Programming for the             ! How its implemented
           # Combined C with object                 internet                           " Compiled                        ! Intended domain of use
             oriented programming                 " Java                               " Interpreted                        " General purpose
      " Ada                                           # Secure execution of
           # Designed for systems                       remote code                                                         " Systems programming
               programming                                                          ! Programming paradigm                  " Scripting
           # Developed to use in place
                                               ! 2000s                                 " Procedural programming             " Concurrent/distributed
             of 100s of languages used                                                                                        processes
             by US DoD                            " Security & reliability             " Object-oriented
                                                                                         programming                        " Educational
      " Perl                                      " Programming for multiple
                                                                                       " Functional programming             " Various other domains
           # Developed (late 1980s)                 processors
             for text manipulation                                                     " Logic programming
           # Popularized in 1990s for                                                  " …
             web-site programming
      " Focus on use of modules
        for large scale software
        development




                 Compiled vs. Interpreted                                                     Some Programming Paradigms
 ! Compiled                                                                         ! Procedural programming             ! Functional programming
      " Parse code (typically create an abstract syntax tree)                          " Program can be broken into         " Emphasizes application of
      " Create machine code for entire program                                           procedures (or subroutines           functions
                                                                                         or functions)                      " Avoids state; avoids
 ! Interpreted
                                                                                       " Examples: Fortran, Algol,              mutable data
      " Run each statement as the statement is parsed
                                                                                         Cobol, C, PL/1, Pascal             " Examples: Lisp, Clean, ML,
                                                                                                                              Haskell, Scheme
 ! Examples                                                                         ! Object-oriented
      " Typically compiled: Fortran, Java, C                                          programming                        ! Logic programming
      " Interpreted: Matlab, Python, Logo, some versions of Basic                      " Program is seen as a group         " Based on use of declarative
 ! Advantages/Disadvantages?                                                             of cooperating objects               statements in the language
                                                                                           # Ideas: encapsulation,            of mathematical logic
                                                                                             inheritance, polymorphism
 ! The boundary between compiled and interpreted can be fuzzy                                                               " Example: Prolog, Oz
                                                                                       " Examples: Smalltalk, Java,
      " Java is compiled to produce JBC (Java Byte Code)                                 C++, C#, Python, recent
      " The JBC is then interpreted or JIT compiled                                      Fortran, recent Cobol
              Imperative vs. Declarative                                                             Prolog Example
! Imperative                                                                 sendmore(Digits) :-
                                                                               Digits = [S,E,N,D,M,O,R,Y],   % Create variables
    " Statements tell the computer what to do
                                                                               Digits :: [0..9],       % Associate domains to variables
    " Think “commands” or “recipe”
                                                                               S #\= 0,               % Constraint: S must be different from 0
    " Examples
                                                                               M #\= 0,
        # Java, C, Fortran
                                                                               alldifferent(Digits),  % All elements must take different values


! Declarative                                                                          1000*S + 100*E + 10*N + D   % Other problem constraints
    " Describe what something is like rather than telling how to                      + 1000*M + 100*O + 10*R + E
      create it                                                               #= 10000*M + 1000*O + 100*N + 10*E + Y,
                                                                              labeling(Digits).      % Start the search
    " Examples
        # Functional programming (Haskell)
        # Logic programming (Prolog)
                                                                             (from Wikipedia)




     Languages for Different Domains                                                            Scripting Languages
! General purpose                    ! Concurrent/distributed                ! A script is a sequence of            ! Example scripting languages:
    " Examples: Lisp, Algol, PL/1,     processes                               common commands made into a            Unix shell, Python, Perl,
      Scheme, Java, Python               " Control of multiple threads         single program                         Tcl (Tool command language)
! Systems programming                    " Examples: Ada, Oz, Smalltalk,         " Unix uses shell scripts
    " Emphasis on efficiency and           Java                                  " The shell is the interactive     ! Some Python code:
      tight control of data          ! Educational                                 interface to Unix
      structures                         " Examples: Basic, Haskell,             " You can combine commands         class Stack (object):
    " Examples: C, C++, Forth,             Pascal, Python, Scheme,                 from the Unix shell to create       def __init__ (self):
      Modula-2                             Smalltalk,                              programs                                   self.stack = [ ]
! Scripting                          ! Various other domains                                                           def put (self, item):
                                                                                                                              self.stack.append(item)
    " Examples: Unix shell, Perl,        " Discrete event simulation:        ! A scripting language is usually         def get (self):
      Python, Ruby, Tcl                    Simula                                " Easy to learn                              return self.stack.pop()
                                         " Web scripting: Javascript             " Interpreted instead of              def isEmpty (self):
                                         " Realtime applications: Ada              compiled                                   return len(self.stack) == 0
                                         " Text processing: Snobol
                                         " Printing: Postscript
                                         " …




  A Programming Language Controversy                                                   Just for Fun: An APL Example
! “Go To Statement
  Considered Harmful”
    " Edsger Dijkstra,
      Communications of the
      ACM (March 1968)                                                       ! This is the entire program for a generational update in
                                                                               Conway’s Game of Life
                                     ! Led to concept of structured
! Sparked long-running                                                           "   Live cell & less than 2 live neighbors ⇒ dies of loneliness
                                       programming
  discussion on whether “go              " Idea: Code is clearer if we
                                                                                 "   Live cell & more than 3 neighbors ⇒ dies of overcrowding
  to” is necessary or desirable            restrict ourselves to just a          "   Live cell & 2 or 3 neighbors ⇒ contentment
    " Proponents of “go to”                few control structures                "   Empty cell & exactly 3 neighbors ⇒ birth
      presented examples where           " Loops have single entry, single
      code was more readable               exit
      using “go to”
    " At the time
        # No break
        # No continue
        # No exceptions
     Programming Language Weirdness                                                                            Some Advice
! Weird languages
   " Whitespace
       # Only spaces, tabs, and newlines are significant                                 ! Use the language that best fits your task
       # A great language for security since a program can be printed onto plain paper
         and stored without worrying about an adversary reading the code ☺
   " var'aq                                                                              ! Think small
       # Based on the grammatical structure of the Klingon language
                                                                                            "   Write little programs that test various concepts
! Weird concepts                                                                            "   Test them!
   " Polyglot code                                                                          "   Comment them!
       # Code that is valid for multiple languages                                          "   Build collections of these little programs
       # Usually takes advantage of the different ways that comments are indicated
         in the different languages                                                         "   Reuse your own code
   " Quine
       # A program whose only output is its own source code
       # Not considered valid to use the empty program

				
DOCUMENT INFO
Shared By:
Categories:
Tags:
Stats:
views:6
posted:5/28/2010
language:English
pages:5