37
Advanced Programming Advanced Programming Giuseppe Attardi Giuseppe Attardi Dipartimento di Informatica Dipartimento di Informatica Università di Pisa Università di Pisa Università di Pisa

Advanced Programming Giuseppe Attardi Dipartimento di Informatica Università di Pisa

Embed Size (px)

Citation preview

Page 1: Advanced Programming Giuseppe Attardi Dipartimento di Informatica Università di Pisa

Advanced ProgrammingAdvanced Programming

Giuseppe AttardiGiuseppe Attardi

Dipartimento di InformaticaDipartimento di Informatica

Università di PisaUniversità di Pisa

Università di Pisa

Page 2: Advanced Programming Giuseppe Attardi Dipartimento di Informatica Università di Pisa

Language is an instrument of human reason,not merely a medium for the expression of thought.G. Boole, An Investigation of the Laws of Thought, 1854

Page 3: Advanced Programming Giuseppe Attardi Dipartimento di Informatica Università di Pisa

InstructorInstructor

Giuseppe AttardiOffice: 292Mail: [email protected]

Giuseppe AttardiOffice: 292Mail: [email protected]

Page 4: Advanced Programming Giuseppe Attardi Dipartimento di Informatica Università di Pisa

IntroductionIntroduction

Programming in the 21 centuryProgramming in the 21 century Software as complex as everSoftware as complex as ever Command line interface not enoughCommand line interface not enough Data comes from multiple sources: Data comes from multiple sources:

structured (DB) and unstructuredstructured (DB) and unstructured Single computer not enoughSingle computer not enough Software development is a group Software development is a group

activityactivity Deployment on Web or mobile devicesDeployment on Web or mobile devices

Page 5: Advanced Programming Giuseppe Attardi Dipartimento di Informatica Università di Pisa

RequirementsRequirements

Cannot start from scratchCannot start from scratchReusable components are neededReusable components are neededOS + libraries not enoughOS + libraries not enough

Page 6: Advanced Programming Giuseppe Attardi Dipartimento di Informatica Università di Pisa

Elements of a SolutionElements of a Solution

Software FrameworkSoftware FrameworkComponent ModelComponent ModelExecution EnvironmentExecution Environment

Page 7: Advanced Programming Giuseppe Attardi Dipartimento di Informatica Università di Pisa

More Complex SoftwareMore Complex Software

Object-Oriented Programming allows Object-Oriented Programming allows ever larger applications to be builtever larger applications to be built

Require increased high-level Require increased high-level application and system oversightapplication and system oversight

Multi-tier applications development Multi-tier applications development increases the choices on how to increases the choices on how to build applicationsbuild applications

A new A new Software Architect Software Architect Role is Role is neededneeded

Page 8: Advanced Programming Giuseppe Attardi Dipartimento di Informatica Università di Pisa

Software Architect DutiesSoftware Architect Duties

Creating, defining or choosing an Creating, defining or choosing an application frameworkapplication framework

Creating the component designCreating the component design Structure a complex application into Structure a complex application into

piecespieces Understand the interactions and Understand the interactions and

dependencies among componentsdependencies among components Select the platform based on Select the platform based on

cost/performance criteriacost/performance criteria Organize and supervise the Organize and supervise the

““construction siteconstruction site””

Page 9: Advanced Programming Giuseppe Attardi Dipartimento di Informatica Università di Pisa

Application FrameworkApplication Framework

A software framework used to A software framework used to implement the implement the standardstandard structure of structure of an application for a an application for a specificspecific development environmentdevelopment environment

Page 10: Advanced Programming Giuseppe Attardi Dipartimento di Informatica Università di Pisa

Software FrameworkSoftware Framework

A collection of A collection of common codecommon code providing providing generic functionalitygeneric functionality that that can be selectively overridden or can be selectively overridden or specialized by user codespecialized by user code providing providing specific functionalityspecific functionality

Frameworks, like software libraries, Frameworks, like software libraries, provide provide reusable abstractions reusable abstractions of of code wrapped in a well-defined APIcode wrapped in a well-defined API

Page 11: Advanced Programming Giuseppe Attardi Dipartimento di Informatica Università di Pisa

Framework FeaturesFramework Features

Inversion of controlInversion of control– unlike in libraries, the overall program's

flow of control is not dictated by the caller, but by the framework

– Hollywood Principle:Don’t call us, we’ll call you

Default behaviorDefault behaviorExtensibility: usually by selective Extensibility: usually by selective

overridingoverridingNon-modifiable framework code Non-modifiable framework code

Page 12: Advanced Programming Giuseppe Attardi Dipartimento di Informatica Università di Pisa

OO Software FrameworkOO Software Framework

Object-oriented programming Object-oriented programming frameworks consists in a frameworks consists in a set of set of abstract classesabstract classes

An application can be built simply An application can be built simply inheriting from pre-existing classes inheriting from pre-existing classes in the frameworkin the framework

