SlideShare a Scribd company logo
Programming Paradigms ( http://www.directi.com  |  http://wiki.directi.com  |  http://careers.directi.com )‏ Licensed under Creative Commons Attribution Sharealike Noncommercial By, Janeve George [email_address] & Nilesh Mevada [email_address]
Creative Commons Sharealike Attributions Noncommercial Few Instruction It's a workshop not a presentation !!! Parking Lot Perks
Creative Commons Sharealike Attributions Noncommercial Aim of the session Introduction to programming concepts and techniques Differentiate between various programming paradigms Q: Why there are so many programming paradigms? A:  Q: Isn't there 'one language' that would suffice? A: Q: How can we deal with understanding so many paradigms? A:
Creative Commons Sharealike Attributions Noncommercial Flow of the session Programming Paradigm Definition Why bother about 'Programming Paradigms'? Appreciating 'Programming paradigms' Programming Concepts An Overview Eager and Lazy Evaluation Procedures Functions External and Internal State Concurrency Static vs Dynamic Typing Some Real-Life Problems Search (Java vs Prolog)‏ Higher Order Functions (Java vs Haskell)‏
Creative Commons Sharealike Attributions Noncommercial Flow of the session Programming Paradigm - Definition Why bother about 'Programming Paradigms'? Appreciating 'Programming paradigms' Programming Concepts An Overview Eager and Lazy Evaluation Procedures Functions External and Internal State Concurrency Static vs Dynamic Typing Some Real-Life Problems Search (Java vs Prolog)‏ Higher Order Functions (Java vs Haskell)‏
Creative Commons Sharealike Attributions Noncommercial Programming Paradigm - Definition What are Programming Paradigms? Fundamental style of computer programming. (wikipedia.org)‏ It serves as a pattern or model for a programming‏ language Function Oriented Object Oriented Logical Programming Java ML Haskell Prolog Mercury Oz Erlang Smalltalk
Creative Commons Sharealike Attributions Noncommercial Flow of the session Programming Paradigm - Definition Why bother about 'Programming Paradigms'? Appreciating 'Programming paradigms' Programming Concepts An Overview Eager and Lazy Evaluation Procedures Functions External and Internal State Concurrency Static vs Dynamic Typing Some Real-Life Problems Search (Java vs Prolog)‏ Higher Order Functions (Java vs Haskell)‏
Creative Commons Sharealike Attributions Noncommercial Why bother about 'Programming Paradigms'?
Creative Commons Sharealike Attributions Noncommercial Why bother about 'Programming Paradigms'?
Creative Commons Sharealike Attributions Noncommercial Why bother about 'Programming Paradigms'?
Creative Commons Sharealike Attributions Noncommercial Why bother about 'Programming Paradigms'? Tools (Programming Languages) may not suffice to deal with the real life problems. They might not support the solution at all or only partially.  Learning new programming languages becomes easier To bring innovations in programming technologies
Creative Commons Sharealike Attributions Noncommercial Flow of the session Programming Paradigm - Definition Why bother about 'Programming Paradigms'? Appreciating 'Programming paradigms' Programming Concepts An Overview Eager and Lazy Evaluation Procedures Functions External and Internal State Concurrency Static vs Dynamic Typing Some Real-Life Problems Search (Java vs Prolog)‏ Higher Order Functions (Java vs Haskell)‏
Creative Commons Sharealike Attributions Noncommercial Appreciating 'Programming paradigms' An example of how a trivial concept can affect/support a computation and hence a particular style of programming... Int X; Int Y = X; Print( Y ); Execution Flow ?
Creative Commons Sharealike Attributions Noncommercial Flow of the session Programming Paradigm - Definition Why bother about 'Programming Paradigms'? Appreciating 'Programming paradigms' Programming Concepts An Overview Eager and Lazy Evaluation Procedures Functions External and Internal State Concurrency Static vs Dynamic Typing Some Real-Life Problems Search (Java vs Prolog)‏ Higher Order Functions (Java vs Haskell)‏
Creative Commons Sharealike Attributions Noncommercial Programming Concepts – An Overview Set of  Programming Concepts Procedures Functions Higher/1 st  Order Evaluation Eager/Lazy Variables Single/Multi store Scope Scope of variables Typing State Internal/External Objects Classes Concurrency & on & on & on.....
Creative Commons Sharealike Attributions Noncommercial Programming Concepts – An Overview Subset of Concepts Programming Model Set of Programming Concepts Programming Language(s)‏ Embraced by Followed by Embraced by Followed by
Creative Commons Sharealike Attributions Noncommercial Programming Concepts – An Overview Subset of Concepts OO Programming Model Set of Programming Concepts OO Programming Language(s)‏ Embraced by Followed by Java Ruby Oz C++ Scala Etc... Objects Classes Inheritance Polymorphism Explicit State Etc... Embraced by Followed by
Creative Commons Sharealike Attributions Noncommercial Programming Concepts – An Overview Subset of Concepts Functional Programming Model Set of Programming Concepts Functional Programming Language(s)‏ Embraced by Followed by Lazy/Eager Evaluation Functions Higher Order Func. Etc... Haskell Erlang ML Scheme Etc... Embraced by Followed by
Creative Commons Sharealike Attributions Noncommercial Programming Concepts – An Overview
Creative Commons Sharealike Attributions Noncommercial Programming Concepts – An Overview
Creative Commons Sharealike Attributions Noncommercial Few important concepts Eager Evaluation Lazy Evaluation Procedures Functions External State Internal State Concurrency Static vs Dynamic Typing Programming Concepts – An Overview
Creative Commons Sharealike Attributions Noncommercial Programming Concepts – Eager Evaluation An expression which is evaluated as soon as it gets bound to a variable Importance Simple Commonly found  Easy implementation for languages Problems Expressions are always evaluated Languages supporting easy evaluation Almost all including java, c#, c, etc.
Creative Commons Sharealike Attributions Noncommercial Programming Concepts – Eager Evaluation .... List  Gen (  int   N ) { ArrayList list =  new  ArrayList(); list. add ( N ); list. addAll (  Gen (N+1) ); return  list; } void   myMethod  () { List K =  Gen (1); System.out. println ( "Elements: " + K. getElementAt ( 3 ) ); } ....
Creative Commons Sharealike Attributions Noncommercial Programming Concepts – Lazy Evaluation An expression is evaluated only when needed Also known as delayed evaluation or call-by-need. Importance To deal with potentially infinite data. Generally, calculations are not repeated. Problems Difficult at glance Difficult to predict time/space complexity Languages supporting Lazy Evaluation Haskell, Oz, Scheme, OCamel
Creative Commons Sharealike Attributions Noncommercial Programming Concepts – Lazy Evaluation declare fun lazy  { Gen  N}  N | { Gen  N+1} end declare  K = { Gen  1} { Browse  “Elements: ” + Nth K 3}
Creative Commons Sharealike Attributions Noncommercial Programming Concepts – Procedures A code construct which can  Execute a set of statements in an order Accept zero or more arguments Return zero or more results Produce a side effect Importance One of the most basic building block of any programming language A means of telling the system how to execute some behavior May be used as to abstract out functions, objects & classes Languages that support procedures C, C++, C#, Oz proc  { Max  X Y ?Z} if  X>=Y  then  Z=X  else  Z=Y  end end
Creative Commons Sharealike Attributions Noncommercial Programming Concepts – Procedures local  Default MaxOrDefault  in Default=10 proc  { MaxOrDefault  Arg ?Result} if  Arg >= Default  then   Result = Arg  else   Result = Default end end local   Result   in { MaxOrDefault  5 Result} { Browse  Result} end end
Creative Commons Sharealike Attributions Noncommercial Programming Concepts – Functions A code construct which can  Execute a set of statements in a given order Accept zero or more arguments Returns only one result and no side effect Pure functions avoid state and mutable data Importance A basic building block of many programming language A means of telling the system how to execute some behavior Can replicate a pure mathematical model Languages that support Functions Haskell, OCamel, ML, Oz fun  { Max  X Y} if  X>=Y  then  Z=X  else  Z=Y  end end Z = { Max  10, 20}
Creative Commons Sharealike Attributions Noncommercial Programming Concepts – Functions (Higher Order)‏ Higher Order Functions Accepts functions as arguments along with other types Can return a function as result Ordering means... 1st order  :- having no functions as args 2nd  order :- can have 1st order functions as args nth order :- can have n-1th order functions as args We can build abstraction using Higher Order Functions map  f  []  =  [] map  f (x:xs) = f x :  map  f xs numbers =  [ 7,9,13 ] inc  x = x  +  1 more_numbers =  map   inc  numbers
Creative Commons Sharealike Attributions Noncommercial Programming Concepts – Functions (Higher Order)‏ listsum   []  = 0 listsum  (x:xs) = x  +   listsum  xs listprod   []   = 1 listprod  (x:xs) = x  *   listprod  xs fold  op init  []  = init fold  op init (x:xs) = x  `op`   fold op init xs listsum  =  fold  (+) 0 listprod  =  fold  (*) 1
Creative Commons Sharealike Attributions Noncommercial Programming Concepts – External and Internal State Explicit State State remembrance across calls Importance One of the base concept for Object Orientation Implicit state Defined by the function for its internal calculations. Importance Storing temporary results which otherwise might require repetitive calls. Languages that support external state Object Oriented languages like Java, Smalltalk, etc Languages that have global variables Languages that support internal state All languages that have variables in procedures / functions
Creative Commons Sharealike Attributions Noncommercial Programming Concepts – External and Internal State fun  { Sum  Numbers} Result = { NewCell  0} Input = { NewCell  Numbers} proc  { Sum } case  @Input  of  nil  then skip [] X | Y  then Result := @Result + X Input := Y { Sum }  end end in { Sum } @Result end
Creative Commons Sharealike Attributions Noncommercial Programming Concepts – Concurrency Multiple and independent executions From real-life problems point of view, the definition adds this clause “and communicates only when needed” Importance relates more to real-life problems response time improved due to parallel executions Problems race condition Languages that support concurrent execution Java, Oz thread ConcurrentFlow1 = { GenerateNumbers  1 10} end
Creative Commons Sharealike Attributions Noncommercial Programming Concepts – Concurrency fun  { GenerateNumbers  FromArg ToArg} { Delay  100} if   FromArg > ToArg   then   nil else FromArg | { GenerateNumbers  FromArg+1 ToArg} end end thread   ConcurrentFlow1 = { GenerateNumbers  1 10} end thread ConcurrentFlow2 = { GenerateNumbers  11 20} end { Browse  ConcurrentFlow1} { Browse  ConcurrentFlow2}
Creative Commons Sharealike Attributions Noncommercial Programming Concepts – Concurrency .... public   void  main(String[] args)  throws   InterruptedException { Temp temp =  new   Temp(); createAConcurrentFlow(1, 10); createAConcurrentFlow(11, 20); } .... private   void  createAConcurrentFlow( int  FromArg,  int  ToArg) { new  Runnable() { public   void  run() { try   { new  Temp().GenerateNumbers(FromArg, ToArg); } catch  (InterruptedException e) {  } } }; } ....
Creative Commons Sharealike Attributions Noncommercial Programming Concepts – Static Typing Type checking is performed during compile-time Variables should be defined before they're used.  Variables can be cast into other types Variables don't get converted Importance Improved error-catching ability, efficiency, security partial program verification Problems reducing expressiveness of the programming language restrictions for the programmer on the programs he can write Languages that use static typing C, C++, C#, Java, ML, Pascal, Haskell
Creative Commons Sharealike Attributions Noncommercial Programming Concepts – Static Typing int  num, sum;  // explicit declaration num = 5;  // now use the variables sum = 10; sum = sum + num;
Creative Commons Sharealike Attributions Noncommercial Programming Concepts – Dynamic Typing Type checking is performed during runtime It's not necessary to define the variable before used Variables can be converted to other types implicitly Importance variables can be bound to any first-class-citizen in the lang. (proc, func, mix of data-types, etc.)‏ independent compilations of the program (since no type checking at compile time)‏ Problems more type-error-prone code at run-time. Languages that uses dynamic typing JavaScript, Lisp, Perl, PHP, Prolog, Python, Ruby
Creative Commons Sharealike Attributions Noncommercial Programming Concepts – Dynamic Typing foo() { x = 1; x = 'hello'; }
Creative Commons Sharealike Attributions Noncommercial Flow of the session Programming Paradigm Definition Why bother about 'Programming Paradigms'? Appreciating 'Programming paradigms' Programming Concepts An Overview Eager and Lazy Evaluation Procedures Functions External and Internal State Concurrency Static vs Dynamic Typing Some Real-Life Problems Search (Java vs Prolog)‏ Higher Order Functions (Java vs Haskell)‏
Creative Commons Sharealike Attributions Noncommercial Some Real-Life Problems – Prolog vs Java % % Facts % male(hrithik). male(shahrukh). male(salman). male(abhishek). male(akshay). male(aamir). female(diya). female(aishwarya). female(katrina). female(malaika). parent(hrithik,shahrukh). parent(hrithik,salman). parent(hrithik,diya). parent(shahrukh,abhishek). parent(shahrukh,akshay). parent(salman,aishwarya). parent(salman,katrina). parent(salman,aamir). parent(diya,malaika). % % Rules % father(X,Y) :- parent(X,Y), male(X). mother(X,Y) :- parent(X,Y), female(X). grandparent(X,Y) :- parent(X,Z), parent(Z,Y). paternalgrandfather(X,Y) :- father(X,Z), father(Z,Y). sibling(X,Y) :- parent(Z,X), parent(Z,Y). brothers(X,Y) :- sibling(X,Y),male(X),male(Y), \+ (X=Y). % % Queries % cmd: mother(diya,malaika) % Outupt: yes/no cmd: mother(Mother,Child). % Output: lists (mother,child) pair found in facts  % according to associations defined
Creative Commons Sharealike Attributions Noncommercial Some Real-Life Problems – Statistics
Creative Commons Sharealike Attributions Noncommercial How to approach Programming Paradigm? Our Way was... Concepts first, Languages Later. Other effective ways...  Mastering any one programming model (e.g. Object Oriented) and then comparing it with others (e.g. functional, procedural, etc.)‏
Creative Commons Sharealike Attributions Noncommercial References Books Concepts, Techniques & Models Of Computer Programming by Peter Van Roy & Seif Haridi Links On Web http://wikipedia.org http://www.infocheese.com/programmingparadigms.html
Creative Commons Sharealike Attributions Noncommercial What we expect post this session Experimentation with other programming languages Functional language -> Haskell / ML / Scheme Object Oriented language -> Java, C++, C#, Scala Aspect Oriented language -> AspectJ, AspectC++ Logic language -> Prolog / Mercury Mixed languages -> Scala, Oz Sharing your experiences with us... A testimonial “ I want to thank you and DIRECTI for conducting such a marvelous session and I am very much indebted for that.  I fell in love with LISP programming language and found that it was very much ideal for signal processing algos.  The approach u have suggested was just great and the book you have suggested was really really great.” - Chinni Krishna, Mukt '08 Session Attendee
Questions??? [email_address]  &  [email_address] http://directi.com http://careers.directi.com   Download slides:  http://wiki.directi.com
Retrospective!!! [email_address]  &  [email_address] http://directi.com http://careers.directi.com   Download slides:  http://wiki.directi.com

More Related Content

PDF
XKE - Programming Paradigms & Constructs
PPTX
Common Programming Paradigms
PPTX
Programming Paradigms Seminar 2
PPT
Programming Paradigms
PPTX
CS152 Programming Paradigm
DOC
Programming paradigms
PPTX
pebble - Building apps on pebble
PPT
Chapter1pp
XKE - Programming Paradigms & Constructs
Common Programming Paradigms
Programming Paradigms Seminar 2
Programming Paradigms
CS152 Programming Paradigm
Programming paradigms
pebble - Building apps on pebble
Chapter1pp

What's hot (18)

PDF
Presentation
PPTX
Prgramming paradigms
PPTX
Dart programming language
PPTX
Architecting Domain-Specific Languages
PPTX
Dart ppt
PDF
Programming Paradigms
PPTX
Programming Languages
PPTX
Programming paradigm
PDF
Dart the better Javascript 2015
PDF
Dart workshop
PPT
Andy On Closures
PPT
Agile development with Ruby
PDF
Programing paradigm & implementation
PPTX
Dart presentation
PPT
Concepts In Object Oriented Programming Languages
PDF
Implementing Higher-Kinded Types in Dotty
PDF
Domain specific languages and Scala
PPTX
Why functional programming in C# & F#
Presentation
Prgramming paradigms
Dart programming language
Architecting Domain-Specific Languages
Dart ppt
Programming Paradigms
Programming Languages
Programming paradigm
Dart the better Javascript 2015
Dart workshop
Andy On Closures
Agile development with Ruby
Programing paradigm & implementation
Dart presentation
Concepts In Object Oriented Programming Languages
Implementing Higher-Kinded Types in Dotty
Domain specific languages and Scala
Why functional programming in C# & F#
Ad

Similar to Programming Paradigms (20)

PDF
PL Lecture 01 - preliminaries
PDF
Google Interview Questions By Scholarhat
PPTX
PARADIGM IT.pptx
PDF
Shuzworld Analysis
PDF
C++ book
PPTX
Designing function families and bundles with java's behaviors parameterisatio...
PDF
Cognizant Interview Questions By ScholarHat.pdf
PPTX
Tools for the Toolmakers
PPTX
Introduction to Software - Coder Forge - John Mulhall
PDF
Programming for Problem Solving
PDF
Quick Intro to Clean Coding
PPTX
Javascript
PDF
So You Just Inherited a $Legacy Application...
PPTX
Modern_2.pptx for java
PPTX
Framework engineering JCO 2011
PDF
So You Just Inherited a $Legacy Application… NomadPHP July 2016
PDF
Core Java - OO Programming
PPTX
Programming paradigms Techniques_part2.pptx
PDF
(Costless) Software Abstractions for Parallel Architectures
PL Lecture 01 - preliminaries
Google Interview Questions By Scholarhat
PARADIGM IT.pptx
Shuzworld Analysis
C++ book
Designing function families and bundles with java's behaviors parameterisatio...
Cognizant Interview Questions By ScholarHat.pdf
Tools for the Toolmakers
Introduction to Software - Coder Forge - John Mulhall
Programming for Problem Solving
Quick Intro to Clean Coding
Javascript
So You Just Inherited a $Legacy Application...
Modern_2.pptx for java
Framework engineering JCO 2011
So You Just Inherited a $Legacy Application… NomadPHP July 2016
Core Java - OO Programming
Programming paradigms Techniques_part2.pptx
(Costless) Software Abstractions for Parallel Architectures
Ad

Recently uploaded (20)

PPTX
sap open course for s4hana steps from ECC to s4
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
cuic standard and advanced reporting.pdf
PPTX
Cloud computing and distributed systems.
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Encapsulation theory and applications.pdf
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Unlocking AI with Model Context Protocol (MCP)
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Empathic Computing: Creating Shared Understanding
sap open course for s4hana steps from ECC to s4
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
cuic standard and advanced reporting.pdf
Cloud computing and distributed systems.
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Advanced methodologies resolving dimensionality complications for autism neur...
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
“AI and Expert System Decision Support & Business Intelligence Systems”
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Encapsulation theory and applications.pdf
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
NewMind AI Weekly Chronicles - August'25 Week I
Building Integrated photovoltaic BIPV_UPV.pdf
Unlocking AI with Model Context Protocol (MCP)
20250228 LYD VKU AI Blended-Learning.pptx
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Empathic Computing: Creating Shared Understanding

Programming Paradigms

  • 1. Programming Paradigms ( http://www.directi.com | http://wiki.directi.com | http://careers.directi.com )‏ Licensed under Creative Commons Attribution Sharealike Noncommercial By, Janeve George [email_address] & Nilesh Mevada [email_address]
  • 2. Creative Commons Sharealike Attributions Noncommercial Few Instruction It's a workshop not a presentation !!! Parking Lot Perks
  • 3. Creative Commons Sharealike Attributions Noncommercial Aim of the session Introduction to programming concepts and techniques Differentiate between various programming paradigms Q: Why there are so many programming paradigms? A: Q: Isn't there 'one language' that would suffice? A: Q: How can we deal with understanding so many paradigms? A:
  • 4. Creative Commons Sharealike Attributions Noncommercial Flow of the session Programming Paradigm Definition Why bother about 'Programming Paradigms'? Appreciating 'Programming paradigms' Programming Concepts An Overview Eager and Lazy Evaluation Procedures Functions External and Internal State Concurrency Static vs Dynamic Typing Some Real-Life Problems Search (Java vs Prolog)‏ Higher Order Functions (Java vs Haskell)‏
  • 5. Creative Commons Sharealike Attributions Noncommercial Flow of the session Programming Paradigm - Definition Why bother about 'Programming Paradigms'? Appreciating 'Programming paradigms' Programming Concepts An Overview Eager and Lazy Evaluation Procedures Functions External and Internal State Concurrency Static vs Dynamic Typing Some Real-Life Problems Search (Java vs Prolog)‏ Higher Order Functions (Java vs Haskell)‏
  • 6. Creative Commons Sharealike Attributions Noncommercial Programming Paradigm - Definition What are Programming Paradigms? Fundamental style of computer programming. (wikipedia.org)‏ It serves as a pattern or model for a programming‏ language Function Oriented Object Oriented Logical Programming Java ML Haskell Prolog Mercury Oz Erlang Smalltalk
  • 7. Creative Commons Sharealike Attributions Noncommercial Flow of the session Programming Paradigm - Definition Why bother about 'Programming Paradigms'? Appreciating 'Programming paradigms' Programming Concepts An Overview Eager and Lazy Evaluation Procedures Functions External and Internal State Concurrency Static vs Dynamic Typing Some Real-Life Problems Search (Java vs Prolog)‏ Higher Order Functions (Java vs Haskell)‏
  • 8. Creative Commons Sharealike Attributions Noncommercial Why bother about 'Programming Paradigms'?
  • 9. Creative Commons Sharealike Attributions Noncommercial Why bother about 'Programming Paradigms'?
  • 10. Creative Commons Sharealike Attributions Noncommercial Why bother about 'Programming Paradigms'?
  • 11. Creative Commons Sharealike Attributions Noncommercial Why bother about 'Programming Paradigms'? Tools (Programming Languages) may not suffice to deal with the real life problems. They might not support the solution at all or only partially. Learning new programming languages becomes easier To bring innovations in programming technologies
  • 12. Creative Commons Sharealike Attributions Noncommercial Flow of the session Programming Paradigm - Definition Why bother about 'Programming Paradigms'? Appreciating 'Programming paradigms' Programming Concepts An Overview Eager and Lazy Evaluation Procedures Functions External and Internal State Concurrency Static vs Dynamic Typing Some Real-Life Problems Search (Java vs Prolog)‏ Higher Order Functions (Java vs Haskell)‏
  • 13. Creative Commons Sharealike Attributions Noncommercial Appreciating 'Programming paradigms' An example of how a trivial concept can affect/support a computation and hence a particular style of programming... Int X; Int Y = X; Print( Y ); Execution Flow ?
  • 14. Creative Commons Sharealike Attributions Noncommercial Flow of the session Programming Paradigm - Definition Why bother about 'Programming Paradigms'? Appreciating 'Programming paradigms' Programming Concepts An Overview Eager and Lazy Evaluation Procedures Functions External and Internal State Concurrency Static vs Dynamic Typing Some Real-Life Problems Search (Java vs Prolog)‏ Higher Order Functions (Java vs Haskell)‏
  • 15. Creative Commons Sharealike Attributions Noncommercial Programming Concepts – An Overview Set of Programming Concepts Procedures Functions Higher/1 st Order Evaluation Eager/Lazy Variables Single/Multi store Scope Scope of variables Typing State Internal/External Objects Classes Concurrency & on & on & on.....
  • 16. Creative Commons Sharealike Attributions Noncommercial Programming Concepts – An Overview Subset of Concepts Programming Model Set of Programming Concepts Programming Language(s)‏ Embraced by Followed by Embraced by Followed by
  • 17. Creative Commons Sharealike Attributions Noncommercial Programming Concepts – An Overview Subset of Concepts OO Programming Model Set of Programming Concepts OO Programming Language(s)‏ Embraced by Followed by Java Ruby Oz C++ Scala Etc... Objects Classes Inheritance Polymorphism Explicit State Etc... Embraced by Followed by
  • 18. Creative Commons Sharealike Attributions Noncommercial Programming Concepts – An Overview Subset of Concepts Functional Programming Model Set of Programming Concepts Functional Programming Language(s)‏ Embraced by Followed by Lazy/Eager Evaluation Functions Higher Order Func. Etc... Haskell Erlang ML Scheme Etc... Embraced by Followed by
  • 19. Creative Commons Sharealike Attributions Noncommercial Programming Concepts – An Overview
  • 20. Creative Commons Sharealike Attributions Noncommercial Programming Concepts – An Overview
  • 21. Creative Commons Sharealike Attributions Noncommercial Few important concepts Eager Evaluation Lazy Evaluation Procedures Functions External State Internal State Concurrency Static vs Dynamic Typing Programming Concepts – An Overview
  • 22. Creative Commons Sharealike Attributions Noncommercial Programming Concepts – Eager Evaluation An expression which is evaluated as soon as it gets bound to a variable Importance Simple Commonly found Easy implementation for languages Problems Expressions are always evaluated Languages supporting easy evaluation Almost all including java, c#, c, etc.
  • 23. Creative Commons Sharealike Attributions Noncommercial Programming Concepts – Eager Evaluation .... List Gen ( int N ) { ArrayList list = new ArrayList(); list. add ( N ); list. addAll ( Gen (N+1) ); return list; } void myMethod () { List K = Gen (1); System.out. println ( "Elements: " + K. getElementAt ( 3 ) ); } ....
  • 24. Creative Commons Sharealike Attributions Noncommercial Programming Concepts – Lazy Evaluation An expression is evaluated only when needed Also known as delayed evaluation or call-by-need. Importance To deal with potentially infinite data. Generally, calculations are not repeated. Problems Difficult at glance Difficult to predict time/space complexity Languages supporting Lazy Evaluation Haskell, Oz, Scheme, OCamel
  • 25. Creative Commons Sharealike Attributions Noncommercial Programming Concepts – Lazy Evaluation declare fun lazy { Gen N} N | { Gen N+1} end declare K = { Gen 1} { Browse “Elements: ” + Nth K 3}
  • 26. Creative Commons Sharealike Attributions Noncommercial Programming Concepts – Procedures A code construct which can Execute a set of statements in an order Accept zero or more arguments Return zero or more results Produce a side effect Importance One of the most basic building block of any programming language A means of telling the system how to execute some behavior May be used as to abstract out functions, objects & classes Languages that support procedures C, C++, C#, Oz proc { Max X Y ?Z} if X>=Y then Z=X else Z=Y end end
  • 27. Creative Commons Sharealike Attributions Noncommercial Programming Concepts – Procedures local Default MaxOrDefault in Default=10 proc { MaxOrDefault Arg ?Result} if Arg >= Default then Result = Arg else Result = Default end end local Result in { MaxOrDefault 5 Result} { Browse Result} end end
  • 28. Creative Commons Sharealike Attributions Noncommercial Programming Concepts – Functions A code construct which can Execute a set of statements in a given order Accept zero or more arguments Returns only one result and no side effect Pure functions avoid state and mutable data Importance A basic building block of many programming language A means of telling the system how to execute some behavior Can replicate a pure mathematical model Languages that support Functions Haskell, OCamel, ML, Oz fun { Max X Y} if X>=Y then Z=X else Z=Y end end Z = { Max 10, 20}
  • 29. Creative Commons Sharealike Attributions Noncommercial Programming Concepts – Functions (Higher Order)‏ Higher Order Functions Accepts functions as arguments along with other types Can return a function as result Ordering means... 1st order :- having no functions as args 2nd order :- can have 1st order functions as args nth order :- can have n-1th order functions as args We can build abstraction using Higher Order Functions map f [] = [] map f (x:xs) = f x : map f xs numbers = [ 7,9,13 ] inc x = x + 1 more_numbers = map inc numbers
  • 30. Creative Commons Sharealike Attributions Noncommercial Programming Concepts – Functions (Higher Order)‏ listsum [] = 0 listsum (x:xs) = x + listsum xs listprod [] = 1 listprod (x:xs) = x * listprod xs fold op init [] = init fold op init (x:xs) = x `op` fold op init xs listsum = fold (+) 0 listprod = fold (*) 1
  • 31. Creative Commons Sharealike Attributions Noncommercial Programming Concepts – External and Internal State Explicit State State remembrance across calls Importance One of the base concept for Object Orientation Implicit state Defined by the function for its internal calculations. Importance Storing temporary results which otherwise might require repetitive calls. Languages that support external state Object Oriented languages like Java, Smalltalk, etc Languages that have global variables Languages that support internal state All languages that have variables in procedures / functions
  • 32. Creative Commons Sharealike Attributions Noncommercial Programming Concepts – External and Internal State fun { Sum Numbers} Result = { NewCell 0} Input = { NewCell Numbers} proc { Sum } case @Input of nil then skip [] X | Y then Result := @Result + X Input := Y { Sum } end end in { Sum } @Result end
  • 33. Creative Commons Sharealike Attributions Noncommercial Programming Concepts – Concurrency Multiple and independent executions From real-life problems point of view, the definition adds this clause “and communicates only when needed” Importance relates more to real-life problems response time improved due to parallel executions Problems race condition Languages that support concurrent execution Java, Oz thread ConcurrentFlow1 = { GenerateNumbers 1 10} end
  • 34. Creative Commons Sharealike Attributions Noncommercial Programming Concepts – Concurrency fun { GenerateNumbers FromArg ToArg} { Delay 100} if FromArg > ToArg then nil else FromArg | { GenerateNumbers FromArg+1 ToArg} end end thread ConcurrentFlow1 = { GenerateNumbers 1 10} end thread ConcurrentFlow2 = { GenerateNumbers 11 20} end { Browse ConcurrentFlow1} { Browse ConcurrentFlow2}
  • 35. Creative Commons Sharealike Attributions Noncommercial Programming Concepts – Concurrency .... public void main(String[] args) throws InterruptedException { Temp temp = new Temp(); createAConcurrentFlow(1, 10); createAConcurrentFlow(11, 20); } .... private void createAConcurrentFlow( int FromArg, int ToArg) { new Runnable() { public void run() { try { new Temp().GenerateNumbers(FromArg, ToArg); } catch (InterruptedException e) { } } }; } ....
  • 36. Creative Commons Sharealike Attributions Noncommercial Programming Concepts – Static Typing Type checking is performed during compile-time Variables should be defined before they're used. Variables can be cast into other types Variables don't get converted Importance Improved error-catching ability, efficiency, security partial program verification Problems reducing expressiveness of the programming language restrictions for the programmer on the programs he can write Languages that use static typing C, C++, C#, Java, ML, Pascal, Haskell
  • 37. Creative Commons Sharealike Attributions Noncommercial Programming Concepts – Static Typing int num, sum; // explicit declaration num = 5; // now use the variables sum = 10; sum = sum + num;
  • 38. Creative Commons Sharealike Attributions Noncommercial Programming Concepts – Dynamic Typing Type checking is performed during runtime It's not necessary to define the variable before used Variables can be converted to other types implicitly Importance variables can be bound to any first-class-citizen in the lang. (proc, func, mix of data-types, etc.)‏ independent compilations of the program (since no type checking at compile time)‏ Problems more type-error-prone code at run-time. Languages that uses dynamic typing JavaScript, Lisp, Perl, PHP, Prolog, Python, Ruby
  • 39. Creative Commons Sharealike Attributions Noncommercial Programming Concepts – Dynamic Typing foo() { x = 1; x = 'hello'; }
  • 40. Creative Commons Sharealike Attributions Noncommercial Flow of the session Programming Paradigm Definition Why bother about 'Programming Paradigms'? Appreciating 'Programming paradigms' Programming Concepts An Overview Eager and Lazy Evaluation Procedures Functions External and Internal State Concurrency Static vs Dynamic Typing Some Real-Life Problems Search (Java vs Prolog)‏ Higher Order Functions (Java vs Haskell)‏
  • 41. Creative Commons Sharealike Attributions Noncommercial Some Real-Life Problems – Prolog vs Java % % Facts % male(hrithik). male(shahrukh). male(salman). male(abhishek). male(akshay). male(aamir). female(diya). female(aishwarya). female(katrina). female(malaika). parent(hrithik,shahrukh). parent(hrithik,salman). parent(hrithik,diya). parent(shahrukh,abhishek). parent(shahrukh,akshay). parent(salman,aishwarya). parent(salman,katrina). parent(salman,aamir). parent(diya,malaika). % % Rules % father(X,Y) :- parent(X,Y), male(X). mother(X,Y) :- parent(X,Y), female(X). grandparent(X,Y) :- parent(X,Z), parent(Z,Y). paternalgrandfather(X,Y) :- father(X,Z), father(Z,Y). sibling(X,Y) :- parent(Z,X), parent(Z,Y). brothers(X,Y) :- sibling(X,Y),male(X),male(Y), \+ (X=Y). % % Queries % cmd: mother(diya,malaika) % Outupt: yes/no cmd: mother(Mother,Child). % Output: lists (mother,child) pair found in facts % according to associations defined
  • 42. Creative Commons Sharealike Attributions Noncommercial Some Real-Life Problems – Statistics
  • 43. Creative Commons Sharealike Attributions Noncommercial How to approach Programming Paradigm? Our Way was... Concepts first, Languages Later. Other effective ways... Mastering any one programming model (e.g. Object Oriented) and then comparing it with others (e.g. functional, procedural, etc.)‏
  • 44. Creative Commons Sharealike Attributions Noncommercial References Books Concepts, Techniques & Models Of Computer Programming by Peter Van Roy & Seif Haridi Links On Web http://wikipedia.org http://www.infocheese.com/programmingparadigms.html
  • 45. Creative Commons Sharealike Attributions Noncommercial What we expect post this session Experimentation with other programming languages Functional language -> Haskell / ML / Scheme Object Oriented language -> Java, C++, C#, Scala Aspect Oriented language -> AspectJ, AspectC++ Logic language -> Prolog / Mercury Mixed languages -> Scala, Oz Sharing your experiences with us... A testimonial “ I want to thank you and DIRECTI for conducting such a marvelous session and I am very much indebted for that. I fell in love with LISP programming language and found that it was very much ideal for signal processing algos. The approach u have suggested was just great and the book you have suggested was really really great.” - Chinni Krishna, Mukt '08 Session Attendee
  • 46. Questions??? [email_address] & [email_address] http://directi.com http://careers.directi.com Download slides: http://wiki.directi.com
  • 47. Retrospective!!! [email_address] & [email_address] http://directi.com http://careers.directi.com Download slides: http://wiki.directi.com