Tute 1 Answers

1. Compare and contrast declarative and imperative paradigms?

 A programming paradigms is a style, or “way,” of programming.

Declarative Paradigms

Declarative is a programming paradigm, that expresses the logic of a computation without describing its control. Programming by specifying the result you want, not how to get it.

example : -
var results = collection.Where( num => num % 2 != 0);
Imperative Paradigms
Imperative programming is a programming paradigm that uses statements that change a program’s state. Programming with an explicit sequence of commands that update state.

example:-
List<int> collection = new List<int> { 1, 2, 3, 4, 5 };List<int> results = new List<int>();foreach(var num in collection){ if (num % 2 != 0) results.Add(num);}

2. Discuss the difference between procedural programming and functional programming?

Functional programming is a programming paradigm   a style of building the structure and elements of computer programs  that treats computation as the evaluation of mathematical functions and avoids changing-state and mutable data.
example:-
pure int factorial( invariant int n ){
  if( n <= 1 ){
    return 1;
  }else{
    return n * factorial( n-1 );
  }
}
Procedural programming is a programming paradigm, derived from structured programming, based upon the concept of the procedure call. Procedures, also known as routines, subroutines, or functions (not to be confused with mathematical functions, but similar to those used in functional programming), simply contain a series of computational steps to be carried out.
example:-
int factorial( int n ){
  int result = 1;
  for( ; n > 0 ; n-- ){
    result *= n;
  }
  return result;
}



3. Explain the Lambda calculus and Lambda expressions in functional programming. 


Lambda calculus

Functional programming languages are based on the lambda-calculus. The lambda-calculus grew out of an attempt by Alonzo Church and Stephen Kleene in the early 1930s to formalize the notion of computability (also known as constructibility and effective calculability). It is a formalization of the notion of functions as rules (as opposed to functions as tuples). As with mathematical expressions, it is characterized by the principle that the value of an expression depends only on the values of its subexpressions. The lambda-calculus is a simple language with few constructs and a simple semantics. But, it is expressive; it is sufficiently powerful to express all computable functions.
As an informal example of the lambda-calculus, consider the function defined by the polynomial expression


x2 + 3x - 5.
λx.(x2+ 3x - 5)
λx. (- (+ (* x x) (* 3 x)) 5).
λx.((- ((+ ((* x) x)) ((* 3) x))) 5)
f a
λx.((- ((+ ((* x) x)) ((* 3) x))) 5) 1.
((- ((+ ((* 1) 1)) ((* 3) 1))) 5)
((- ((+ 1) 3)) 5)
((- 4) 5)
-1.


The variable x is a parameter. In the lambda-calculus, the notation λx.M is used to denote a function with parameter x and body M. That is, x is mapped to M. We rewrite our function in this format
and read it as ``the function of x whose value is defined by x2 + 3x - 5''. The lambda-calculus uses prefix form and so we rewrite the body in prefix form,
The lambda-calculus curries its functions of more than one variable i.e. (+ x y) is written as ((+ x) y), the function (+ x) is the function which adds something to x. Rewriting our example in this form we get:
To denote the application of a function f to an argument a we write
To apply our example to the value 1 we write
To evaluate the function application, we remove the λx. and replace each remaining occurence of x with 1 to get
then evaluate the two multiplication expressions
then the addition
and finally the subtraction

Lambda expressions
Lambda expressions (or lambda functions) are essentially blocks of code that can be assigned to variables, passed as an argument, or returned from a function call, in languages that support high-order functions. They have been part of programming languages for quite some time. Some examples include Smalltalk, Lisp, Ruby, Scala, Python, and, more recently, Java and JavaScript. Here are some 
examples:
Python:
square = lambda x: x**2
square(6) //-> 36


4. What is meant by “no side-effects” and “referential transparency” in functional programming? 


no side-effects

Functional programming includes many different techniques. Some techniques are fine with side effects. But one important aspect is  If I call a function on the same value, I always get the same result. So I can substitute a function call with the return value, and get equivalent behaviour. This makes it easier to reason about the program, especially when debugging.
Should the function have side effects, this doesn't quite hold. The return value is not equivalent to the function call, because the return value doesn't contain the side effects.
The solution is to stop using side effects and encoding these effects in the return value. Different languages have different effect systems. E.g. Haskell uses monads to encode certain effects such as IO or State mutation. The C/C++/Rust languages have a type system that can disallow mutation of some values.
In an imperative language, a print("foo") function will print something and return nothing. In a pure functional language like Haskell, a print function also takes an object representing the state of the outside world, and returns a new object representing the state after having performed this output. Something similar to newState = print "foo" oldState. I can create as many new states from the old state as I like. However, only one will ever be used by the main function. So I need to sequence the states from multiple actions by chaining the functions. To print foo bar, I might say something like print "bar" (print "foo" originalState).
If an output state is not used, Haskell doesn't perform the actions leading up to that state, because it is a lazy language. Conversely, this laziness is only possible because all effects are explicitly encoded as return values.
Note that Haskell is the only commonly used functional language that uses this route. Other functional languages incl. the Lisp family, ML family, and newer functional languages like Scala discourage but allow still side effects – they could be called imperative–functional languages.
Using side effects for I/O is probably fine. Often, I/O (other than logging) is only done at the outer boundary of your system. No external communication happens within your business logic. It is then possible to write the core of your software in a pure style, while still performing impure I/O in an outer shell. This also means that the core can be stateless.
Statelessness has a number of practical advantages, such as increased reasonability and scalability. This is very popular for web application backends. Any state is kept outside, in a shared database. This makes load balancing easy: I don't have to stick sessions to a specific server. What if I need more servers? Just add another, because it's using the same database. What if one server crashes? I can redo any pending requests on another server. Of course, there still is state – in the database. But I've made it explicit and extracted it, and could use a pure functional approach internally if I want to.