Instantiation of a framework consists Instantiation of a framework consists of composing and subclassing the of composing and subclassing the existing classesexisting classes

Page 13: Advanced Programming Giuseppe Attardi Dipartimento di Informatica Università di Pisa

Examples of FrameworksExamples of Frameworks

GUIGUI– MFC– Gnome– Qt

GeneralGeneral– Android– Spring– Cocoa

WebWeb– ASP.Net– GWT– Rails

ConcurrenceConcurrence– Hadoop Map/Reduce

Page 14: Advanced Programming Giuseppe Attardi Dipartimento di Informatica Università di Pisa

Class Hierarchy (NextSTEP Class Hierarchy (NextSTEP 1988)1988)

Page 15: Advanced Programming Giuseppe Attardi Dipartimento di Informatica Università di Pisa

Cocoa (2013)Cocoa (2013)

Page 16: Advanced Programming Giuseppe Attardi Dipartimento di Informatica Università di Pisa

Benefits of FrameworksBenefits of Frameworks

Drives solutionDrives solution– Dictates how to fill-in-the-blanks

Helps solving recurring problemsHelps solving recurring problems– Designed for reuse– High value, since reduces cost of

development

Page 17: Advanced Programming Giuseppe Attardi Dipartimento di Informatica Università di Pisa

Framework DesignFramework Design

Intellectual Challenging TaskIntellectual Challenging TaskRequires a deep understanding of Requires a deep understanding of

the problem domainthe problem domainRequires mastering of software Requires mastering of software

patterns, OO methods and patterns, OO methods and polymorphism in particularpolymorphism in particular

Page 18: Advanced Programming Giuseppe Attardi Dipartimento di Informatica Università di Pisa

Design PatternDesign Pattern

More abstract than frameworksMore abstract than frameworks– Frameworks can be embodied in code, but only

examples of patterns can be embodied in code– Design patterns explain the intent, trade-offs, and

consequences of a design Smaller architectural elements than frameworksSmaller architectural elements than frameworks

– A typical framework contains several design patterns but the reverse is never true.

Less specialized than frameworksLess specialized than frameworks– Frameworks always have a particular application

domain– Design patterns can be used in nearly any kind of

application

Page 19: Advanced Programming Giuseppe Attardi Dipartimento di Informatica Università di Pisa

ExamplesExamples

VisitorVisitorPublish/SubscribePublish/SubscribeFactoryFactoryDependency InjectionDependency InjectionChain of ResponsibilityChain of ResponsibilityObserverObserver IteratorIteratorDecoratorDecorator

Page 20: Advanced Programming Giuseppe Attardi Dipartimento di Informatica Università di Pisa

Dependency InjectionDependency Injection

Allows avoiding hard-coded Allows avoiding hard-coded dependencies and changing themdependencies and changing them

Allows selection among multiple Allows selection among multiple implementations of a given implementations of a given dependency interface at run timedependency interface at run time

Examples:Examples:– load plugins dynamically– replace mock objects in test

environments vs. real objects in production environments

Page 21: Advanced Programming Giuseppe Attardi Dipartimento di Informatica Università di Pisa

Course ObjectivesCourse Objectives

Understand programming language Understand programming language technology:technology:– Execution Models– Run-time

Analyze programming metaphors:Analyze programming metaphors:– Objects– Components– Patterns

Learn advanced programming techniquesLearn advanced programming techniques Understand their limits ad how to Understand their limits ad how to

overcome themovercome them

Page 22: Advanced Programming Giuseppe Attardi Dipartimento di Informatica Università di Pisa

Course ObjectivesCourse Objectives

Explain how high level programming Explain how high level programming concepts and metaphors map into concepts and metaphors map into executable systems and which are their executable systems and which are their costs and limitationscosts and limitations

Acquaint with modern principles, Acquaint with modern principles, techniques, and best practices of advanced techniques, and best practices of advanced software construction software construction

Introduce techniques of programming at Introduce techniques of programming at higher abstraction levels, in particular higher abstraction levels, in particular generative programming, component generative programming, component programming and web computing programming and web computing

Present state-of-the-art frameworks Present state-of-the-art frameworks incorporating these techniquesincorporating these techniques

Page 23: Advanced Programming Giuseppe Attardi Dipartimento di Informatica Università di Pisa

SyllabusSyllabus

Page 24: Advanced Programming Giuseppe Attardi Dipartimento di Informatica Università di Pisa

Programming Language Programming Language FoundationsFoundations Syntax, Parsing, Abstract Syntax Tree, Syntax, Parsing, Abstract Syntax Tree,

Parser Generators Parser Generators Names, Scope, Binding Names, Scope, Binding Parameter Passing Parameter Passing Static and Dynamic Allocaltion: Stack, Static and Dynamic Allocaltion: Stack,

Heap Heap Types, Inheritance, Polymorphism, Types, Inheritance, Polymorphism,

Overloading Overloading Delegates, Closures Delegates, Closures Exception Handling Exception Handling

