Programming Languages Features - PowerPoint PPT Presentation

1 / 18
About This Presentation
Title:

Programming Languages Features

Description:

High-order. 5 ... Computer program which prints its own source code (without reading it from a ... Goals: quality assurance, reliability. Eiffel language ... – PowerPoint PPT presentation

Number of Views:22
Avg rating:3.0/5.0
Slides: 19
Provided by: informat8
Category:

less

Transcript and Presenter's Notes

Title: Programming Languages Features


1
Programming Languages Features
  • Programming styles or paradigms
  • Imperative
  • Functional
  • Declarative
  • Modularity
  • Procedural
  • Object-oriented
  • Aspect-oriented
  • Reflective
  • Component-based
  • Design by Contract

2
Programming Styles or Paradigms
  • Imperative how
  • Most common languages (C, C, Java)
  • Programmer provides explicit algorithm to solve a
    problem
  • State (variable assignments), side effects
  • Functional (e.g. LISP (next Seminar))
  • Everything is a function
  • Computation function evaluation
  • Declarative what
  • AI background Intelligent systems
  • Programmer states what needs to be done (not an
    explicit algorithm)
  • System searches for solution
  • No explicit global state and side effects

3
Programming Styles or Paradigms
  • Declarative
  • Logic (e.g. Prolog)
  • Rule-based (CLIPS/Jess, Cisco ACLs)
  • expert(pmeier, uberlin, graphtheory).
  • expert(jsmith, ucla, netarch).
  • ...
  • paper(title1, ptann, ulancs, netarch).
  • paper(title2, mgerla, ucla, netarch).
  • paper(title3, pkim, uskr, graphtheory).
  • ...
  • reviewer(E, P) -
  • expert(E, I, T), paper(P, _ , J, T), \ I J.
  • ?- reviewer(X,Y).

gprolog http//gnu-prolog.inria.fr/
not
run program query
4
More Programming Styles and Paradigms
  • Deductive
  • Message-passing
  • Constraint
  • High-order
  • ........

5
Modularity Features
  • Procedural
  • Object-oriented
  • Aspect-oriented
  • Reflective
  • Component-based
  • Design by Contract

6
Aspect-Oriented Programming (AOP)
  • Separation of concerns
  • Functional (application) concerns
  • Good encapsulation through classes (OO)
  • Cross-cutting concerns
  • Repeat across different classes
  • Examples logging, monitoring, debugging,
    security
  • Encapsulation through aspects
  • Aspect construct encapsulates cross-cutting
    concerns
  • Facilitates changes and upgrades (e.g. security
    policies)
  • No changes to functional classes

7
Aspect-Oriented Programming (AOP)
  • AspectJ Language
  • Java extension
  • Implementation within Eclipse software platform
  • Weaving classes and aspects together through
    joint points, pointcuts and advices
  • joint points points in the program where the
    aspect must interfere (typically method calls,
    access to class members, exception handler
    blocks)
  • pointcut selects joint points that match certain
    criteria
  • advices the aspect-related code that is executed
    before, after, or around (beforeafter) a joint
    point.

8
AOP Example Logging
class A method1(...) method2(...)
jointpoint
aspect AutoLog pointcut loggableCalls()
ltpattern_specgt before()loggableCalls()
logger.entry(thisJointPoint.get...)
after()loggableCalls() logger.exit(thisJointPoi
nt.get...)
  • class B
  • method1(...)
  • method2(...)

jointpoint
9
Component-Based Systems
  • Classes (OO)
  • Clear interface on exported features (how to use
    class)
  • Imported features (what the class uses) not
    entirely clear from outside (class as a
    black-box)
  • Components
  • Both exported and imported features must be
    specified
  • Like a hardware component described in a
    datasheet
  • Software factories assembling software like
    hardware
  • Reusable components
  • (Dynamic) composition mechanisms
  • E.g. (Enterprise) JavaBeans, TinyOS nesC (sensor
    nets)

10
Computational Reflection
  • Reflection or introspection think about
    oneself
  • Self-Reference Quine
  • Computer program which prints its own source code
    (without reading it from a file or other external
    input)
  • Self-replicating program
  • Reflective system information about itself
    (meta-information) accessible to the system
    itself
  • Meta-info may be used to explain or change its
    behavior
  • Two levels
  • Functional level or Base level
  • Meta level meta-information

11
Quine Examples
  • From http//www.nyx.net/gthompso/quine.htm
  • In C
  • charf"charfcscmain()
  • printf(f,34,f,34,10)c"
  • main()printf(f,34,f,34,10)
  • In Scheme
  • ((lambda (x)
  • (list x (list (quote quote) x)))
  • (quote
  • (lambda (x)
  • (list x (list (quote quote) x)))))
  • More http//www.madore.org/david/computers/quine
    .html

12
Computational Reflection
  • Reflection tower (recursive)
  • Meta level inspects base level
  • Meta meta level inspects meta level, , and so on
  • Java reflection (java.lang.reflect.)
  • Read classes and methods by name
  • Discover class, object, and method properties
  • Invoke methods or create objects whose class is
    discovered only at run time
  • Not possible to create new classes, modify
    methods, etc.

13
Design by Contract
  • Contract specification associated to a
    component
  • Goals quality assurance, reliability
  • Eiffel language
  • Contract specification as part of the language
    constructs

contract
Component A (Supplier)
Component B (Client)
Benefits and obligations
14
Contract Example in Eiffel
  • class DICTIONARY ...
  • put (x ELEMENT key STRING) is
  • require
  • count lt capacity
  • not key.empty
  • do
  • ... insertion algorithm ...
  • ensure
  • has (x)
  • item (key) x
  • count old count 1
  • invariant
  • 0 lt count
  • count lt capacity
  • end

Pre-conditions or obligations
Post-conditions or benefits
General class assertion
15
Concurrency and Parallelism
sequential execution
parallel execution
begin
A
fork
cobegin
A
C
B
B
A
C
B
join
coend
D
C
end
time
16
Concurrency and Parallelism
  • Granularity
  • Processes (e.g. Unix fork)
  • Threads (e.g. in Java)
  • Concurrent blocks fork, join, cobegin...coend
  • Machine instructions e.g. Very Long Instruction
    Word (VLIW), Data Flow machines

17
Concurrency and Parallelism
  • Chemical Programming Gamma

54
20
max
76
1
max(x,y) x gt y gt x
8
9
20
54
max
max
76
1
76
9
18
Other Features and Concepts
  • Iterators
  • Persistence
  • Operational Semantics
  • Self-Documentation
  • Proof-Carrying Code
  • .....
Write a Comment
User Comments (0)
About PowerShow.com