Full Transcript

CSCI-325: Programming Languages Preliminaries What Is This Class About? Studying the design choices and issues of the various language constructs: Syntax and Semantics Analysis Computability Theory Grammers What Are Some Similarities & Differences Between… Java and Python J...

CSCI-325: Programming Languages Preliminaries What Is This Class About? Studying the design choices and issues of the various language constructs: Syntax and Semantics Analysis Computability Theory Grammers What Are Some Similarities & Differences Between… Java and Python Java and C++ Python and R Java and JavaScript Other languages you are familiar with Reasons for Studying Programming Language Concepts Why should we study programming languages? ○ increased ability to express ideas ○ improved background for choosing appropriate languages ○ increased ability to learn new languages ○ better understanding the significance of implementation ○ better understanding of computation What are Computer Programs Used For? What are Computer Programs Used For? Scientific Applications (Fortran) ○ need simple data structures but large floating point computations; arrays Business Applications (COBOL) ○ produce elaborate reports (decimal numbers & characters) Artificial Intelligence (LISP, Prolog, Python, R) ○ Symbols manipulated, Linked Lists used Systems Programming (C) ○ need efficiency Web Software (Java) ○ uses a collection of languages: markup (HTML, which is NOT a programming language), scripting (PHP) ○ general purpose How Are Programming Languages Evaluated? Readability: how easy it is for a program to be read and understood in the language Writability: how easy it is to create a program in the language Reliability: how well a program in the language performs to its specifications under a variety of conditions Cost: the total cost of the language Readability Overall Simplicity ○ manageable number of features and constructs ○ minimal feature multiplicity ○ assembly language – so simple it’s less readable Readability Overall Simplicity Orthogonality: a relatively small set of primitive constructs can be combined in a relatively small number of ways ○ the more orthogonal the design, the fewer exceptions needed Readability Overall Simplicity Orthogonality Data Types ○ adequate, pre-defined data types Readability Overall Simplicity Orthogonality Data Types Syntax Considerations ○ special words and methods of forming compound statements ○ self-descriptive constructs, meaningful keywords Writability Simplicity and Orthogonality ○ Few constructs, few primitives, small number of rules for combining them Support for Abstraction ○ The ability to define and use complex structures or operations in ways that allow details to be ignored Expressivity ○ A set of relatively convenient ways of specifying operations ○ Strength and number of operators and predefined functions Reliability Type Checking ○ Testing for type errors at compile time or run-time ex– C does not check if for Array Out Of Bounds, Java does Exception Handling ○ Intercept run-time errors and take corrective measures Aliasing ○ Presence of two or more distinct referencing methods for the same memory location (generally accepted as dangerous) Readability & Reliability ○ A language that does not support natural ways of expressing an algorithm will require the use of unnatural approaches which reduces reliability Cost Training programmers to use the language Writing, Compiling, and Executing programs ○ time & money Language Implementation Systems: free compilers? Reliability: poor reliability leads to high cost ○ If software at a nuclear power plant fails, extremely high cost Maintaining programs ○ SOFTWARE MAINTAINABILITY IS INCREDIBLY IMPORTANT maintenance costs are 2-4x higher than development costs Other Evaluation Criteria Portability ○ the ease with which programs can be moved from one implementation to another Generality ○ the applicability to a wide range of applications ○ Python does a lot of data stuff, C is great for OSs, PHP is great for dynamic web- page content Well-definedness ○ The completeness and precision of the language’s official definition Influences on Language Design Computer Architecture ○ Languages are developed around the prevalent computer architecture – the von Neumann architecture Program Design Methodologies ○ New software development methodologies (object-oriented software development) leads to new programming paradigms and new programming languages von Neumann Architecture data & programs are stored in same memory CPU (executes instructions) is separate from memory instructions & data are piped from memory to CPU results from CPU must be piped back to memory Computer Architecture Influences Most popular languages are based around the von Neumann architecture– called imperative languages. central features: ○ variables – model memory cells ○ assignment statements – based on piping ○ iterative repetition – most efficient repetition for this architecture Execution of machine code program on this architecture occurs in a process called the fetch-execute cycle Fetch-Execute Cycle Each instruction to be executed must be moved from memory to the CPU The address of the next instruction is stored in a register called the program counter initialize the program counter repeat forever fetch the instruction pointed by the counter increment the counter decode the instruction execute the instruction end repeat Programming Methodologies Influences 1950s and 1960s: Simple applications (satelite tracking), worry about machine efficiency Late 1960s: People efficiency became important (readability, better control structures, etc.) Late 1970s: Process-oriented to data-oriented ○ data abstraction – abstrac data types to solve problems Mid-1980s: Object-oreinted programming ○ Data Abstractions & Inheritance & Polymorphism Language Categories Imperative Languages (C, Perl, JavaScript) ○ Central features: variables, assignment statements, iteration ○ Include Object-Oriented (Python, C++, Java) Functional Languages (LISP, Scheme, F#) ○ Main means of making computations is by applying functions to given parameters Logic Languages (Prolog) ○ Rule based language (rules specified in no particular order) ○ Implementation specifies order Markup / Programming Hybrid Languages (HTML) ○ Markup languages (which are not programming lanugages) extended to support some programming Language / Design Tradeoffs Reliability vs Cost of Execution ○ Example: Java demands all references to array elements be checked for proper indexing, C does not Readability vs Writability ○ APL provides many powerful operators which allows for complex computations to be written compactly ○ Mathematical Beauty? Writability vs Reliability ○ C++ pointers are very flexible but can be dangerous Implementation Methods Compilation ○ Program translated into machine language, which is executed directly on the computer Pure Interpretation ○ Program interpreted by another program (the interpreter) ○ Interpreter acts as a software simulation of a machine whose fetch-execute cycle deals with high-level language program statements Hybrid ○ Translate high-level language programs to an intermediate language designed to allow easy interpretation Compilation Translate high-level program (source language) into machine code (machine language) Slow translation, fast execution Process: ○ lexical analysis: converts characters in source program into lexical units ○ syntax analysis: transforms lexical units into parse trees which represent the syntactic structure of the program ○ semantic analysis: generate intermediate code ○ code generation: generate machine code Compilation Process Pure Interpretation No translation Easier implementation of programs ○ run-time errors easily and immediately displayed Slower execution (10-100x slower than compiled programs) Often requires more space Pure Interpretation Process Hybrid A high-level program is translated to an intermediate language that allows for easy interpretation Faster than pure interpretation Initial Java Virtual Machine (JVM) made up a hybrid system ○ contained a byte code (the intermediate form) interpreter and a run-time system ○ Now, Java systems translate byte code into machine code Hybrid Implementation Process Just-In-Time Implementation Systems Widely used for Java programs Initially translate programs to an intermediate language Then compile intermediate language of the subprograms into machine code when they are called Machine code version is kept for subsequent calls Preprocessors A preprocessor is a program that processes another program just before that program is compiled Commonly used to specify that code from another file is to be included from sklearn.preprocessing import train_test_split import math import java.util.Scanner Programming Environments A collection of tools used in the development of software ○ file system, text editor, linker, compiler ○ large collection of integrated tools accessed through a uniform UI UNIX – an older programming environment built around a portable multiprogramming operating system ○ originally was missing a uniform interface ○ now, GUIs make the interface appear similar to windows or mac Tiobe Index Measure of popularity of programming languages Rank calculate from the # of search engine results for queries containing language name ○ Google, Google Blogs, MSN, Yahoo!, Baidu, Wikipedia, YouTube https://www.tiobe.com/tiobe-index/ Discussion How much do our language skills impact our ability for abstract thought? What common programming language statement is most detrimental to readability? Compare and contrast C with Python: ○ Which has more readability? Why? ○ Which has more writability? Why? What kind of programming environments have you used? Which have you liked? Why?

Use Quizgecko on...
Browser
Browser