What is programming language? � Translator between you, the programmer and CSCI: 4500/6500 Programming the computer’s native language � Computer’s native language: Languages » Computer is on/off switches that tells the computer what to do. – 01111011 01111011 01111011 Motivation � How? » Assemblers, compilers and interpreters � Like English each programming language has its own grammar and syntax (more details week 2) 1 2 Maria Hybinette, UGA Maria Hybinette, UGA Why are there so many Language Definition programming languages? � Syntax » Similar to the grammar of a natural language � Evolution: We learn better ways of doing things » Most languages defined uses a context free grammar (Chomsky’s type over time 2 grammar, can be described by non-deterministic PDA): – Production rules: A � � , where A is a single non terminal and � is string � Application Domains: Different languages are of terminals and non terminals (rl more restrictive � � { � , aA, a } ) good for different application domains with – Example: the language of properly matched parenthesis is generated by different needs that often conflict (next slide) the grammar: S � | SS | (S) | � – <if-statement> ::= if (<expression>) <statement> [else <statement>] » Special purpose: Hardware and/or Software � Semantics � Socio-Economical: Proprietary interests, » What does the program “mean”? commercial advantage » Description of an if-statement [K&R 1988]: – An if-statement is executed by first evaluating its expression, which must have � Personal Preferences: For example, some arithmetic or pointer type, including all side-effects, and if it compares unequal to prefer recursive thinking other iterative thinking 0, the statement following the expression is executed. If there is an else part, and the expression is 0, the statement following the else is executed. 3 4 Maria Hybinette, UGA Maria Hybinette, UGA What makes a language Some Application Domains successful? � Expressiveness: Easy to express things, easy use � Scientific computing: Large number of floating point once fluent, "powerful” (C, Common Lisp, APL, Algol- computations (e.g. Fortran) 68, Perl) � Business applications: Produce reports, use decimal � Learning curve: Easy to learn (BASIC, Pascal, LOGO, numbers and characters (e.g. COBOL) Scheme) � Artificial intelligence: Symbols rather than numbers � Implementation: Easy to implement (BASIC, Forth) manipulated (e. g. LISP) � Efficient: Possible to compile to very good (fast/small) � Systems programming: Need efficiency because of code (Fortran) continuous use, low-level access (e.g. C) � Sponsorship: Backing of a powerful sponsor (COBOL, � Web Software: Eclectic collection of languages: PL/1, Ada, Visual Basic) markup (e.g., XHTML-- not a programming language), � Cost: Wide dissemination at minimal cost (Pascal, scripting (e.g., PHP), general-purpose (e.g., Java) Turing, Java) � Academic: Pascal, BASIC 5 6 Maria Hybinette, UGA Maria Hybinette, UGA
Why study programming language concepts? What makes a good language? No universal accepted metric for design. � One School of thought of Linguists: The “Art “ of designing programming languages » Language shapes the way we thing and determines what we can think about [Whorf-Sapir Hypothesis 1956] Look at characteristics and see how they affect the » Programmers only skilled in one language may not have a deep understanding of concepts of other languages, criteria below[Sebesta]: whereas and who is multi-lingual can solve problems in many different ways. � Readability: the ease with which programs can be read and understood � Help you choose appropriate languages for different � Writability: the ease with which a language can be application domains used to create programs � Increased ability to learn new languages » Concepts have more similarities, � Reliability: conformance to specifications (i.e., � Easier to express ideas performs to its specifications) � Help you make better use of whatever language you use � Cost: the ultimate total cost (includes efficiency) 7 8 Maria Hybinette, UGA Maria Hybinette, UGA Characteristics Compactness (Raymond) � Simplicity: � Compact: Fits inside a human head » Modularity, Compactness » Test: Does an experienced user normally need a (encapsulation, abstraction) manual? » Orthogonality » Not the same as weak (can be powerful and flexible) � Expressivity » Not the same as easily learned – Example: Lisp has a tricky model to learn then it � Syntax becomes simple � Control Structures » Not the same as small either (may be predictable and obvious to an experienced user with many � Data types & Structures pieces) � Type checking � Semi-compact: Need a reference or cheat Hatton 97 (Raymond’s The Art sheet card of Unix Programming) � Exception handling 9 10 Maria Hybinette, UGA Maria Hybinette, UGA Compactness Orthogonality � Mathematically means: ”Involving right angles” � The Magical Number Seven, Plus or Minus Two: Some � Computing: Operations/Instructions do not have side Limits on Our Capacity for Processing Information effects; each action changes just one thing without [Miller 1956] affecting others. » Does a programmer have to remember more than seven � Small set of primitive constructs can be combined in a entry points? Anything larger than this is unlikely to be strictly compact. relatively small number of ways (every possible combination is legal) � C & Python are semi-compact � Example monitor controls: � Perl, Java and shells are not (especially since serious shell programming requires you to know half-a-dozen » Brightness changed independently of the contrast level, other tools like sed(1) and awk(1)). colorbalance independently of both. � Don’t repeat yourself rule: Every piece of knowledge must � C++ is anti-compact -- the language's designer has have a single , unambiguous, authoritative representation admitted that he doesn't expect any one programmer within a system, or as Kernighan calls this: the Single Point to ever understand it all. Of Truth or SPOT rule. � Easier to re-use 11 12 Maria Hybinette, UGA Maria Hybinette, UGA
Affects Readability Criteria Simplicity x � Overall simplicity Readability Writability Reliability » Compactness Control Structures x » Few “feature multiplicity” (c+=1, c++) Data types & x Simplicity: Modular, x x x Structures – (means of doing the same operation) Compact & Orthogonal Syntax Design x » Minimal operator overloading x x x Control Structures Support Abstraction � Orthogonality Data types & Structures x x x Expressivity � Syntax considerations Syntax Design x x x » Special words for compounds (e.g. end if .) Type Checking Support Abstraction x x » Identifier forms (short forms of Fortran example) Exception Handling Expressivity x x � Control statements Restrictive Aliasing Type Checking x » Data structures facilities (true/1) x Exception Handling » Control structures ( while vs goto example next… x Restrictive Aliasing 13 14 Maria Hybinette, UGA Maria Hybinette, UGA while vs goto Affect Writability � Simplicity and orthogonality while ( incr < 20 ) loop 1: Simplicity x { if ( incr >= 20 ) » Few constructs, a small number of while ( sum <= 100 ) Orthogonality goto out; primitives, a small set of rules for { loop 2: Control Structures x combining them sum += incr; if ( sum > 100 ) } � Support for abstraction Data types & x goto next; incr++; sum += incr; Structures » The ability to define and use complex } goto loop 2; Syntax Design x structures or operations in ways that next: allow details to be ignored Support x incr++; Abstraction goto loop 1; � Comparison of a nested loop � Expressivity out: versus doing the same task in a Expressivity x » A set of relatively convenient ways of language without adequate control specifying operations Type Checking statements. » Example: the inclusion of for Exception � Which is more readable? Handling statement in many modern languages Restrictive Aliasing 15 16 Maria Hybinette, UGA Maria Hybinette, UGA Affects Reliability Affects Cost � Type checking Simplicity x � Training programmers to use language » Testing for type errors Orthogonality � Writing programs (closeness to particular � Exception handling Control Structures x applications) » Intercept run-time errors and take Data types & x corrective measures Structures � Compiling programs � Aliasing Syntax Design x � Executing programs » Presence of two or more distinct Support Abstraction x referencing methods for the same � Language implementation system: availability memory location Expressivity x � Readability and writability of free compilers Type Checking x » A language that does not support Exception Handling � Reliability: poor reliability leads to high costs x “natural” ways of expressing an algorithm will necessarily use Restrictive Aliasing x � Maintaining programs “unnatural” approaches, and hence reduced reliability 17 18 Maria Hybinette, UGA Maria Hybinette, UGA
Recommend
More recommend