SlideShare une entreprise Scribd logo
1  sur  32
Télécharger pour lire hors ligne
Programming Paradigms
Bhavin Kamani
Cuisine
Music Genre
Imperative Programming
Instructional
Command
Variable State
Conditions
Loops
Direct
Efficient
Inflexible
Side Effects
Assembly, C
COBOL, Visual Basic
Object Oriented
Programming
Abstraction
Maintainibility
Learning Curve
Over Engineering
C++, Java, C#
Ruby, Python
Declarative Programming
"What" instead of "How"
Reduced Side effects
Order of statements not crucial
Domain Specific Languages
SQL
Domain Specific Languages
Regular Expression
Functional Programming
Composability
Concurrency
Learning Curve
Main stream support
LISP, Haskell, Erlang
Closure, Scala, F#
Multi-Paradigm Programming
http://www.99-bottles-of-beer.net
JavaScript
Lyrics
99 bottles of beer on the wall, 99 bottles of beer.
Take one down and pass it around, 98 bottles of beer on the wall.
98 bottles of beer on the wall, 98 bottles of beer.
Take one down and pass it around, 97 bottles of beer on the wall.
97 bottles of beer on the wall, 97 bottles of beer.
Take one down and pass it around, 96 bottles of beer on the wall.
--------------------------------------------------------------------------
--------------------------------------------------------------------------
1 bottle of beer on the wall, 1 bottle of beer.
Take one down and pass it around, no more bottles of beer on the wall.
No more bottles of beer on the wall, no more bottles of beer.
Go to the store and buy some more, 99 bottles of beer on the wall.
Imperative Style
var lyrics = [];
for (var bottles = 99; bottles > 0; bottles--) {
lyrics.push(bottles + " bottles of beer on the wall, "
+ bottles + " bottles of beer");
var next_bottles = ((bottles-1) == 0 ? "no more" : (bottles-1));
lyrics.push("Take one down and pass it around, "
+ next_bottles + " bottles of beer on the wall.");
}
var zero_bottle = "No more";
lyrics.push(zero_bottle + " bottles of beer on the wall, "
+ zero_bottle + " bottles of beer");
lyrics.push("Go to the store and buy some more, "
+ "99 bottles of beer on the wall.");
document.writeln(lyrics.join("<BR>"));
Object-Oriented Style
varBottleSong=function(num_bottles,stanza){
this.num_bottles=num_bottles;
this.stanza=stanza;
};
BottleSong.prototype={
sing:function(separator){
varbeer_form="bottlesofbeer";
for(varbottles=this.num_bottles;bottles>0;bottles--){
this.stanza.addLine(bottles+beer_form+"onthewall,"+bottles+beer_form);
varnext_bottles=((bottles-1)==0?"nomore":(bottles-1));
this.stanza.addLine("Takeonedownandpassitaround,"+next_bottles+beer_form+"onthewall.");
}
varzero_bottle="Nomore";
this.stanza.addLine(zero_bottle+beer_form+"onthewall,"+zero_bottle+beer_form);
this.stanza.addLine("Gotothestoreandbuysomemore,"+this.num_bottles+beer_form+"onthewall.");
returnthis.stanza.write(separator);
}
}
varStanza=function(){
this.lines=[];
};
Stanza.prototype={
addLine:function(line){
this.lines.push(line);
},
write:function(separator){
returnthis.lines.join(separator);
}
}
varsong=newBottleSong(99,newStanza());
document.writeln(song.sing("<BR>"));
Functional Style
var BottleSong = function(num_bottles){
var bottles = function(n){
return (n == 0 ? "no more" : n) + " bottles";
}
this.num_bottles = num_bottles;
this.last_stanza = function(){
return ["No more bottles of beer on the wall, no more bottles of beer.",
"Go to the store and buy some more, 99 bottles of beer on the wall."];
}
this.stanza = function(n) {
var line = [bottles(n) + " of beer on the wall, " + bottles(n) + " of beer."];
line.push("Take one down and pass it around, " + bottles(n-1) + " of beer on the wall.");
return line;
}
}
BottleSong.prototype = {
sing: function(separator){
var bottles = _.range(this.num_bottles,0,-1)
var that = this;
return _.reduce(bottles, function(lyrics, n) {
return lyrics.concat(that.verse_n(n));
},[]).concat(that.verse_0()).join(separator);
}
}
var song = new BottleSong(99);
document.writeln(song.sing("<BR>"));
bottles 0 = "no more bottles"
bottles 1 = "1 bottle"
bottles n = show n ++ " bottles"
verse 0 = "No more bottles of beer on the wall, no more bottles of beer.n"
++ "Go to the store and buy some more, 99 bottles of beer on the wall."
verse n = bottles n ++ " of beer on the wall, " ++ bottles n ++ " of beer.n"
++ "Take one down and pass it around, " ++ bottles (n-1)
++ " of beer on the wall.n"
main = mapM (putStrLn . verse) [99,98..0]
Haskel Solution
(defn bottles-str [n]
(str
(cond
(= 0 n) "no more bottles"
(= 1 n) "1 bottle"
:else (format "%d bottles" n))
" of beer"))
(defn print-bottle [n]
(println (format "%s on the wall, %s." (bottles-str n) (bottles-str n)))
(println "Take one down and pass it around," (bottles-str (dec n)) "on the wall."))
(defn sing [n]
(dorun (map print-bottle (reverse (range 1 (inc n)))))
(println "No more bottles of beer on the wall, no more bottles of beer.")
(println "Go to the store and buy some more," (bottles-str n) "on the wall."))
(sing 99)
Clojure Solution
Piet Solution
Whitespace Solution
Paradigm Evolution
Java 8
Lambda Expression
Programming paradigm

