1 / 56

Chapter 2: Evaluating Major Programming Languages

CS 35000. Fall 2016. Chapter 2: Evaluating Major Programming Languages. Peter A. Ng CS 35000 Programming Language Design Indiana University – Purdue University Fort Wayne. Outline. Programming Language Domains Procedure-Oriented Languages Script Languages Object-Oriented Languages.

demarcusd
Download Presentation

Chapter 2: Evaluating Major Programming Languages

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CS 35000 Fall 2016 Chapter 2: Evaluating Major Programming Languages Peter A. Ng CS 35000 Programming Language Design Indiana University – Purdue University Fort Wayne

  2. Outline • Programming Language Domains • Procedure-Oriented Languages • Script Languages • Object-Oriented Languages

  3. Procedure-Oriented FORTRAN ALGOL Pascal C COBOL BASIC Script Languages Shell SQL Perltext manipulation, web dev, GUI dev, etc PHP Ruby Object-Oriented Ada Smalltalk C++ Java J2EE AI Languages LISP Prolog JEE is Java Enterprise Edition, consisting of core Java with powerful set of libraries Programming Language Domains • Web App • Javascript • JSPJavaServer Pages • .NET and C# • Mobile App • Object C • J2MEJava 2 Platform, Miro edition • Script Languages • Shell • Perl • PHP • Ruby

  4. We will cover the most important and popular PLs in the course projects http://www.tiobe.com/index.php/content/paperinfo/tpci/index.html

  5. Procedure-Oriented FORTRAN ALGOL Pascal C COBOL BASIC Script Languages Shell SQL Perl PHP Ruby Object-Oriented Ada Smalltalk C++ Java J2EE AI Languages LISP Prolog Programming Language Domains • Web App • Javascript • JSP • .NET and C# • Mobile App • Object C • J2ME • Script Languages • Shell • Perl • PHP • Ruby

  6. Pseudocode– the Preliminary of PL • Pseudocodeis the predecessor of most of the programming languages • It is an alternative to writing outline of a program during the 1940s and 1950s • It cannot be translated into machine language automatically • Must be interpreted by human • Some examples • Shortcode • Speedcoding

  7. IBM 704 and FORTRAN • FORTRAN I (FORmulaTRANslation) • Developed by John Backus at IBM (1954 – 1957) • Designed for the IBM 704, which had index and floating point registers • The design goals of FORTRAN is to eliminate coding errors and the debugging process • Hardware environment of development • Computers were slow and unreliable • Most applications were developed for scientific computational purposes • No standard software development methodology or IDE • How to use machine efficiently was the primary concern

  8. FORTRAN I • Characteristics of FORTRAN I • Names can contain up to sixcharacters • Support Post-testcounting loop (DO)  Similar to “DO… WHILE” • Support Formatted I/O • Support User-defined subprograms • Support 3-way selection statement (arithmetic IF) • Does not support various data types • Variables were floating-point type unless starting with I, J, K, L, M, or N

  9. FORTRAN • The impact of FORTRAN • Compiler released in April 1957 (18 worker-years of effort) • Programs larger than 400 lines rarely compiled correctly • Code execution was very fast • FORTRAN quickly became widely used after that

  10. FORTRAN • FORTRAN II - 1958 • Independent compilation • Longer programs now possible • Many bugs fixed • FORTRAN IV - 1960-62 • Explicit type declarations • Logical IF statement • Subprogram names could be parameters • ANSI standard in 1966

  11. FORTRAN • FORTRAN 77 - 1978 • Character string handling • Logical loop control statement • IF-THEN-ELSE statement • FORTRAN 90 - 1990 • Statements could appear before position 7 • Modules • Dynamic arrays • Pointers • Recursion • CASE statement • Parameter type checking

  12. FORTRAN Examples • Example DO 100 N = 1, 20 <body> 100 CONTINUE • Example IF ( N + 23*M ) 10,20,30 //if negative, zero, positive, goto 10, 20, 30 10 CONTINUE < statements for N+23*M < 0 > GOTO 40 20 CONTINUE < statements for N+23*M = 0 > GOTO 40 30 CONTINUE < statements for N+23*M > 0 > 40 CONTINUE

  13. FORTRAN • FORTRAN Evaluation • Fundamentally changed the way how computer is used • Install gfortranon Ubuntu and run your first Fortran program

  14. Procedure-Oriented FORTRAN ALGOL Pascal C COBOL BASIC Script Languages Shell SQL Perl PHP Ruby Object-Oriented Ada Smalltalk C++ Java J2EE AI Languages LISP Prolog Programming Language Domains • Web App • Javascript • JSP • .NET and C# • Mobile App • Object C • J2ME • Script Languages • Shell • Perl • PHP • Ruby

  15. ALGOL 58 Design • Before ALGOL 58 • All languages were machine-dependent • There is no universal language for implementing various applications • Goals of ALGOL 58: • The statement is close to mathematical notation • It is good at describing algorithms – called algorithmic Language • It can be translatable to machine language • ALGOL’s descendants • C, Pascal, Ada, Simula, CPL

  16. ALGOL 60 & ALGOL 68 • ALGOL 60 • New features: • Block structure (local scope) • Two parameter passing methods • Subprogram recursion • Stack-dynamic arrays • Still no I/O and no string handling • ALGOL 68 • Design is based on the concept of orthogonality • User-defined data structures A few basic types that could be combined in many ways • Dynamic arrays

  17. Names can have any length Type was formalized ALGOL language Example procedureAbsmax(a) Size:(n, m) Result:(y) Subscripts:(i, k); value n, m; array a; integer n, m, i, k; real y; comment The absolute greatest element of the matrix a, of size n by m is transferred to y, and the subscripts of this element to i and k; begin integer p, q; y := 0; i := k := 1; for p:=1 step 1 until n do for q:=1 step 1 until m do if abs(a[p, q]) > y then begin y := abs(a[p, q]); i := p; k := q end end Absmax Array can have any # of dimensions A lot of similarity to C Compound statement Assignment Operator

  18. ALGOL 60 • Successes: • Became the standard way to publish algorithms for over 20 years • Became the standard for most subsequent imperative languages • The 1stmachine-independent language • The 1st language, whose syntax was formally defined b an standard form (Backus Normal Form, namelyBNF) • Failures: • Never widely used, especially in U.S. • Machine dependent I/O (difficult to port) • BNFseemed strange and complicated at the time

  19. ALGOL Descendants • ALGOL had strong influence on subsequent languages, especially Pascal, C, and Ada. For example: • Pascal (1971) • Remarkable combination of simplicity and expressivity • Designed for teaching structured programming • From 1970s to 1990s, it was the most popular language for teaching programming at universities

  20. C (1972) • One of the most widely used programming languages of all time • Designed for systems programming (at Bell Labs by Dennis Richie) • Evolved primarily from B and ALGOL 68 • Initially spread through UNIX • It has a powerful set of operators, but with poor type checking • C choose poor type checking for efficiency purpose • Why type checking is important???

  21. Strong V.S. Weak Type Checking • What are strong and weak type checking? • Strong Type Checking • A language explicitly converts (or casts) types when used • A value has a type and that type cannot change • Weak Type Checking • A language implicitly converts (or casts) types when used • The type of a value depends on how it is used • Efficiency V.S. Reliability VB: int 42 Java script: String “537” var x := 5; // (1) (x is an integer) var y := "37"; // (2) (y is a string) x + y; // (3) (?) Apple script: String “375”

  22. What about C? #include<stdio.h> main() { int x = 5; char y[] = "37"; char* z = x + y; printf("First Name: %s", y); printf("First Name: %s", z); } Run this program and explain why!

  23. Procedure-Oriented FORTRAN ALGOL Pascal C COBOL BASIC Script Languages Shell SQL Perl PHP Ruby Object-Oriented Ada Smalltalk C++ Java J2EE AI Languages LISP Prolog Programming Language Domains • Web App • Javascript • JSP • .NET and C# • Mobile App • Object C • J2ME • Script Languages • Shell • Perl • PHP • Ruby

  24. Procedure-Oriented FORTRAN ALGOL Pascal C COBOL BASIC Script Languages Shell SQL Perl PHP Ruby Object-Oriented Ada Smalltalk C++ Java J2EE AI Languages LISP Prolog Programming Language Domains • Web App • Javascript • JSP • .NET and C# • Mobile App • Object C • J2ME • Script Languages • Shell • Perl • PHP • Ruby

  25. COBOL (COmmon Business-Oriented Language) • First Design Meeting (DoD) - May 1959 • Design goals: • Must look like simple English • Must be easy to use, even if that means it will be less powerful • Must broaden the base of computer users • Must not be biased by current compiler problems • Features: • Names up to 12 characters, with embedded hyphens • English names for arithmetic operators (no arithmetic expressions) • Data and code were completely separate • Verbs were first word in every statement

  26. COBOL Hello World 000100 IDENTIFICATION DIVISION. 000200 PROGRAM-ID. HELLOWORLD. 000300 000400* 000500 ENVIRONMENT DIVISION. 000600 CONFIGURATION SECTION. 000700 SOURCE-COMPUTER. RM-COBOL. 000800 OBJECT-COMPUTER. RM-COBOL. 000900 001000 DATA DIVISION. 001100 FILE SECTION. 001200 100000 PROCEDURE DIVISION. 100100 100200 MAIN-LOGIC SECTION. 100300 BEGIN. 100400 DISPLAY " " LINE 1 POSITION 1 ERASE EOS. 100500 DISPLAY "Hello world!" LINE 15 POSITION 10. 100600 STOP RUN. 100700 MAIN-LOGIC-EXIT. 100800 EXIT. Data and code were completely separate Verbs were first word in every statement

  27. Contributions of COBOL • Contributions: • First macro facility in a high-level language • Hierarchical data structures (records) • Nested selection statements • Long names (up to 30 characters), with hyphens • Separate data division • Still a useful business applications language

  28. Procedure-Oriented FORTRAN ALGOL Pascal C COBOL BASIC Script Languages Shell SQL Perl PHP Ruby Object-Oriented Ada Smalltalk C++ Java J2EE AI Languages LISP Prolog Programming Language Domains • Web App • Javascript • JSP • .NET and C# • Mobile App • Object C • J2ME • Script Languages • Shell • Perl • PHP • Ruby

  29. BASIC (Beginner's All-purpose Symbolic Instruction Code) • A dialect of Fortran and ALGOL 60, which designed in 1964 • Design Goals: • Easy to learn and use for non-science students • Must be “pleasant and friendly” • Fast turnaround for homework • Free and private access • User time is more important than computer time • Current popular dialects: Visual BASIC or VB.NET • First language widely used with time sharing Computers become inexpensive What is it?

  30. Procedure-Oriented FORTRAN ALGOL Pascal C COBOL BASIC Script Languages Shell Perl SQL PHP Ruby Object-Oriented Ada Smalltalk C++ Java J2EE AI Languages LISP Prolog Programming Language Domains • Web App • Javascript • JSP • .NET and C# • Mobile App • Object C • J2ME • Script Languages • Shell • Perl • PHP • Ruby

  31. Shell Script sample.sh • A shell script is a script written for the shell, the command line interpreter of Unix/Linux • Common operation includes: File manipulation, program execution, and printing text. • It has the advantages to use the applications and commands that provided by Unix/Linux operating systems $ vi isnump_n#!/bin/sh## Script to see whether argument is positive or negative#if [ $# -eq 0 ] then echo "$0 : You must give/supply one integers" exit 1fi if test $1 -gt 0 then echo "$1 number is positive"else echo "$1 number is negative"fi :> chmod +x sample.sh :> ./sample.sh -1 :> -1 number is negative

  32. Perl • Its syntax is related to ALGOL and C • It is widely used as a general purpose language • Particularly useful for text processing!!! • Essential Perl: http://cslibrary.stanford.edu/108/EssentialPerl.html helloworld.pl #!/usr/local/bin/perl print "Hello World";

  33. SQL Language • The primary language that specially designed to manipulate data in databases (DB) • Oracle, MySQL, DB2, SQLite, etc…. • It uses simple syntax, such as: • SELECT, FROM, WHERE,… • Although other languages provide API to access DB, the API have to invoke SQL eventually SQL

  34. Scripting Languages for the Web • JavaScript • Used in Web programming (client-side) to create dynamic HTML documents • Related to Java only through similar syntax • PHP • PHP: Hypertext Preprocessor • Used for Web applications (server-side) • Produces HTML code as output • Python • An OO interpreted scripting language • Type checked but dynamically typed • Supports web form processing, cookies, and database access • Python On XP: 7 Minutes To “Hello World!” (http://www.richarddooling.com/index.php/2006/03/14/python-on-xp-7-minutes-to-hello-world/)

  35. Code Snippet Javascript <!DOCTYPE html> <html> <head> <script type="text/javascript"> function displayDate() { document.getElementById("demo").innerHTML=Date(); } </script> </head> <body> <h1>My First Web Page</h1> <p id="demo">This is a paragraph.</p> <button type="button" onclick="displayDate()">Display Date</button> </body> </html> PHP $brush_price = 5; echo "<table border=\"1\" align=\"center\">"; echo "<tr><th>Quantity</th>"; echo "<th>Price</th></tr>"; for ( $counter = 10; $counter <= 100; $counter += 10 ) { echo "<tr><td>"; echo $counter; echo "</td><td>"; echo $brush_price * $counter; echo "</td></tr>"; } echo "</table>";

  36. Procedure-Oriented FORTRAN ALGOL Pascal C COBOL BASIC Script Languages Shell SQL Perl PHP Ruby Object-Oriented Ada Smalltalk C++ Java J2EE AI Languages LISP Prolog Programming Language Domains • Web App • Javascript • JSP • .NET and C# • Mobile App • Object C • J2ME • Script Languages • Shell • Perl • PHP • Ruby

  37. What is Object-oriented programming (OOP) • Object-oriented programming (OOP) is a programming paradigm based on the concept of "objects“ • Objects are data structures that contain • data, in the form of fields, often known as attributes; and • code, in the form of procedures, often known as methods. • A distinguishing feature of objects is that an object's procedures can access and modify the data fields of the object • In object-oriented programming, programs are designed a group of objects that interact with one another. • There is significant diversity in object-oriented programming, but most popular languages are class-based, meaning that objects are instances of classes

  38. Features of OOP Composability -- Structured Design Encapsulation -- Information Hiding Hide complexity from the user of a software of SDK. Protect low-level functionality. Interfaces allow to freely combine modules to produce new systems. Hierarchy Continuity Changes and maintenance in only a few modules does not affect the architecture. Incremental development from small and simple to more complex modules.

  39. Features of OOP (‘Cont) Abstraction -- Understandability Modularization Decompose problem into smaller subproblems that can be solved separately. Terminology of the problem domain is reflected in the software solution. Individual modules are understandable by human readers.

  40. Smalltalk • Developed 1972-1980 at Xerox PARC • Pioneered the graphical user interface • First full implementation of an pure object-oriented language • Data abstraction • Inheritance • Dynamic type binding • Everything is an object • Classes • Methods • Integers • Etc.

  41. C++ • Developed 1980-85 at Bell Labs by Bjarne Stroustrup • Evolved from C, SIMULA 67, and Smalltalk • In cooperate object-oriented programming features to C • It also include exception handling mechanism • No array range checking or garbage collection • It is a complicated language, because it supports both procedural and OO programming

  42. C++ Related languages • Eiffel • Related language that supports OOP • Not directly derived from any other language • Smaller and simpler than C++, but still has most of the power • Delphi (Borland) • Pascal plus some features to support OOP • More elegant and safer than C++

  43. Java • Developed by Sun in early 1990s • Syntax based on C++ and closer to Smalltalk • Significantly simplified, smaller, safer • Does not include struct, union, enum, pointer…, but provide something similar or allow users to define their own • Onlysupports OOP • No pointers is allowed • It support applets and concurrency

  44. Mutex for Concurrency Java Example Class  Object import java.util.ArrayList; import java.util.List; /** * Data structure for a web crawler. Keeps track of the visited sites and keeps a list of sites which needs still to be crawled. * @author AnyiLiu*/ public class CrawledSites { private List<String> crawledSites = new ArrayList<String>(); private List<String> linkedSites = new ArrayList<String>(); public void add(String site) { synchronized (this) { if (!crawledSites.contains(site)) { linkedSites.add(site); } } } /** * Get next site to crawl. Can return null (if nothing to crawl) */ public String next() { if (linkedSites.size() == 0) { return null; } synchronized (this) { // Need to check again if size has changed if (linkedSites.size() > 0) { String s = linkedSites.get(0); linkedSites.remove(0); crawledSites.add(s); return s; } return null; } } } Reference

  45. Java ME and Object C • What is J2EE and how is it different from Java? • Java Standard Edition (AKA. J2SE)  Java, JDBC, JNDI, RMI • Java Enterprise Edition (AKA. J2EE)J2SE+JavaMail, Activation, JAXB, JSE, JMS, Servlets, EJB, etc • Based on Java, but includes a larger set of libraries • Java Micro Edition (AKA J2ME)  mobile app development

  46. J2EE Hiearchy

  47. C# • Part of the Microsoft .NET development platform • Based on C++ and Java • Provides a language for component-based software development • All .NET languages use Common Type System (CTS), which provides a common class library • C#, Visual BASIC.NET, Managed C++, J#.NET, and Jscript.NET

  48. hello, world Java V.S. C# class HelloWorld { public static void main(String[] args) { System.out.println("Hello World"); } } using System; class Hello { static void Main() { Console.WriteLine(“Hello World"); } } C:> javac HelloWorld.java C:> java HelloWorld C:> Hello World C:> cschello.cs C:> hello.exe C:> Hello World

  49. Procedure-Oriented FORTRAN ALGOL Pascal C COBOL BASIC Script Languages Shell SQL Perl PHP Ruby Object-Oriented Ada Smalltalk C++ Java J2EE AI Languages LISP Prolog Programming Language Domains • Web App • Javascript • JSP • .NET and C# • Mobile App • Object C • J2ME • Script Languages • Shell • Perl • PHP • Ruby

  50. LISP (LISt Processing language) • Designed by John McCarthy of MIT in 1958 • AI research needed a language that . . . • Could process data in lists , rather than arrays • Supported symboliccomputation, rather than numeric • Only two basic data types • Atoms • Lists • Dialects are still used, such as : • Common Lisp • Scheme (print "Hello world")

More Related