Difference between revisions of "Multi-Paradigm Programming and Scripting"
Adelo Vieira (talk | contribs) (→Languages evaluation Criteria) |
Adelo Vieira (talk | contribs) |
||
Line 51: | Line 51: | ||
<br /> | <br /> | ||
− | ==Languages evaluation criteria== | + | ==Some important programming concepts== |
+ | |||
+ | |||
+ | <br /> | ||
+ | ===Languages evaluation criteria=== | ||
https://www.cs.scranton.edu/~mccloske/courses/cmps344/sebesta_chap1.html | https://www.cs.scranton.edu/~mccloske/courses/cmps344/sebesta_chap1.html | ||
Line 105: | Line 109: | ||
<br /> | <br /> | ||
− | ==Imperative versus declarative code== | + | ===Imperative versus declarative code=== |
https://medium.com/front-end-weekly/imperative-versus-declarative-code-whats-the-difference-adc7dd6c8380 | https://medium.com/front-end-weekly/imperative-versus-declarative-code-whats-the-difference-adc7dd6c8380 | ||
<br /> | <br /> | ||
− | ===Imperative paradigm=== | + | ====Imperative paradigm==== |
'''Procedural''' and '''object-oriented programming''' belong under imperative paradigm that you know from languages like <code>C</code>, <code>C++</code>, <code>C#</code>, <code>PHP</code>, <code>Java</code> and of course <code>Assembly</code>. | '''Procedural''' and '''object-oriented programming''' belong under imperative paradigm that you know from languages like <code>C</code>, <code>C++</code>, <code>C#</code>, <code>PHP</code>, <code>Java</code> and of course <code>Assembly</code>. | ||
Line 137: | Line 141: | ||
<br /> | <br /> | ||
− | ===Declarative paradigm=== | + | ====Declarative paradigm==== |
'''Logic''', '''functional''' and '''domain-specific''' languages belong under '''declarative paradigms''' and they are not always Turing-complete (they are not always universal programming languages). Examples would be <code>HTML</code>, <code>XML</code>, <code>CSS</code>, <code>SQL</code>, <code>Prolog</code>, <code>Haskell</code>, <code>F#</code> and <code>Lisp</code>. | '''Logic''', '''functional''' and '''domain-specific''' languages belong under '''declarative paradigms''' and they are not always Turing-complete (they are not always universal programming languages). Examples would be <code>HTML</code>, <code>XML</code>, <code>CSS</code>, <code>SQL</code>, <code>Prolog</code>, <code>Haskell</code>, <code>F#</code> and <code>Lisp</code>. | ||
Line 151: | Line 155: | ||
<br /> | <br /> | ||
− | + | ===Compilation vs Interpretation=== | |
− | ==Compilation vs Interpretation== | ||
https://medium.com/@DHGorman/a-crash-course-in-interpreted-vs-compiled-languages-5531978930b6 | https://medium.com/@DHGorman/a-crash-course-in-interpreted-vs-compiled-languages-5531978930b6 | ||
Line 169: | Line 172: | ||
<br /> | <br /> | ||
− | ===Advantages and Disadvantages=== | + | ====Advantages and Disadvantages==== |
'''Compiled Languages:''' | '''Compiled Languages:''' | ||
Line 192: | Line 195: | ||
<br /> | <br /> | ||
− | + | ====Phases of Compilation==== | |
− | ===Phases of Compilation=== | ||
[[File:Phases of compilation.png|950px|thumb|center|]] | [[File:Phases of compilation.png|950px|thumb|center|]] | ||
Line 211: | Line 213: | ||
<br /> | <br /> | ||
− | |||
==Object-Oriented Paradigm== | ==Object-Oriented Paradigm== | ||
Revision as of 21:35, 2 November 2019
Why Multi-Paradigm Programming and Scripting? | |||
---|---|---|---|
| |||
Content of this course | |||
Programming Constructs:
|
Programming Paradigms & Languages:
|
Scripting:
|
Applications of Shell Scripting:
|
Some important programming concepts
Languages evaluation criteria
https://www.cs.scranton.edu/~mccloske/courses/cmps344/sebesta_chap1.html
Readability | Writability | Reliability | Cost | Other criteria |
---|---|---|---|---|
This refers to the ease with which programs (in the language under consideration) can be understood. This is especially important for software maintenance.
|
This is a measure of how easily a language can be used to develop programs for a chosen problem domain.
|
This is the property of performing to specifications under all conditions.
|
The following contribute to the cost of using a particular language:
|
|
Imperative versus declarative code
Imperative paradigm
Procedural and object-oriented programming belong under imperative paradigm that you know from languages like C
, C++
, C#
, PHP
, Java
and of course Assembly
.
Your code focuses on creating statements that change program states by creating algorithms that tell the computer how to do things. It closely relates to how hardware works. Typically your code will make use of conditinal statements, loops and class inheritence.
Example of imperative code in JavaScript
is:
class Number {
constructor (number = 0) {
this.number = number;
}
add (x) {
this.number = this.number + x;
}
}
const myNumber = new Number (5);
myNumber.add (3);
console.log (myNumber.number); // 8
Declarative paradigm
Logic, functional and domain-specific languages belong under declarative paradigms and they are not always Turing-complete (they are not always universal programming languages). Examples would be HTML
, XML
, CSS
, SQL
, Prolog
, Haskell
, F#
and Lisp
.
Declarative code focuses on building logic of software without actually describing its flow. You are saying what without adding how. For example with HTML you use to tell browser to display an image and you don’t care how it does that.
Example of declarative code in JavaScript is:
const sum = a => b => a + b;
console.log (sum (5) (3)); // 8
Compilation vs Interpretation
https://medium.com/@DHGorman/a-crash-course-in-interpreted-vs-compiled-languages-5531978930b6
https://guide.freecodecamp.org/computer-science/compiled-versus-interpreted-languages/
Speaking simplistically, compiled languages are those which are written in one language and, before being run, translated or "compiled" into another language, called the target language (typically in machine language that the processor can execute). Once the translation is complete, the executable code is either run or set aside to run later. Some common compiled languages include C
, C++
, Delphi
and Rust
.
The compiler
translates the high-level source program into an equivalent target program (typically in machine language).
The alternative to using a compiler
(for a compiled language) is using an interpreter
(for interpreted languages). Interpreted languages are "interpreted" live in their original source code, although in reality they are merely compiled at runtime. What this allows for is a lot more flexibility, especially when it comes to a program adaptively modifying its structure. This flexibility does have a cost; interpreted languages are considered significantly slower.
Interpreters
will run through a program line by line and execute each command.
Advantages and Disadvantages
Compiled Languages:
- Advantages:
- Programs compiled into native code at compile time usually tend to be faster than those translated at run time, due to the overhead of the translation process.
- Disadvantages:
- Additional time needed to complete the entire compilation step before testing, and Platform dependence of the generated binary code.
Interpreted Languages:
- Advantages:
- Greater flexibility
- Better diagnostics (error messages)
- An Interpreted language gives implementations some additional flexibility over compiled implementations. Because interpreters execute the source program code themselves, the code itself is platform independent (Java's byte code, for example). Other features include dynamic typing, and smaller executable program size.
- Disadvantages:
- The most notable disadvantage is typical execution speed compared to compiled languages.
- Interpreted languages were once known to be significantly slower than compiled languages. But, with the development of just-in-time compilation, that gap is shrinking.
Phases of Compilation
- Scanning:
- Parsing:
- Semantic analysis:
- Intermediate form :
- Optimization:
- Code generation phase :
Object-Oriented Paradigm
C++ Inheritance
https://www.w3schools.com/cpp/cpp_inheritance.asp
https://www.tutorialspoint.com/cplusplus/cpp_interfaces.htm
Difference Between Static and Dynamic Binding
https://techdifferences.com/difference-between-static-and-dynamic-binding.html
Reflection
A programming language that supports reflection allows its programs to have runtime access to their types and structure and to be able to dynamically modify their behavior
- The types and structure of a program are called
metadata
- The process of a program examining its metadata is called
introspection
- Interceding in the execution of a program is called
intercession
Uses of reflection for software tools:
- Class browsers need to enumerate the classes of a program
- Visual IDEs use type information to assist the developer in building type correct code
- Debuggers need to examine private fields and methods of classes
- Test systems need to know all of the methods of a class
Downsides of Reflection:
- Performance costs
- Exposes private fields and methods
- Voids the advantages of early type checking
- Some reflection code may not run under a security manager, making code nonportable
Reflection in Java
- Limited support from
java.lang.Class
- Java runtime instantiates an instance of
Class
for each object in the program
- The
getClass
method ofClass
returns theClass
object of an object
float[] totals = new float[100];
Class fltlist = totals.getClass();
Class stg = "hello".getClass();
- If there is no object, use class field:
Class stg = String.class;
- Class has four useful methods:
getMethod
searches for a specific public method of a classgetMethods
returns an array of all public methods of a classgetDeclaredMethod
searches for a specific method of a classgetDeclaredMethods
returns an array of all methods of a class- The
Method
class defines the invoke method, which is used to execute the method found bygetMethod
Some tutorials
Examples from Introduction to Programming Using Python 3
http://www.cs.armstrong.edu/liang/py/ExampleByChapters.html
C++ tutorial
http://www.cplusplus.com/doc/tutorial/program_structure/