Thursday 29 September 2016

Understanding the concepts of Functional Programming & Imperative Programming

Functional Programming

  • Functional programming is programming paradigm it's a style of coding in which most of the codes to be written in the from of functions.
  • In functional programming, we do everything with functions such as it takes something as input and gives an output. 
  • Functional programming is a form of declarative programming.
  • The functional programming paradigm was explicitly created to support a pure functional approach to problem solving.
  • Pure functional approach means a function that does not have side effects and also does not rely on the mutable state. In a simple word everything should reside inside the function such that when some change made to function it will have no side effects to the whole program. 
  • Easier testing and debugging. Because pure functions can more easily be tested in isolation, you can write test code that calls the pure function with typical values, valid edge cases, and invalid edge cases.
  • In functional approach, program flow control is based on Function calls, including recursion.

Advantages of Functional Programming

  • Bugs-Free Code
  • Efficient Parallel Programming
  • Better Performance
  • Better Encapsulation
  • Increase Reusability
  • Better Modularity
  • Increase Readability and Maintainability
  • Increase Testability
  • Robust & Reliable Code


Imperative Programming

  • Imperative Programming is one of the popular programming paradigms which executes a sequence of steps/instructions/statements in some order.
  •  In Imperative programming, you tell the computer what to do.Like "Computer , add x and y" or "Computer, do that do this" and the computer goes and does it.
  • An imperative language uses a sequence of statements to determine how to reach a certain goal. These statements are said to change the state of the program as each one is executed in turn.
  • In Imperative approach, primary flow control is based on Loops, conditionals, and function calls.
  • Examples of Imperative Programming are C, C++, JAVA etc.

Characteristics of Imperative Programming

  • Sequence of Statements.
  • Order of execution of Statements is very important.
  • They contain state.
  • They use both immutable and Mutable Data.
  • They can change state.
  • They may have Side-effects.
  • They directly change the state of Program.
  • They represent the state with Data Fields.

Example for both Functional and Imperative programming approach:


Imperative Approach:

A program to add a series of three numbers.

int total = 0;
int number1 = 5;
int number2 = 10;
int number3 = 15;
total = number1+number2+number3;

Functional Approach:

A program to add a series of three numbers.

int addSeries(int num1,int num2,int num3)
{
     int total = 0;
     int number1 = num1;
     int number2 = num2;
     int number3 = num3;
     total = number1+number2+number3;
     return total;
}

I hope by going through this simple example on functional and imperative programming approach will help you clear your doubts.

Tuesday 13 September 2016

Understanding the basic difference between Recursion & Iteration.

RECURSION

  1. Recursion - The process of calling a function by itself.
  2. Recursion uses selection structure.
  3. Infinite recursion occurs if the recursion step does not reduce the problem in a manner that converges on some condition.(base case)
  4. Recursion terminates when a base case is recognized.
  5. Recursion is usually slower than iteration due to the overhead of maintaining the stack.
  6. Recursion uses more memory than iteration.
  7. Infinite recursion can crash the system.
  8. Recursion makes code smaller.

ITERATION

  1. Iteration - these are loop-based repetitions of a process.
  2. Iteration uses repetition structure.
  3. An infinite loop occurs with iteration if the loop condition test never becomes false.
  4. Iteration terminates when the loop condition fails.
  5. Iteration does not use stack so it's faster than recursion.
  6. Iteration consumes less memory.
  7. Infinite uses CPU cycles repeatedly.
  8. Iteration makes the code longer.

Illustration of Recursion & Iteration:


Recursion Vs Iteration
Remember any recursive problem can be solved iteratively. But you can't solve all problems using recursion.

Friday 9 September 2016

Understanding Difference Between Static and Dynamic Websites.

Understanding Static Web Sites


  • A static website is stored on a server using HTTP server software
  • Client sends HTTP Request with a URL(Uniform Resource Locator)
  • Server locates and sends requested file as an HTTP Response
Static Websites Request-Response
  • The code & text for each Page is written out separately
  • Each Page is saved on the server, just like it is displayed
  • Changes must be made by hand in each Page's code

Understanding Dynamic Web Sites

Dynamic Websites Request-Response 
  • Application server is installed on the same server as HTTP server software
  • Client sends HTTP Request with a URL(Uniform Resource Locator)
  • HTTP Server dispatches request to application server 
  • Application server dynamically constructs HTTP response
  • Each websites Page does not actually exist anywhere
  • In one place is the look-and-feel/ layout of the website
  • In another place is the content of the website(text,photos)
  • When a user wants to see a Page, the server creates it on the fly  

As Dynamic Websites have more advantages than static one so most of the websites you are looking is a dynamic one.

To build a Dynamic Web Application the top three server scripting languages are:
  1. ASP.NETASP.NET is an open-source server-side web application framework designed for web development to produce dynamic web pages. It was developed by Microsoft to allow programmers to build dynamic websites, web applications, and web services.
  2. PHPPHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages.PHP is a widely-used, free, and efficient alternative to competitors such as Microsoft's ASP.
  3. JSPJavaServer Pages (JSP) is a server-side programming technology that enables the creation of dynamic, platform-independent method for building Web-based applications. JSP have access to the entire family of Java APIs, including the JDBC API to access enterprise databases.