Referential transparency 

Referential transparency is a property of a specific part of a program or a programming language, especially functional programming languages like Haskell and R. An expression in a program is said to be referentially transparent if it can be replaced with its value and the resulting behavior is the same as before the change. This means that the program's behavior is not changed whether the input used is a reference or an actual value that the reference is pointing to.

Referential transparency has its roots in analytical philosophy, which is a branch of philosophy that studies natural language constructs, arguments and statements based on the methods of mathematics and logic and has little to do with programming, although it has been adopted by computer scientists.
The concept is simple, the "referent," the thing that an expression refers to, can be used to substitute the "referrer" without changing the meaning of the expression. For example, the statement "Luke's father is an evil man," "Luke's father" references "Darth Vader" in Star Wars lore. So the statement is referentially transparent since "Luke's father" can be replaced at any time with "Darth Vader" and the statement would not change in meaning. However, in the statement "the audience did not know until 'The Empire Strikes Back' that Luke's father is actually Darth Vader" is not a referentially transparent expression since if "Luke's father" is replaced with "Darth Vader" the expression becomes "the audience did not know until 'The Empire Strikes Back' that Darth Vader is actually Darth Vader," which has an entirely different meaning.
In relation to programming, the concept is at first glance the same, but many philosophers disagree that the concept is implemented or carried over well in programming languages. But in general programming, this simply means that an expression can be replaced by its resulting value without having an effect on the program's behavior. For example, the function plusOne(x) simply adds one to whatever the value of x is, so if we know that x = 5 then we can safely replace the function with the value 6 in an expression which yields the same behavior when using plusOne(x). But if there is an external variable within the expression that is controlled externally, say in the function plusY(x) where Y within the function is externally controlled, the resulting behavior may not be the same — in this case this is not a referentially transparent expression.

5. Discuss the key features of Object Oriented Programming.

 key features of Object Oriented Programming

Objects:
Objects are the basic run-time entities in an object-oriented programming. They may represents a person, a place, a bank account, a table of data or any item that the program has to handle. They may also represents user-defined data such as vector, time and lists. When the program is executed, the object interact by sending message to one another.
Classes:
Objects contain data, and code to manipulate that data. The entire set of data and code of an object can be made a user-defined data type with the help of class. In fact, objects are variable of the type class. Once a class has been defined, we can create a number of objects belonging to that class. A class is a collection of objects of similar type.
Ex. Fruit mango;
Data Abstraction:
Abstractions refer to the act of representing essential features without including background details or explanation. They are commonly known as Abstraction Data Type(ADT).
Encapsulation:
The wrapping up of data and functions into single unit is known as encapsulation. Data encapsulation is a striking feature of a class. The data is not accessible to the outside world, and only those functions which are wrapped in the class can access it. These functions provide the interface between the object's data and the program.
Inheritance:
Inheritance is the process by which objects of one class acquire the properties of object of another class. The class whose members are inherited is called the Base class and the class that inherits those members is called Derived class. It supports class of hierarchical classification.
The concept of inheritance provides the ideas of reusability. This means we can add essential features to an exciting class without modifying it.
Polymorphism:
Polymorphism is another OOP concept. Polymorphism means the ability to take more than one form. An operation may exhibit different behaviors at different instances.

6. How the event-driven programming is different from other programming paradigms? 

  • Object Oriented Programming (OOP) and Event-Driven Programming (EDP) are orthogonal, which means that they can be used together.
  • In OOP with EDP all OOP principles (encapsulation, inheritance and polymorphism) stay intact.
  • In OOP with EDP objects acquire some mechanism of publishing event notifications and subscribing to event notifications from other objects.

The difference between OOP with / without EDP is control flow between objects.


  • In OOP without EDP control moves from one object to another object on a method call. Object mainly invokes methods of other objects.
  • In OOP with EDP control moves from one object to another object on event notification. Object subscribes on notifications from other objects, then waits for notifications from the objects it is subscribed on, does some work based on notification and publishes it's own notifications.


Conclusion: OOP+EDP is "exactly our old friend OOP" with control flow inverted thanks to Event-Driven Design.


7. Compare and contrast the Compiled languages, Scripting languages, and Markup languages. 

COMPILED LANGUAGE

Compiled language is similar to programming language.A programming language is the proper and formal language that has been designed to allow programmers to communicate instructions to a computer. Programming language is used to create programs.
Programming language is used to transform data by creating CPU instruction that will rewrite the input data into the desired output. This is a language that encodes programs, meaning that a word in the language can be interpreted as a sequence of actions.

