New Programming Paradigms Lecturer: Pánovics János (google the name for further details) Requirements: For signature: classroom work and a 15-minute presentation Exam: written exam (mainly concepts and code analysis)
Programming Languages What is a computer good for? Data processing machine: can process a big amount of data in a short time (almost) without errors. Task is written by a program or (program) code. The code is written in a special language: programming language.
Categories of Computer Languages programming language (e.g., C) database query language (e.g., SQL) scripting language (e.g., Perl) visual language (e.g., LabView) modeling language (e.g., UML) markup language (e.g., XML) style sheet language (e.g., CSS) configuration language (e.g., JSON) domain-specific language (e.g., RecipeBook)
Classification of Programming Languages Machine language: Program in machine language: machine code (binary). Translator program: not required. Assembly languages: Program in assembly: assembly (source) code (text). Translator program: assembler. High-level programming languages: Program in HLPL: (C, Pascal, ) source code (text). Translator program: compiler or interpreter.
Compilers and Interpreters Typical compilation process: source code source code object code preprocessor compiler linker executable code runtime system execution
Compilers and Interpreters Interpretation process: source code execution interpreter
Compilers and Interpreters Hybrid execution process: source code compiler intermediate language code execution interpreter
type system abstraction reusability concurrency Features of High-Level Programming Languages exception handling secure programming (assertions)
Type System untyped languages (e.g., assembly) single-type languages (e.g., scripting and markup languages) typed languages static typing (types determined at compile time) manifestly typed languages (explicit declarations; e.g., Java) type-inferred languages (implicit declarations; e.g., Haskell) dynamic typing (types determined at run time, e.g., Python): more flexible but also more error-prone duck typing ( If it walks like a duck and it quacks like a duck, then it must be a duck. ) weak typing (implicit type conversions; e.g., JavaScript) strong typing (type equivalence; e.g., Pascal): type-safe languages
Abstraction Data abstraction: data type programmer-defined type abstract data type (encapsulation, information hiding) class (inheritance) abstract class interface Procedural abstraction: subprogram (function, procedure), method package, module, unit, inheritance, polymorphism (overriding) overloading namespace (Java: package),.net assembly (Java: jar), generics (templates, parameterized types and methods)
Programming Paradigms A programming paradigm is an approach reflecting a possible way of thinking about a system to be modeled; it is a style of programming. There is no best approach. Which one to use depends on the problem. Aspects to consider: conciseness, readability, flexibility, reusability, efficiency, etc. Paradigms are not meant to be mutually exclusive.
List of Common Paradigms Imperative: control flow is an explicit sequence of statements. Declarative: programs state the result you want, not how to get it. Object-oriented: computation is effected by sending messages to objects; objects have state and behavior. Event-driven: control flow is determined by asynchronous actions (from humans or sensors). Flow-driven: computation is specified by multiple processes communicating over predefined channels. Aspect-oriented: programs have cross-cutting concerns applied transparently. Reflective: programs manipulate their own structures (also called metaprogramming).
Imperative Programming The program is made up of statements, which describe how to solve the problem. Sequential execution is the default; special statements that influence control flow: jumps. Variables are used to store values. Computer-friendly way of thinking: closely related to von Neumann architecture. Does not require intelligent run-time environment. Subparadigms (programming techniques): Structured programming: both data and code have hierarchical structures. Procedural programming: subprograms (functions and procedures) are used to structure code. Uses calls and parameters. Modular programming: groups programming constructs that represent the same concern of the system into distinct, loosely coupled modules.
Declarative Programming Contrasts with imperative programming. The program describes what the problem is, rather than specifying how to solve it. Human-friendly way of thinking. Requires an intelligent run-time environment. Subparadigms: Functional (applicative) programming: computation proceeds by (nested) function calls that avoid any global state. Function-level (combinator) programming: programs have no variables, they use only functions and functionals. Logic (rule-based) programming: programmer specifies a set of facts and rules, and an engine infers the answers to questions.
Object-Oriented Programming The task of a program is carried out by the communication of objects. Objects have a unique identity (OID), a state (current values of their fields), and behavior (describing how they react to messages; realized by methods). Combines data model with procedural model. Class: type (abstraction) of similar objects. Class-based inheritance: subclass defined based on superclass. Class hierarchy: object polymorphism (Liskov substitution principle). Overriding: method polymorphism. Prototype-based inheritance: implements inheritance via cloning of instances.
Aspect-Oriented Programming Based on the separation of concerns (SoC): program elements representing the same concern of the problem should be placed in the same module, an aspect. Typically used for separating code responsible for nonfunctional requirements, like logging, persistence, security, etc. Join point: a moment of execution when the control can be passed over to the code of an aspect. Advice: the action to perform at a given join point. Pointcut: defines a set of join points where the associated advice should be applied. Weaving: assembling the final program from the separated modules. It can be done at compile (preprocessing) time, link time, load time, or run time.
Metaprogramming A technique that allows the programmer to manage (examine, manipulate, or construct) the base program from a higher dimension, the metaprogram. The code in the base level is considered data in the meta level. Reflection: construction of metaobjects representing (reflecting) elements of the base program. Structural reflection: access data structures (such as classes or methods) used by the program statically fixed at compile time. Behavioral reflection: intercept an operation (such as a method invocation) and alter the behavior of that operation. Introspection: the program can examine itself. Intercession: the program can modify its state/meaning. Reification: implementing the effect of manipulation of metaobjects in the base level; i.e., making an abstract concept concrete. Metaobject protocol (MOP): specifies what kind of metainformation can be accessed and how it can be used to analyze or modify the base program.
Programming Languages and Paradigms Pure languages: support only one paradigm (e.g., C). Hybrid languages: support two paradigms (e.g., Java 7). Multiparadigm languages: support more than two paradigms (e.g., C#). Programmers may choose the paradigm that is best suited for the problem and their needs.