chapter 1

Upload: harvey-james-chua

Post on 01-Mar-2016

212 views

Category:

Documents


0 download

DESCRIPTION

Language Design

TRANSCRIPT

  • Programming Language DesignChapter 1CS 350 Programming Language DesignIndiana University Purdue University Fort Wayne

  • Chapter 1: PreliminariesReasons for Studying Programming LanguagesProgramming DomainsLanguage Evaluation CriteriaInfluences on Language DesignLanguage CategoriesLanguage Design Trade-OffsImplementation MethodsProgramming Environments

  • Reasons for Studying Programming LanguagesThe expressive power of the language we use to communicate influences the depth at which we can thinkIt is difficult to conceptualize structures you cannot describeConsider implementing a complex application in assembly language without knowledge of subprograms or object-oriented programming?with that knowledge?

  • Reasons for Studying Programming LanguagesAbility to choose the best language for the problemPopular languages used today are far from idealIs a cheap compiler a good reason for choosing a language?Is programmer familiarity with a related language a good reason for choosing a language?Foundation for learning new languages

  • Reasons for Studying Programming LanguagesUnderstanding of runtime and implementation issuesRelative efficiency of alternative constructsCommon bugsProper use of a languageOverall advancement of computing

  • Programming DomainsScientific applicationsLarge number of floating point computationsExamples: Mathematica and MapleBusiness applicationsProduce reportsUse decimal numbers and charactersCOBOL

  • Programming DomainsArtificial intelligenceSymbols rather than numbers are typically manipulatedFirst AI language was LISP McCarthyProlog Clocksin and MellishSystems programmingNeed for efficiency because of continuous useLow-level features for interfaces to external devicesC

  • Programming DomainsWeb softwareMarkup languagesSuch as XHTMLScripting languagesA list of commands is placed in a file or in XHTML document for executionPerl, JavaScript, PHPSpecial-purpose languagesRPG business reportsAPT programmable machine toolsGPSS simulation

  • Language Evaluation CriteriaReadabilityWritabilityReliabilityCostOther

  • Language Evaluation CriteriaReadabilityVery importantMaintenance can be 70 90% of system lifecycle costOverall simplicityToo many features are badMultiplicity of features is badAre you confused by Java I/O choices?

  • Language Evaluation CriteriaReadabilityOrthogonalityA relatively small set of primitive constructs that can be combined in a relatively small number of waysConsistent set of rules for combining constructs (simplicity)Every possible combination is legalMakes the language easy to learn and read Meaning is context independentVAX assembly language and Ada are good examplesLack of orthogonality leads to exceptions to rulesC is littered with special casesE.g. - structs can be returned from functions but arrays cannot

  • Language Evaluation CriteriaReadabilityUseful control statementsAbility to define data types and structuresSyntax considerationsProvision for descriptive identifiers BASIC once allowed only identifiers to consist of one character with an optional digitMeaningful reserved wordsMeaning should flow from appearance

  • Language Evaluation CriteriaWritabilityMost readability factors also apply to writabilitySimplicity and orthogonalityControl statements, data types and structuresSupport for abstractionData abstractionProcess abstractionExpressivityIt is easy to express program ideas in the languageAPL is a good example

  • Language Evaluation CriteriaReliabilityType checkingFamous failure of space shuttle experiment due to int / float mix-up in parameter passingException handlingAbility to intercept run-time errorsAliasingAbility to use different names to reference the same memoryA dangerous featureReadability and writability both influence reliability

  • Language Evaluation CriteriaCostTraining programmers to use languageWriting programs in a particular problem domainCompiling programsExecuting programsLanguage implementation system (free?)Reliability Maintaining programsOthers: portability, generality, well-definedness

  • Von Neumann computer architecture

  • Influences on Language DesignWe use imperative languages, at least in part, because we use von Neumann machinesData and programs stored in same memoryMemory is separate from CPUInstructions and data are piped from memory to CPUBasis for imperative languagesVariables model memory cellsAssignment statements model pipingIteration is the most efficient way to implement repetition

  • Influences on Language DesignProgramming methodologies1950s and early 1960sSimple applicationsOverriding concern about machine efficiencyLate 1960sPeople efficiency became importantReadabilityBetter control structuresStructured programmingTop-down design and step-wise refinement

  • Influences on Language DesignProgramming methodologiesLate 1970sProcess-oriented techniques yielded to data-oriented techniquesData abstractionMiddle 1980s to presentObject-oriented programmingEncapsulation with data abstractionInheritanceDynamic method bindingSmalltalk and JavaConcurrent programming and parallelismCreating and controlling concurrent program units

  • Language CategoriesImperativeCentral featuresVariablesAssignment statementsIterationAlgorithm specified in detail with a specific order of execution for statementsC, Pascal, Visual BASIC.NETFunctionalMain means of making computations is by applying functions to given parametersNo variablesNo loopingLISP, Scheme

  • Language CategoriesLogicRule-basedRules are specified in no special orderLanguage system chooses execution order that produces the desired resultPrologObject-orientedEncapsulate data objects with processingInheritance and dynamic type bindingGrew out of imperative languagesSmalltalk, C++, Java

  • Language Design Trade-OffsDesigning a programming language involves an number of compromises and trade-offsReliability vs. cost of executionRange checking for array references?Readability vs. writabilityThe APL language traded readability for writabilityWritability vs. reliabilityPascal variant records are flexible but not safeC++ pointers are flexible but not safe

  • Layered View of Computer

  • Implementation MethodsCompilationTranslates a high-level program to machine codeSlow translationFast executionSeparate compilation units must be combined by a linker into an executable image(.exe file)

  • Implementation MethodsPure interpretationNo translation before executionSlow executionLoop statements are repeatedly translatedBecoming rare except for web scripting languagesJavaScriptPHP

  • Implementation MethodsHybrid implementation systemsTranslates a high-level language to intermediate codeEach statement is translated only once in contrast to pure interpretationMedium execution speedSmalltalk and JavaIntermediate code is called bytecodeThe interpreter is the JVMJIT technology now widely used with Java and .NET

  • Programming EnvironmentsThe collection of tools used in software developmentFile system, text editor, compiler, linkerBorland JBuilderAn integrated development environment for JavaMicrosoft Visual Studio.NETA large, complex visual environmentUsed to program in C#, Visual BASIC.NET, Jscript, J#, and C++