MARKUP LANGUAGE

This is debatable, but markup language is not considered to be a programming language simply because the term is not well-defined. A markup language is used to control the presentation of the data, like representing structured data. For example, HTML is used to specify that some part of a document is a title, another part is a list, another part is heading etc. So, based off of that, a markup language is used to describe the data and the formatting in a textual format. There is a general rule, that a markup language will not describe a process or an algorithm (like programming language does) but is just pure data.

SCRIPTING LANGUAGE

A scripting language is a subset of programming languages that is used to mediate between programs in order to generate data. The main feature of scripting languages is that it can guide other programs, much like a script that will give an actor/actress their cue to start his/her part. It is a language that is meant to be interpreted, rather than compiled, emphasizing its purpose as a subset of all programming languages. Some may define it as a programming language that support scripts (which is written to control other programs). Therefore, scripting language is written to control another program or programs, and sometimes take a longer time to run, since the script must be interpreted first and then run into a supporting system.


8. Discuss the role of the virtual runtime machines. 

The virtual machine function is a function for the realization of virtual machine environment. This function enables you to create multiple independent virtual machines on one physical machine by virtualization resources such as the CPU, memory, network and disk that are installed on a physical machine.
The function is made up of one host OS and multiple guest OSes.

9. Find how the JS code is executed (What is the runtime? where do you find the interpreter?)

Runtime 
A software program needs to execute, and to do that it needs an environment to run in. The runtime environment loads class files and ensures there is access to memory and other system resources to run them. In the past, most software used the operating system (OS) as its runtime environment. The program ran inside whatever computer it was on, but relied on operating system settings for resource access. Resources in this case would be things like memory and program files and dependencies. The Java Runtime Environment changed all that, at least for Java programs.

Where do you find the interpreter

A compiler is a program that reads in as input a program (in some high-level programming language) and outputs machine language code (for some machine architecture). The machine language code can subsequently be executed any number of times using different input data each time. As an example, the Unix program g++transforms a C++ source file into a machine executable file a.out which can be run natively on Sparc microprocessors. As a second example, the Java compiler javac transforms a .java source file into a .class file that is written in Java bytecode, which is the machine language for an imaginary machine known as the Java Virtual Machine.

10. Explain how the output of an HTML document is rendered, indicating the tools used to display the output.

The HTML is the most popular mark-up language.Now it has newer version .So any one who love to build a simple web page ,should have a knowledge in HTML. This is how the rendering works in html.This is a one of a good explanation that found on the internet. Software that renders HTML pages (Web pages). It turns the HTML layout tags in the page into the appropriate commands for the operating system, which causes the formation of the text characters and images for screen and printer. Also called a "layout engine," a rendering engine is used by a Web browser to render HTML pages, by mail programs that render HTML email messages, as well as any other application that needs to render Web page content. For example, Trident is the rendering engine for Microsoft's Internet Explorer, and Gecko is the engine in Firefox. Trident and Gecko are also incorporated into other browsers and applications. Following is a sampling of browsers and rendering engines.


11. Identify different types of CASE tools, Workbenches, and Environments for different types of software systems (web-based systems, mobile systems, IoT systems, etc.). 

Types of CASE tools

Classic CASE tools - established software development support tools (e.g. interactive debuggers, compilers, etc.)
Real CASE tools - can be separated into three different categories, depending on where in the development process they are most involved in:
  • Upper - support analysis and design phases
  • Lower - support coding phase
  • Integrated - also known as I-CASE support analysis, design and coding phases
Upper and lower CASE tools are named as such because of where the phases they support are in the Waterfall Model 

Types of workbenches.
  • Business planning and modeling.
  • Analysis and design.
  • User-interface development.
  • Programming.
  • Verification and validation.
  • Maintenance and reverse engineering.
  • Configuration management.
  • Project management.

    Types of Environments.
    • The Analysis and Design Environment.
    • The Development Environment.
    • The Common Build Environment.
    • The Testing Environment: This has two components: The Systems Integration Testing Environment. The User Acceptance Testing Environment.
    • The Production Environment.

    12. Discuss the difference between framework, library, and plugin, giving some examples.     

    Library:

    It is just a collection of routines (functional programming) or class definitions(object oriented programming). The reason behind is simply code reuse, i.e. get the code that has already been written by other developers. The classes or routines normally define specific operations in a domain specific area. For example, there are some libraries of mathematics which can let developer just call the function without redo the implementation of how an algorithm works.

    Framework:

    In framework, all the control flow is already there, and there are a bunch of predefined white spots that we should fill out with our code. A framework is normally more complex. It defines a skeleton where the application defines its own features to fill out the skeleton. In this way, your code will be called by the framework when appropriately. The benefit is that developers do not need to worry about if a design is good or not, but just about implementing domain specific functions.

    Plugin:

     A utility build for a library (ui-router -> AngularJS) or many libraries in combination (date-picker -> bootstrap.css + jQuery) without which your plugin might now work as expected.





    Comments

    Popular posts from this blog

    Tute 3 Answers

    tute 4

    tute 9