Download Principles of Programming Languages - 815338A

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Java performance wikipedia , lookup

Falcon (programming language) wikipedia , lookup

Parsing wikipedia , lookup

Functional programming wikipedia , lookup

Reactive programming wikipedia , lookup

Program optimization wikipedia , lookup

ILLIAC IV wikipedia , lookup

History of compiler construction wikipedia , lookup

Compiler wikipedia , lookup

Go (programming language) wikipedia , lookup

Programming language wikipedia , lookup

Object-oriented programming wikipedia , lookup

Structured programming wikipedia , lookup

Abstraction (computer science) wikipedia , lookup

Assembly language wikipedia , lookup

C Sharp (programming language) wikipedia , lookup

Interpreter (computing) wikipedia , lookup

Transcript
PrinciplesofProgramming
Languages- 815338A
Sandun Dasanayake – sandun.dasanayake(at)oulu.fi
Costs
• Trainingprogrammerstousethelanguage
• Writingprograms(closenesstoparticularapplications)
• Compilingprograms
• Executingprograms
• Languageimplementationsystem:availabilityoffreecompilers
• Reliability:poorreliabilityleadstohighcosts
• Maintainingprograms
LanguageDesignTrade-offs
• ReliabilityvsCost
• Moreresourcesrequirestoensurereliability
• Thedevelopershavetomakeadecisionatsomepoint.
• Example:Typechecking
• InC,theindexrangesofarraysarenotchecked,Soexecutesfast,butitnotsoreliable
• Ontheotherhand,Javachecksallreferencestoarrayelements,Javaexecutesslower,butismore
reliable
• Readabilityvs.writability
• Example:APL
• APLprovidesmanypowerfuloperators(andalargenumberofnewsymbols),allowing
complexcomputationstobewritteninacompactprogrambutatthecostofpoorreadability
• Writability (flexibility)vs.reliability
• Example:C++pointers
• Theyarepowerfulandveryflexiblebutareunreliable
OtherFactors
• Portability
• Theeasewithwhichprogramscanbemovedfromoneimplementationto
another
• Generality
• Theapplicabilitytoawiderangeofapplications
• Well-definedness
• Thecompletenessandprecisionofthelanguage’sofficialdefinition
InfluenceonLanguageDesign
• ComputerArchitecture
• Languagesaredevelopedaroundtheprevalentcomputerarchitecture,
knownasthevonNeumannarchitecture
• ProgramDesignMethodologies
• Newsoftwaredevelopmentmethodologies(e.g.,object-orientedsoftware
development)ledtonewprogrammingparadigmsandbyextension,new
programminglanguages
ComputerArchitecture
• Well-knowncomputerarchitecture:Von
Neumann
• Imperativelanguages,mostdominant,because
ofvonNeumanncomputers
•
•
•
•
Dataandprogramsstoredinmemory
MemoryisseparatefromCPU
InstructionsanddataarepipedfrommemorytoCPU
Basisforimperativelanguages
• Variablesmodelmemorycells
• Assignmentstatementsmodelpiping
• Iterationisefficient
Imagesource:https://goo.gl/rZn4yl
VonNeumannArchitecture
ProgrammingDesignMethodologies
• 1950sandearly1960s:Simpleapplications;worryaboutmachineefficiency
• Late1960s:Peopleefficiencybecameimportant;readability,bettercontrol
structures
• Structuredprogramming
• Top-downdesignandstep-wiserefinement
• Late1970s:Process-orientedtodata-oriented
• Dataabstraction
• Middle1980s:Object-orientedprogramming
• Dataabstraction+inheritance+polymorphism
LanguageCategories
• Imperative
•
•
•
•
•
Centralfeaturesarevariables,assignmentstatements,anditeration
Includelanguagesthatsupportobject-orientedprogramming
Includescriptinglanguages
Includethevisuallanguages
Examples:C,Java,Perl,JavaScript,VisualBASIC.NET,C++
• Functional
• Mainmeansofmakingcomputationsisbyapplyingfunctionstogivenparameters
• Examples:LISP,Scheme,ML,F#
• Logic
• Rule-based(rulesarespecifiedinnoparticularorder)
• Example:Prolog
• Markup/programminghybrid
• Markuplanguagesextendedtosupportsomeprogramming
• Examples:JSTL,XSLT
ImplementationMethods
• Compilation
• Programsaretranslatedintomachinelanguage;includesJITsystems
• Use:Largecommercialapplications
• PureInterpretation
• Programsareinterpretedbyanotherprogramknownasaninterpreter
• Use:Smallprogramsorwhenefficiencyisnotanissue
• HybridImplementationSystems
• Acompromisebetweencompilersandpureinterpreters
• Use:Smallandmediumsystemswhenefficiencyisnotthefirstconcern
LayeredViewofComputer
The operating system and
language implementation are
layered over machine interface
of a computer
Compilation
• Translatehigh-levelprogram(sourcelanguage)intomachinecode(machine
language)
• Slowtranslation,fastexecution
• Compilationprocesshasseveralphases:
• lexicalanalysis:convertscharactersinthesourceprogramintolexicalunits
• syntaxanalysis:transformslexicalunitsintoparsetreeswhichrepresentthesyntactic
structureofprogram
• Semanticsanalysis:generateintermediatecode
• codegeneration:machinecodeisgenerated
TheCompilationProcess
VonNeumannBottleneck
• Connectionspeedbetweenacomputer’smemoryanditsprocessor
determinesthespeedofacomputer
• Programinstructionsoftencanbeexecutedmuchfasterthanthe
speedoftheconnection;theconnectionspeedthusresultsina
bottleneck
• KnownasthevonNeumannbottleneck;itistheprimarylimiting
factorinthespeedofcomputers
PureInterpretation
• Notranslation
• Easierimplementationofprograms(run-timeerrorscaneasilyand
immediatelybedisplayed)
• Slowerexecution(10to100timesslowerthancompiledprograms)
• Oftenrequiresmorespace
• Nowrarefortraditionalhigh-levellanguages
• SignificantcomebackwithsomeWebscriptinglanguages(e.g.,
JavaScript,PHP)
PureInterpretationProcess
HybridImplementationSystems
• Acompromisebetweencompilersandpureinterpreters
• Ahigh-levellanguageprogramistranslatedtoanintermediate
languagethatallowseasyinterpretation
• Fasterthanpureinterpretation
• Examples
• Perlprogramsarepartiallycompiledtodetecterrorsbeforeinterpretation
• InitialimplementationsofJavawerehybrid;theintermediateform,bytecode,provides
portabilitytoanymachinethathasabytecodeinterpreterandarun-timesystem(together,
thesearecalledJavaVirtualMachine)
HybridImplementationProcess
Just-in-TimeImplementationSystems
• Initiallytranslateprogramstoanintermediatelanguage
• Thencompiletheintermediatelanguageofthesubprogramsinto
machinecodewhentheyarecalled
• Machinecodeversioniskeptforsubsequentcalls
• JITsystemsarewidelyusedforJavaprograms
• .NETlanguagesareimplementedwithaJITsystem
• Inessence,JITsystemsaredelayedcompilers
Preprocessors
• Preprocessormacros(instructions)arecommonlyusedtospecifythat
codefromanotherfileistobeincluded
• Apreprocessorprocessesaprogramimmediatelybeforetheprogram
iscompiledtoexpandembeddedpreprocessormacros
• Awell-knownexample:Cpreprocessor
• expands#include, #define,andsimilarmacros
ProgrammingEnvironments
• Acollectionoftoolsusedinsoftwaredevelopment
• GNU
• CollectionofprogrammingtoolsproducedbytheGNU
• Cross-platform
• Eclipse
• MostwidelyusedJavaIDE
• Supportmanyotherlanguagesviaplugins
• Notonlyprogramming– helpdesignandothertasks
• MicrosoftVisualStudio.NET
• Alarge,complexvisualenvironment
• UsedtobuildWebapplicationsandnon-Webapplicationsinany.NETlanguage
• NetBeans
• RelatedtoVisualStudio.NET,exceptforapplicationsinJava