COS 301 Programming Languages
Total Page:16
File Type:pdf, Size:1020Kb
COS 301 Topics Programming Languages • Reasons for Studying Concepts of Programming Languages • Programming Domains Preliminaries • Language Evaluation Criteria • Influences on Language Design • Language Categories • Language Design Trade-Offs • Implementation Methods • Programming Environments Why Study Concepts of Programming Why Study Concepts of Programming Languages? Languages? • Increased ability to express ideas • To improve expressiveness • Improved background for choosing appropriate – Expressiveness increases with vocabulary languages – Ability to visualize solutions increases with new programming constructs and depth of abstraction • Increased ability to learn new languages – If the only tool you know is a hammer, the only • Better understanding of significance of solutions you can see involve nails implementation – Even if a language does not directly support a • Better use of languages that are already particular abstract feature (e.g. associative array) known you can simulate it as part of solution • Overall advancement of computing Gain improved background for choosing Improve your ability to learn new appropriate languages languages • A fundamental result of theory is that all • First language or two are difficult and time- languages are equivalent in computing power consuming to learn • Anything that can be computed in Java or • These languages also constrict your view of Python can also be computed in BASIC, COBOL or languages – As you learn the abstract concepts underlying FORTRAN programming languages you acquire a framework for – But some languages are better in terms of understanding a new language expressiveness for a given problem – Eventually you can read many unfamiliar languages – Learning just one or two languages in great depth can with little or minimal effort be hazardous to your career – Current trend is to combine relatively simple language with a huge library. Why re-invent the • Let’s consider some problems… wheel? The Tiobe Index Gain a better understanding of significance of implementation • See • Programming languages provide a virtual http://www.tiobe.com/index.php/content/pap machine with which we express problems and erinfo/tpci/index.html their solutions. • Counts top languages by counting hits of the • The virtual machine has to execute on a real one most popular search engines • Understanding the implementation of a • See programming language helps to http://www.tiobe.com/index.php/content/pap – Achieve more efficient problem solutions erinfo/tpci/tpci_definition.htm – Avoid subtle bugs caused by particular language implementations Gain better use of current languages Programming Paradigms • As languages evolve, they become large and • A programming paradigm is a pattern of complex compared to earlier languages problem-solving thought that underlies a • Many modern languages are multi-paradigm particular genre of programs and languages. languages – procedural, functional, object • Many people classify languages into four main oriented paradigms: • A broad understanding of concepts and – Imperative (Procedural) paradigms allows you to better leverage your – Object-oriented knowledge of current languages – Functional – Logic (declarative) Imperative or Procedural Paradigm A Von Neumann Computer • The oldest programming model • Follows the classic von Neumann-Eckert model: – Program and data are indistinguishable in memory – Program = a sequence of commands – State = values of all variables when program runs • Large programs use procedural abstraction • Language has assignments, loops, conditionals, procedure and functional calls, control flow • Example imperative languages: • Cobol, Fortran, C, Ada, Perl, … Object Oriented (OO) Paradigm Functional Paradigm • An OO Program is a collection of objects that interact by • Functional programming models a computation as a passing messages that transform the state. collection of mathematical functions. • Concepts of OOP: – Input = domain – Sending Messages – Output = range – Inheritance • Functional languages are characterized by: – Polymorphism – Functional composition • Example OO languages: – Recursion – Smalltalk, Java, C++, C#, and Python – Conditional evaluation • We will look at Smalltalk in detail later. Languages such • Example functional languages: as Java and C++ are OOP concepts grafted onto a – Lisp, Scheme, ML, Haskell, … procedural core – Surprisingly Javascript supports functional programming very well! Logic Paradigm Declarative Languages • Logic programming declares what outcome the • Prolog is a unique language with its basic ideas program should accomplish, rather than how it of facts, rules and atoms combined into a should be accomplished. program often called a database • When studying logic programming we see: • There are other declarative languages where a “program” consists only of statements declaring – Programs as sets of constraints on a problem what the result should be, not how to do it – Programs that achieve all possible solutions • SQL (Structured Query Language) is the prime – Programs that are nondeterministic example • Example logic programming languages: – But all SQL implementations have procedural – Prolog extensions (PL/SQL, T-SQL, etc.) • XPath is another example Markup Hybrid Languages Markup Hybrids • Pure markup languages are mostly based on • XSLT (Extensible Stylesheet Language Standardized General Markup Language (SGML) Transformations) is a declarative XML based • HTML and XML are examples of two pure markup language used for transforming from XML to XML languages • Often used to transform XML documents into – No processing is done by the language HTML (a subset of XML) for presentation in – Markup provides directions to an external tool browsers • But markup languages have been extended to • Requires a processing engine that takes XML and support some programming XSLT as input and outputs XML (or HTML) • Examples: JSTL, XSLT • Capabilities overlap XQuery Programming Domains Programming Domains • Scientific applications • Computer software operates in a large number of – Large numbers of floating point computations; use of arrays different domains – Fortran – Scientific applications • Business applications – Business applications – Produce reports, use decimal numbers and characters – Artificial intelligence – COBOL – Systems programming • Artificial intelligence – The Internet – Symbols rather than numbers manipulated; use of linked lists – LISP – Multimedia • Systems programming – Embedded Systems – Need efficiency because of continuous use – Industrial Control – C • Some programming languages have been designed • Web Software for specific domains – Eclectic collection of languages: markup (e.g., XHTML), scripting (e.g., PHP), general-purpose (e.g., Java) • Others were explicitly design as general purpose Scientific Applications Scientific Applications • AKA Number Crunching. The first computer • Earliest high-level languages (FORTRAN, from applications (1940’s) FORmula TRANslation) were designed for • Normally involve simple data structures, simple scientific computing control structures and large numbers of floating • Efficiency is primary concern -- competition point computations with assembler • Abstraction is usually applied OUTSIDE the • Algol 60 was designed to provide better language before the computational problem is expressiveness and abstraction but failed to expressed in a language catch on • FORTRAN is still very much in use – only recently has C begun to be adopted in the domain Business Applications COBOL • Early 1950’s people realized that computers • More lines of COBOL are in existence and still were very good at doing tedious and boring tasks running than any other computer language • Computers were specifically designed for • If you want job security learn COBOL – there’s business (high I/O capabilities) as were always demand for people who can maintain the languages COBOL corpus • COBOL (COmmon Business Oriented Language) • Other developments in business applications are was first designed in 1959 (based on Grace of little interest to computer science; e.g., RPG Hopper’s Flow-Matic language) (Report Program Generator) • In 2002 object-oriented extensions were grafted • Not discussed much in text onto the language Database Management Systems (DBMS) and DBMS Languages associated languages • Usually neglected in programming language texts • DBMS programming languages are no different – A DBMS is a storage system and programming from other programming languages with the environment designed for optimal, error-free and exception that they operate against, and are efficient storage and retrieval of data tightly bound to, a persistent store of data – The “back end” of both business and scientific systems • Most well known are the relational DBMS, all of which support Structured Query Language (SQL) • Many interesting OO languages and DBMS are evolving SQL Artificial Intelligence (AI) • SQL is a “non-procedural language” • Characterized by symbolic rather than numeric – You say what you want rather than expressing an manipulation of data algorithm and hoping that the results are what you want • Goals include mimicking of human intelligence – In practice it not possible to express everything as a and design of systems that can perform well in query, so all DBMS support procedural extensions to areas that humans perform well SQL • List structures seem lend to themselves well to • Other language families are associated with expressiveness in this area other storage systems