Page 25: Advanced Programming Giuseppe Attardi Dipartimento di Informatica Università di Pisa

Run-time SystemsRun-time Systems

Virtual Execution Environment Virtual Execution Environment – Memory Management – Thread Management – Exception Handling – Security – Debugging Support – AOT and JIT Compilation – Dynamic Link/Load – Reflection– Verification

Language InteroperabilityLanguage Interoperability

Page 26: Advanced Programming Giuseppe Attardi Dipartimento di Informatica Università di Pisa

Advanced TechniquesAdvanced Techniques

Generic ProgrammingGeneric Programming– C++ templates– C# Generics– Java Generics

Generative ProgrammingGenerative Programming– Metaprogramming– Reflection– Template– Aspect Oriented Programming– Generators

Page 27: Advanced Programming Giuseppe Attardi Dipartimento di Informatica Università di Pisa

InteroperabilityInteroperability

Process level: interprocess Process level: interprocess communication communication

Language level: CORBA/IDL Language level: CORBA/IDL Object level: DCOM Object level: DCOM

Page 28: Advanced Programming Giuseppe Attardi Dipartimento di Informatica Università di Pisa

Component Based Component Based ProgrammingProgrammingCOM COM JavaBeans JavaBeans .NET (Assembly, Reflection, .NET (Assembly, Reflection,

Interfaces, Attributes) Interfaces, Attributes) OSGi OSGi

Page 29: Advanced Programming Giuseppe Attardi Dipartimento di Informatica Università di Pisa

Web ProgrammingWeb Programming

Web Services, SOAWeb Services, SOAWeb FrameworksWeb FrameworksWeb 2.0Web 2.0

Page 30: Advanced Programming Giuseppe Attardi Dipartimento di Informatica Università di Pisa

Web ServicesWeb Services

XML, XML-Schema XML, XML-Schema SOAP, RPC, Rest SOAP, RPC, Rest WSDL WSDL UDDIUDDI

Page 31: Advanced Programming Giuseppe Attardi Dipartimento di Informatica Università di Pisa

Web Frameworks and Web Frameworks and ApplicationsApplicationsAsp.Net Asp.Net ADO.Net ADO.Net J2EE J2EE Java Server Faces Java Server Faces JQueryJQueryAJAX: XHR, jQuery, YUI, GWT AJAX: XHR, jQuery, YUI, GWT Mashup and Service Oriented Mashup and Service Oriented

ArchitectureArchitecture

Page 32: Advanced Programming Giuseppe Attardi Dipartimento di Informatica Università di Pisa

Scripting LanguagesScripting Languages

PerlPerlPythonPythonJavaScriptJavaScriptPHP PHP

Page 33: Advanced Programming Giuseppe Attardi Dipartimento di Informatica Università di Pisa

Text BooksText Books

Programming Language Programming Language Pragmatics, third ed., Michael L. Pragmatics, third ed., Michael L. Scott, Morgan-Kaufmann, 2009.Scott, Morgan-Kaufmann, 2009.

Generative Programming: Generative Programming: Methods, Tools, and Methods, Tools, and Applications, Krzysztof Applications, Krzysztof Czarnecki, Ulrich Eisenecker, Czarnecki, Ulrich Eisenecker, Addison-Wesley, 2000.Addison-Wesley, 2000.

Object Thinking , David West, Object Thinking , David West, Microsoft Press, 2004.Microsoft Press, 2004.

Page 34: Advanced Programming Giuseppe Attardi Dipartimento di Informatica Università di Pisa

Text BooksText Books

jQuery in Action, B. Bibeault, jQuery in Action, B. Bibeault, Y. Katz, Manning, 2010.Y. Katz, Manning, 2010.

Page 35: Advanced Programming Giuseppe Attardi Dipartimento di Informatica Università di Pisa

AssessmentAssessment

Mid Term Paper: early November, Mid Term Paper: early November, one week homework one week homework

Term Paper: at the end of the course, Term Paper: at the end of the course, 20 days homework 20 days homework

Page 36: Advanced Programming Giuseppe Attardi Dipartimento di Informatica Università di Pisa

Final Term PaperFinal Term Paper

Aims at exercising ability to conceive and Aims at exercising ability to conceive and implement full solutions to a nontrivial problemimplement full solutions to a nontrivial problem

Examples:Examples:– ASP Code generator with regular expression matcher– Implement a DSL for handling persistent object

containers– SOAP protocol and SOAP server– Code generator for searching an object DB– Xpath and XSLT Intrepreter– Language for generating network protocols– AJAX Framework– Unit Testing Framework– State Charts

Page 37: Advanced Programming Giuseppe Attardi Dipartimento di Informatica Università di Pisa

Home WorkHome Work

Develop a simple implementation of Develop a simple implementation of primitives:primitives:– void* malloc(size_t size)– void free(void*)

Assume to have available a block of Assume to have available a block of memory of size MemSize starting at memory of size MemSize starting at MemStartMemStart

Discuss the limits of the solutionDiscuss the limits of the solution