Advanced Programming Advanced Programming
Giuseppe Attardi Giuseppe Attardi
Dipartimento di Informatica Dipartimento di Informatica
Università di Pisa Università di Pisa
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
Instructor and Assistant Instructor and Assistant
Giuseppe Attardi Office: 292
Mail: attardi@di.unipi.it Giuseppe Attardi
Office: 292
Mail: attardi@di.unipi.it
TBDTBD
Recurring questions Recurring questions
To teach or not to teach To teach or not to teach programming?
programming?
How to teach programming?How to teach programming?
Programming is not just Programming is not just programming languages programming languages
Software Everywhere Software Everywhere
Software can be the key to delivering Software can be the key to delivering new product offerings and driving
new product offerings and driving continuous product innovation
continuous product innovation
Software role:Software role:
– Product innovation – Process flexibility
– Process enforcement for quality assurance and matching demands
Software Innovation
Software Innovation
Software as Competitive Software as Competitive
Advantage Advantage
Most Admired Companies Making IT A Competitive Advantage (Forbes)
Accenture
Amazon
Apple
Cleveland Clinic
General Electric
Goldman Sachs
Hospital Corporation of America
IBM
Intermountain Healthcare
JP Morgan Chase
Kaiser Permanente
Mayo Clinic
Microsoft
Nestle
Procter & Gamble
Progressive Insurance
Schlumberger
Target
Toyota
Wells Fargo
Introduction Introduction
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 unstructured structured (DB) and unstructured
Single computer not enoughSingle computer not enough
Software development is a group Software development is a group activity
activity
Deployment on Web or mobile devicesDeployment on Web or mobile devices
Requirements Requirements
Cannot start from scratchCannot start from scratch
Reusable components are neededReusable components are needed
OS + libraries not enoughOS + libraries not enough
Elements of a Solution Elements of a Solution
Software FrameworkSoftware Framework
Component ModelComponent Model
Execution EnvironmentExecution Environment
More Complex Software More Complex Software
Object-Oriented Programming allows Object-Oriented Programming allows ever larger applications to be built
ever larger applications to be built
Require increased high-level Require increased high-level
application and system oversight application and system oversight
Multi-tier applications development Multi-tier applications development increases the choices on how to
increases the choices on how to build applications
build applications
A new A new Software Architect Software Architect Role is Role is needed
needed
Software Architect Duties Software Architect Duties
Creating, defining or choosing an Creating, defining or choosing an application framework
application framework
Creating the component designCreating the component design
Structure a complex application into Structure a complex application into pieces
pieces
Understand the interactions and Understand the interactions and dependencies among components dependencies among components
Select the platform based on Select the platform based on cost/performance criteria
cost/performance criteria
Organize and supervise the Organize and supervise the
““construction siteconstruction site””
Application Framework Application 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 environment development environment
Software Framework Software 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 code
specialized by user code providing providing specific functionality
specific functionality
Frameworks, like software libraries, Frameworks, like software libraries, provide
provide reusable abstractions reusable abstractions of of code wrapped in a well-defined API code wrapped in a well-defined API
Framework Features Framework 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 behavior
Extensibility: usually by selective Extensibility: usually by selective overriding
overriding
Non-modifiable framework code Non-modifiable framework code
OO Software Framework OO Software Framework
Object-oriented programming Object-oriented programming frameworks consists in a
frameworks consists in a set of set of abstract classes
abstract 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 framework in the framework
Instantiation of a framework consists Instantiation of a framework consists of composing and subclassing the
of composing and subclassing the existing classes
existing classes
Examples of Frameworks Examples of Frameworks
GUIGUI
– MFC – Gnome – Qt
GeneralGeneral
– Android – Spring – Cocoa
WebWeb
– ASP.Net – GWT
– Rails
ConcurrenceConcurrence
– Hadoop Map/Reduce
Class Hierarchy (NextSTEP Class Hierarchy (NextSTEP
1988)
1988)
Cocoa (2013)
Cocoa (2013)
Benefits of Frameworks Benefits 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
Framework Design Framework Design
Intellectual Challenging TaskIntellectual Challenging Task
Requires a deep understanding of Requires a deep understanding of the problem domain
the problem domain
Requires mastering of software Requires mastering of software patterns, OO methods and
patterns, OO methods and polymorphism
polymorphism in particular in particular
Design Pattern Design 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 Smaller architectural elements than frameworks
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
Examples Examples
VisitorVisitor
Publish/SubscribePublish/Subscribe
FactoryFactory
Dependency InjectionDependency Injection
Chain of ResponsibilityChain of Responsibility
ObserverObserver
IteratorIterator
DecoratorDecorator
Dependency Injection Dependency Injection
Allows avoiding hard-coded Allows avoiding hard-coded
dependencies and changing them dependencies and changing them
Allows selection among multiple Allows selection among multiple implementations of a given
implementations of a given
dependency interface at run time dependency interface at run time
Examples:Examples:
– load plugins dynamically
– replace mock objects in test
environments vs. real objects in production environments
Dependency Injection Dependency Injection
public class Client {
// Internal reference to the service used by this client private Service service;
Client() {
// Fixed implementation
service = new ServiceExample();
}
Client(Service service) {
// injection of a specific service this.service = service;
}
// Method within this client that uses the service public String greet() {
return "Hello " + service.getName();
} }
Course Objectives Course 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 them
overcome them
Course Objectives Course 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 limitations costs 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 techniques
incorporating these techniques
Syllabus
Syllabus
Programming Language Programming Language
Foundations Foundations
Syntax, Parsing, Abstract Syntax Syntax, Parsing, Abstract Syntax Tree, Parser Generators
Tree, Parser Generators
Names, Scope, Binding Names, Scope, Binding
Parameter Passing Parameter Passing
Static and Dynamic Allocaltion: Static and Dynamic Allocaltion:
Stack, Heap Stack, Heap
Types, Inheritance, Polymorphism, Types, Inheritance, Polymorphism, Overloading
Overloading
Delegates, Closures Delegates, Closures
Exception Handling Exception Handling
Run-time Systems Run-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
Advanced Techniques Advanced Techniques
Generic ProgrammingGeneric Programming
– C++ templates – C# Generics – Java Generics
Generative ProgrammingGenerative Programming
– Metaprogramming – Reflection
– Template
– Aspect Oriented Programming – Generators
Interoperability Interoperability
Process level: interprocess Process level: interprocess communication
communication
Language level: CORBA/IDL Language level: CORBA/IDL
Object level: DCOM Object level: DCOM
Component Based Component Based
Programming Programming
COM COM
JavaBeans JavaBeans
.NET (Assembly, Reflection, .NET (Assembly, Reflection, Interfaces, Attributes)
Interfaces, Attributes)
OSGi OSGi
Web Programming Web Programming
Web Services, SOAWeb Services, SOA
Web FrameworksWeb Frameworks
Web 2.0Web 2.0
Web Services Web Services
XML, XML-Schema XML, XML-Schema
SOAP, RPC, Rest SOAP, RPC, Rest
WSDL WSDL
UDDIUDDI
Web Frameworks and Web Frameworks and
Applications Applications
Asp.Net Asp.Net
J2EE J2EE
JQueryJQuery
AJAX: XHR, jQuery, YUI, GWTAJAX: XHR, jQuery, YUI, GWT
Node.jsNode.js
ReactReact
Service Components Service Components
Service Oriented ArchitectureService Oriented Architecture
MicroservicesMicroservices
Flow Based ProgrammingFlow Based Programming
Scaling Scaling
Map/ReduceMap/Reduce
CUDA ProgrammingCUDA Programming
Web Application Web Application
Frameworks Frameworks
ArchitecturesArchitectures
Principles:Principles:
– Inversion of control
FeaturesFeatures
– Templates
– Database access and mapping – Scaffolding
– Ajax
– Web Services
Examples:Examples:
– Symfony – Laravel
Scripting Languages Scripting Languages
PerlPerl
PythonPython
JavaScriptJavaScript
PHPPHP
RubyRuby
IEEE Spectrum Ranking 2015-2014
IEEE Spectrum Ranking 2015-2014
IEEE Spectrum Ranking 2016-2015
IEEE Spectrum Ranking 2016-2015
CodEval Chart
CodEval Chart
Top 10 Frameworks
Top 10 Frameworks
Top 10 Web Application Top 10 Web Application
Frameworks Frameworks
1.1. Ruby on RailsRuby on Rails
2.2. AngularJSAngularJS
3.3. Ember.jsEmber.js
4.4. CakePHPCakePHP
5.5. PhalconPhalcon
6.6. ZendZend
7.7. ASP.netASP.net
8.8. SymfonySymfony
9.9. ExpressExpress
10.10.CodeigniterCodeigniter
Text Books Text Books
Programming Language Programming Language
Pragmatics, third ed.. Michael L.
Pragmatics, third ed.. Michael L.
Scott, Morgan-Kaufmann, 2009.
Scott, Morgan-Kaufmann, 2009.
Software Components: Beyond Software Components: Beyond
Object-Oriented Programming. C.
Object-Oriented Programming. C.
Szyperski, D. Gruntz, S. Murer, Szyperski, D. Gruntz, S. Murer,
Addison-Wesley, 2002.
Addison-Wesley, 2002.
Additional Reading Additional Reading
Generative Programming: Methods, Generative Programming: Methods,
Tools, and Applications. K.
Tools, and Applications. K.
Czarnecki, U. Eisenecker, Czarnecki, U. Eisenecker,
Addison-Wesley, 2000.
Addison-Wesley, 2000.
Object Thinking. D. West, Microsoft Object Thinking. D. West, Microsoft
Press, 2004.
Press, 2004.
jQuery in Action. B. Bibeault, Y.
jQuery in Action. B. Bibeault, Y.
Katz, Manning, 2010.
Katz, Manning, 2010.
Assessment Assessment
Mid Term Paper: half way, one week Mid Term Paper: half way, one week homework
homework
Term Paper: at the end of the course, Term Paper: at the end of the course, 20 days homework
20 days homework
Final Term Paper Final Term Paper
Aims at exercising ability to conceive and Aims at exercising ability to conceive and
implement full solutions to a nontrivial problem implement 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
Home Work Home 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
MemStart MemStart
Discuss the limits of the solutionDiscuss the limits of the solution