Contenu connexe

En vedette

절차지향 vs 객체지향
절차지향 vs 객체지향절차지향 vs 객체지향
절차지향 vs 객체지향
QooJuice
 
Programming Paradigms Seminar 2
Programming Paradigms Seminar 2 Programming Paradigms Seminar 2
Programming Paradigms Seminar 2
neoxiuting
 

En vedette (19)

Imperative programming
Imperative programmingImperative programming
Imperative programming
 
Programming paradigms
Programming paradigmsProgramming paradigms
Programming paradigms
 
C/C++ History in few slides
C/C++ History in few slides C/C++ History in few slides
C/C++ History in few slides
 
History of c++
History of c++ History of c++
History of c++
 
Programming paradigm and web programming
Programming paradigm and web programmingProgramming paradigm and web programming
Programming paradigm and web programming
 
격변하는 프로그래밍 언어, 이제는 Let it go
격변하는 프로그래밍 언어, 이제는 Let it go격변하는 프로그래밍 언어, 이제는 Let it go
격변하는 프로그래밍 언어, 이제는 Let it go
 
C++ language
C++ languageC++ language
C++ language
 
Overview of programming paradigms
Overview of programming paradigmsOverview of programming paradigms
Overview of programming paradigms
 
Lambda 란 무엇인가
Lambda 란 무엇인가Lambda 란 무엇인가
Lambda 란 무엇인가
 
What is agile
What is agileWhat is agile
What is agile
 
Programming Paradigms Which One Is The Best?
Programming Paradigms Which One Is The Best?Programming Paradigms Which One Is The Best?
Programming Paradigms Which One Is The Best?
 
절차지향 vs 객체지향
절차지향 vs 객체지향절차지향 vs 객체지향
절차지향 vs 객체지향
 
자바8 람다식 소개
자바8 람다식 소개자바8 람다식 소개
자바8 람다식 소개
 
Introduction to Functional Programming in JavaScript
Introduction to Functional Programming in JavaScriptIntroduction to Functional Programming in JavaScript
Introduction to Functional Programming in JavaScript
 
java 8 람다식 소개와 의미 고찰
java 8 람다식 소개와 의미 고찰java 8 람다식 소개와 의미 고찰
java 8 람다식 소개와 의미 고찰
 
那些 Functional Programming 教我的事
那些 Functional Programming 教我的事那些 Functional Programming 教我的事
那些 Functional Programming 教我的事
 
Programming Paradigms Seminar 2
Programming Paradigms Seminar 2 Programming Paradigms Seminar 2
Programming Paradigms Seminar 2
 
Functional Programming Fundamentals
Functional Programming FundamentalsFunctional Programming Fundamentals
Functional Programming Fundamentals
 
Functional programming
Functional programmingFunctional programming
Functional programming
 

Dernier

CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
Earley Information Science
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

Dernier (20)

ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 

Programming paradigm