0% found this document useful (0 votes)
12 views31 pages

CSC 309 Paradigm

Uploaded by

ananianani001
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views31 pages

CSC 309 Paradigm

Uploaded by

ananianani001
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 31

PARADI

GM

Weuset hewordParadigm t
omean“ anyexampleormodel”
.Thi
susage
ofthewor dwaspopulari
zedbythesciencehist
ori
anThomasKuhn.He
usedt hetermtodescribeasetoftheori
es,st
andar
dsandmethodsthat
togetherrepr
esentawayofor gani
zingknowledge-
awayofviewi
ngt he
world.

A paradigm is a way ofdoi ng something (


like programmi ng),nota
concret
et hi
ng( l
ikeal anguage).Now,i t’
struet hati fapr ogramming
l
anguageLhappenst omakeapar t
icul
arprogrammi ngpar adigm Peasy
toexpress,thenweof t
ensay“ Li saP l anguage”( e.g.“Haskellisa
funct
ionalpr
ogrammi nglanguage”)butt hatdoesnotmeant hereisany
suchthingasa“ f
uncti
onallanguageparadigm”.

PROGRAMMI
NGPARADI
GM:

A pr
ogrammingpar
adigm i
sast yl
e,or“
way,”ofprogr
amming.Some
l
anguagesmakei
teasytowr
itei
nsomeparadi
gmsbutnotot
her
s.

Thus,aprogrammingParadi
gm i
sawayofconceptual
izi
ngwhati
tmeans
toper
form computat
ionandhowtaskst
obecarri
edoutonacomputerto
bestr
ucturedandorgani
zed.

Exampl
esofpr
ogr
ammi
ngPar
adi
gm ar
e:

1.
Procedurallanguages
2.
Object-
orientedlanguages
3.
Functi
onal languages
4.
Declar
ative–non- al
gori
thmi
clanguages
5.
Scri
pti
ngl anguages

PROCEDURALLANGUAGES

A procedur
allanguage is a computerpr
ogramming Languages t
hat
f
oll
ows,inorder,asetofcommands.Exampl esofcomputerprocedur
al
l
anguagesareBASIC,C,FORTRAN, Java,
andPascal
.

Pr
ocedur
all
anguagesar
esomeoft
hecommont
ypesofpr
ogr
ammi
ng
l
anguagesusedbyscr iptandsoftwarepr
ogrammers.Theymakeuseof
funct
ions,condit
ionalstat
ements,andvari
abl
estocreatepr
ogr
amsthat
all
owacomput ertocal
culateanddispl
ayadesi
redout
put.

Usingaprocedur allanguagetocreateaprogram canbeaccompl i


shedby
usi
ngapr ogrammi ngedi t
ororIDE,likeAdobeDr eamweaver,Ecli
pse,or
Microsof
tVi sualStudio.Theseeditorshel
puser sdevel
oppr ogrammi ng
codeusingoneormor eprocedur
allanguages,t
estthecode,andf i
xbugs
i
nt hecode.

Exampl
es:

BASI
CPROGRAMMI
NGLANGUAGE

Basi
cpr
ogr
ammi
ngl
anguager
equi
rednumberl
ine

BASI
Cmeans:( Begi
nnersALLpurposeSymboli
cInst
ruct
ionCode)
,refer
s
toasfree– formlanguage,becauseit
’ssi
mplestruct
ureandmi ni
mal
numberofr
ules.Therul
escall
edsyntax.

Statementwri
tt
eni nBASI Cpr
ogrammingnormall
yfol
lowt
hegener
all
ine
formatdefi
nedthatlanguagewit
hfewexcept
ions.

THEGENERALLI
NENFORMAATOFBASI
CLANGAUGEI
S:

1.LI
NENUMBER
2.COMMAND
3.ELEMENT

Eachcomponentser
vesasadi
ff
erentoper
ati
onal
funct
ion

Exampl
e

10LETH=HOURSWORKED

20LETG=GROSSPAY

30LETR=HOURLYRATE

40I
FH>35GOTO70
50PRI
NTH

60GOTO80

70PRI
NTF,
G

80END

Exampl
e:C–LANGUAGE

Sor
ti
ngofnumber
susi
ngC

i
nti
,j
;

i
ntal
enght
;

f
or(
i=0;i<al
engt
h-1;i
++)

I
ntj
Min=i
;

f
or(
j=i
+1;j<al
engt
h;j
++)

i
f(
a[j
]<a[
jMi
n])

j
Min=j

I
f(
jMi
n!=i
)

{
Swap(
a[j
],
a[j
Min]
);

Exampl
einFORTRANpr
ogr
ammi
ngl
anguage

Pr
ogr
am addi
ti
on!Addt
wonumber
saut
omat
ical
ly

I
mpl
ici
tnone#hasnocl
asspackage

r
eal
,par
amet
er:
:a=50

r
eal
,par
amet
er:
:b=60

i
nteger
,::c

c=a+b

wr
it
e(*
,*)‘
Ther
esul
tis:

,c

Endt
hepr
ogr
am addi
ti
on

Exampl
einPascalpr
ogr
ammi
ngl
anguage
Addi
ti
onofnumber
s
vara,
b,c,
s:i
nteger
;#decl
arat
ion
begi
n
wr
it
e(‘
Typea:‘
);r
eadl
n(a)
;
wr
it
e(‘
Typeb:‘
);r
eadl
n(b)
;

S:=a+b;
wr
it
eln(
‘TheSum ofa+bi
s‘,
S);
r
eadl
n
End

Exampl
einJAVAPr
ogr
ammi
ngLanguage

publ
iccl
asssumNat
ural
{

publ
icst
ati
cvoi
dmai
n(St
ri
ng[
]ar
gs)
{

i
ntnum =100,
sum =0;

f
or (
inti=1;i<=num;i++)
;
{
sum +=i; /
/sum =sum +i
;

Syst
em.
out
.pr
int
ln(
"Sum ="+sum)
;
}
}

Out
put

Sum =5050

Exampl
e2FORLOOPJAVAPROGRAMMI
NGLANGUAGE

cl
assMain
{
publ
icst
ati
cvoi
dmai
n(St
ri
ng[
]ar
gs)
{

i
ntn=5;
f
or(
inti=1;i<=n;++i
)

{
Syst
em.
out
.pr
int
ln(
"Javai
sfun"
);
}
}
}

Out
put

Javai
sfun
Javai
sfun
Javai
sfun
Javai
sfun
Javai
sfun

Thi
swi
llpr
int5t
imesasl
ongast
hecondi
ti
oni
mpl
ies

Exampl
e3I
nJAVA
/
/Pr
ogr
am t
opr
intnumber
sfr
om 1t
o5

cl
assMain
{
publ
icst
ati
cvoi
dmai
n(St
ri
ng[
]ar
gs)
{

i
ntn=5;

f
or(inti=1;i<=n;++i)
{
System.out
.pr
int
ln(
i)
;
}
}
}
Out
put

1
2
3
4
5

Exampl
e4WHI
LELOOPJAVAPROGRAMMI
NGLANGUAGE
cl
assMain
{
publ
icst
ati
cvoi
dmai
n(St
ri
ng[
]ar
gs)

i
nti=1,
n=5; /
/decl
arevar
iabl
es

whi
le(
i<=n) /
/whi
lel
oopf
rom 1t
o5

{
Syst
em.
out
.pr
int
ln(
i)
;

i
++;
}
}
}

Out
put

1
2
3
4
5
OBJECT-
ORI
ENTEDPROGRAMMI
NGLANGUAGE
Object-
ori
entedprogramming( OOP)isacomput erpr
ogrammi ngmodel
thatorganizes soft
ware desi
gn ar
ound data,orobjects,ratherthan
functi
onsandl ogic.Anobjectcanbedefinedasadat afiel
dt hathas
uniqueatt
ri
butesandbehavior.

Object
-or
ientedprogramming(OOP)isaprogrammingparadi
gm basedon
t
heconceptof" object
s",whi
chcancont ai
ndat aandcode:datainthe
for
m offields(oft
enknownasat tr
ibut
esorpr oper
ti
es)
,andcode,inthe
for
m ofprocedures(oft
enknownasmet hods).

OOPfocusesont heobject
sthatdeveloperswanttomani pul
aterat
her
t
hanthelogi
crequi
redmanipul
ati
ngthem.Thi sappr
oachtoprogramming
i
swell
-sui
tedforpr
ogramsthatar
elarge,complexandact
ivel
yupdatedor
mai
ntai
ned.

Thefir
ststepinOOPistocol
lectal
loft
heobject
sapr ogrammerwantsto
manipulat
eandident
ifyhowtheyrel
atetoeachother--anexer
ciseof
ten
knownasdat amodel
ing.

Examplesofanobjectcanrangefr
om physicalent
it
ies,
suchasahuman
bei
ngwhoi sdescri
bedbypr oper
ti
esl i
kenameandaddr ess,downt
o
smallcomputerpr
ograms,suchaswidgets.

Onceanobjecti
sknown,itisl
abel
edwi thaclassofobject
sthatdefi
nes
theki
ndofdatai
tcont
ainsandanylogicsequencest
hatcanmanipulat
eit
.
Each di
sti
nctlogi
c sequence i
s known as a met hod.Objects can
communicatewi
thwel
l-
defi
nedint
erfacescall
edmessages.

Pr
inci
plesofOOP
Obj
ect
-or
ient
edpr
ogr
ammi
ngi
sbasedont
hef
oll
owi
ngpr
inci
ples:

 Encapsulati
on.Thei mplement at
ionandst ateofeachobj ectare
pri
vatel
yhel di
nsi
deadef inedboundary,orclass.Otherobjectsdo
nothaveaccesst othisclassort heauthor
it
yt omakechangesbut
areonlyabl etocallal istofpubl i
cfunctions,ormet hods.This
charact
erist
icofdat
ahi dingprovidesgreat
erpr ogr
am secur i
tyand
avoi
dsuni nt
endeddatacor rupt
ion.
 Abst r
action.Obj ects onlyr eveali nternalmechani sms t hatare
relevantf ort he use ofot herobj ects,hidi
ng any unnecessar y
i
mpl ement ationcode.Thi sconcepthel psdevelopersmor eeasi l
y
makechangesandaddi ti
onsovert ime.
 Inher i
tance.Rel at i
onshipsandsubcl assesbetweenobj ectscanbe
assi gned,al l
owi ngdevel oper st or euseacommonl ogicwhi lesti
ll
mai ntainingauni quehi erarchy.Thi spr oper
tyofOOPf orcesamor e
thor oughdat aanal ysis,reducesdevel opmentti
meandensur esa
higherl evelofaccur acy.
 Pol ymor phism.Obj ectscant akeonmor ethanonef orm depending
ont hecont ext.Thepr ogr
am wi lldeterminewhichmeani ngorusage
i
snecessar yforeachexecut ionoft hatobject
,cuttingdownt he
needt odupl i
catecode.

Obj
ect
-or
ient
edpr
ogr
ammi
ngl
anguages
Whil
e Simulai
s credit
ed as the f
irstobj
ect
-or
ient
ed pr
ogr
ammi
ng
l
anguage,t
hemostpopul
arOOPlanguagesar
e:

 Java
 JavaScri
pt
 Python
 C++
 VisualBasi
c.NET
 Ruby
 Scala
 PHP

Exampl
e1acl
asspr
ogr
am

cl
assBi
cycl
e{

/
/st
ateorf
iel
d

pr
ivat
eintgear=5;
/
/behavi
orormet
hod

publ
icvoi
dbr
aki
ng(){

Syst
em.
out
.pr
int
ln(
"Wor
kingofBr
aki
ng"
);

Exampl
es2i
sobj
ectcr
eat
ion

cl
assNameobj
ect=newcl
assName(
);/
/forBi
cycl
ecl
ass

Bi
cycl
espor
tsBi
cycl
e=newBi
cycl
e()
;

Exampl
e3cal
li
ngofanobj
ect

cl
assBi
cycl
e{

/
/fi
eldofcl
ass

i
ntgear=5;

/
/met
hodofcl
ass

voi
dbr
aki
ng(
){

.
..

}
/
/cr
eat
eobj
ect

Bi
cycl
espor
tsBi
cycl
e=newBi
cycl
e()
;

/
/accessf
iel
dandmet
hod

spor
tsBi
cycl
e.gear
;

spor
tsBi
cycl
e.br
aki
ng(
);

Exampl
esOnJAVASCRI
PTLANGUAGECALLEDI
NPHP
<ht
ml>
<body>
<h>Wel
comet
oJavaScr
ipt
</h>
<scr
ipt
>
document
.wr
it
e("
Hel
loJavaScr
iptbyJavaScr
ipt
")
;
</
scr
ipt
>
</
body>
</
html
>

OUTPUT
Wel
comet oJavaScri
pt
Hel
loJavaScr
iptbyJavaScr
ipt

Exampl
einC++Pr
ogr
ammi
ngLanguage
Apr
ogr
am t
opr
int“
Hel
lopr
ogr
ammi
ngCl
ass”

#i
ncl
ude<i
ost
ream>
i
ntmai
n()

cout<<"
Hel
loPr
ogr
ammi
ngCl
ass"
;

r
etur
n0;

OUTPUT
Hel
loPr
ogr
ammi
ngCl
ass

Exampl
e1onPyt
honPr
ogr
ammi
ngl
anguage
pr
int
("
Hel
loWor
ld"
)
Li
kewi
seonJAVApr
ogr
ammi
ngl
anguage

publ
iccl
assHel
loWor
ld

publ
icst
ati
cvoi
dmai
n(St
ri
ng[
]ar
gs)

/
/Pr
int
s"Hel
lo,
Wor
ld"t
othet
ermi
nalwi
ndow.

Syst
em.
out
.pr
int
ln(
"Hel
loWor
ld"
);

I
nPyt
honi
tonl
yrequi
redsi
ngl
est
atementbut
,
Bothprogr
amswil
lprintthesameresul
t,buti
ttakesonl
yonest
atement
wit
houtusi
ngasemicolonorcur
lybr
acket
Exampl
e2i
nPyt
honpr
ogr
ammi
ngl
anguage

pr
int
("
Wel
comet
oPr
ogr
ammi
ngCl
ass"
)

a=10

#Twoobj
ect
sar
epassedi
npr
int
()f
unct
ion

pr
int
("
a="
,a)

b=a

#Thr
eeobj
ect
sar
epassedi
npr
intf
unct
ion

pr
int
('
a='
,a,
'=b'
)

Out
put
:

Wel
comet
oPr
ogr
ammi
ngCl
ass
a=10
a=10=b

FUNCTI
ONALPROGRAMMI
NG
Functi
onalpr ogrammi ngi
sdesi gnedtohandl et
hesymboliccomput ati
on
andapplicati
onpr ocessi
nglist,
andi ti
sbasedonmat hematicalwork.The
mostpopul arfuncti
onalprogrammi nglanguagesar
ePython,Lisp,
Haskel l
,
Cloj
ure,Erl
anget c.

Funct
ionalPr
ogr
ammi
nghast
wot
ypes;t
hosear
eshownasbel
ow:

 PureFunct i
onalLanguages:Purefuncti
onallanguagesuppor t
sonly
t
hef uncti
onalpatt
ern.Anexampl eofthepurefuncti
onallanguageis
Haskell
.
 I
mpur eFunct i
onalLanguage:ImpureFunctionallanguagesupports
t
hepr otot
ypeoff uncti
onsandt heprogrammi ng'
si mperati
vestyl
e.
Anexampl eofanimpur efunct
ionall
anguagei sLISP.
Charact
eri
sti
cs of t
he Funct
ional Pr
ogr
ammi
ng
Language
Charact
eri
sti
cs oft
he f
unct
ionalpr
ogr
ammi
ng l
anguages ar
eli
ke as
shownbelow:

 Functionalpr ogr
ammi ng l
anguagesar edesi gned to perf
orm the
mathemat ical f uncti
ons. These f unct i
ons use condi ti
onal
expressionsandr ecursiontoperf
ormt hecomput ati
on.
 Functionalpr ogrammi ng support
sf unctions i
n higher-or
derand
feat
uresofl azyevaluat i
on.
 FunctionalPr ogr
ammi ngl anguagedirectl
yusest hef uncti
onsand
functi
on calls.Itdoesnotsuppor tthef l
ow ofthecont rol
slike
stat
ement soft hel oop,and statement sar eli
ket heconditi
onal
stat
ement ssuchasI f-
ElseandSwi t
chSt atements.

Advant
agesoft
heFunct
ionalPr
ogr
ammi
ng
Advant
ages oft
he f
unct
ionalpr
ogr
ammi
ng l
anguages ar
e as shown
bel
ow:

 Bugs-Free code:Funct ionalPr ogr ammi ng l anguage does not


support state,so t herei s no si de ef f
ect of t he f unctional
programmi ng;hencewecanwr i
tetheer ror
-freecode.
 Effi
cient Pr ogrammi ng Language: Funct i
onal Pr ogrammi ng
l
anguagehasnomut ablest ate,sot herei snost atechangei ssue.
Wecandot heprogram "Funct ions"t owor kpar all
elto"Instructi
on".
Thistypeofcodesuppor tsreusabilityandt estabil
ityeasil
y.
 Effi
ciency-Funct i
onalPr ogram cont ai
ns t he IndependentUni ts.
Independent uni t
s r un concur rently. Hence t hese f unctional
programsar emor eeffi
cient.
 Suppor t
s Nested Funct ions-Nest ed functions ar e suppor t
ed by
functi
onalprogrammi ng.
 LazyEval uati
on-LazyFunct i
onalConst ructi
onsar ealsosuppor t
ed
byfunctionalprogrammingsuchasLazyLi sts,LazyMaps, etc.

Functi
onalpr
ogrammingdoesnothaveanystat
e,soallt
heti
me,
ther
eisa
needtocreatenewobject
stoperf
ormt heacti
ons.That
'swhyf
uncti
onal
progr
ammi ngneedsalar
gememor yspace.
Functi
onalpr
ogrammi
ngi
susedt
oper
for
mthedi
ff
erentoper
ati
onson
thesamedataset.

TheLI SP suppor
tsart
if
ici
ali
ntel
li
genceapplicat
ionssuchasl
anguage
processi
ng,Machinel
earni
ng,
Modelingofspeechandvisi
on.

Exampl
e1

Def
ini
ngaFunct
ioni
nC++

Let
’stakeanexampl etounder
standhowaf
uncti
oncanbedef i
nedinC++
whichisanobj ect-
ori
entedprogr
ammingl
anguage.Thefol
lowingcode
hasaf unct
ionthataddst wonumbersandprovidesi
tsresultasthe
out
put.

#i
ncl
ude<st
dio.
h>

i
ntaddNum(
inta,
intb)
; /
/funct
ionpr
otot
ype

i
ntmai n(){
intsum;
sum =addNum( 5,
6); //funct
ioncal
l
printf
("sum =%d",
sum);
return0;
}
i
ntaddNum ( i
nta,
i
ntb){ //functi
ondefi
nit
ion
intresult;
result=a+b;
returnresult
; /
/returnstat
ement
}

I
twi
llpr
oducet
hef
oll
owi
ngout
put−

Sum =11
Exampl
e2i
nEr
lagPr
ogr
ammi
ngl
anguage

Def
ini
ngaFunct
ioni
nEr
lang

Let’
sseehow t hesamef unct
ioncanbedef
inedi
nEr
lang,whi
chi
sa
funct
ionalpr
ogr
ammi ngl
anguage.

-
module(hel
loworl
d).
-
expor
t([
add/2,st
art
/0]
).

add(A,B)->
C=A+B,
io:
fwr i
te(
"~h~w"
,[
C])
.
star
t()->
add( 5,
6).

I
twi
llpr
oducet
hef
oll
owi
ngout
put−

11

Exampl
e5i
nLI
SPpr
ogr
ammi
ngl
anguage

Whenyoust ar
tupt heCommonLI SP envir
onment,youshoul dseea
prompt,which means thatLI
SP is waiti
ng foryou to entera LI
SP
expressi
on.I
ntheenvir
onmentIam usi
ng,itl
ooksli
kethefol
lowing:

USER(
1):

The Common LI SP envi r


onmentf oll
ows the al
gor
it
hm bel
ow when
i
nteractingwit
huser s:
l
oop
readinanexpr essionfrom theconsol
e;
evaluatet
heexpr ession;
printther
esultofevaluationtotheconsol
e;
endl oop.

CommonLI
SPr
eadsi
nanexpr
essi
on,
eval
uat
esi
t,andt
henpr
int
soutt
he
resul
t.
Forexample,
ifyouwantt
ocomput
et ueof(
heval 2*cos(
0)*(
4+6)
),you
typei
n:
USER(1)
:(*2(cos0)(
+46) )

CommonLI
SPr
epl
ies:
20.
0

Exampl
e6usi
ngLI
SPpr
ogr
ammi
ngl
anguage
Cont
rolSt
ruct
ures:Recur
sionsandCondi
ti
onal
s

Nowthatweareequi
ppedwit
hal
lthet
oolsfordevel
opi
ngLISPpr
ograms,
l
etusventur
eint
osomethi
ngmoreint
erest
ing.Consi
dert
hedefi
nit
ionof
f
actor
ial
s:

n!=1 fn=1
i
n!=n*(
n-1)
!ifn>1

Wecani
mpl
ementaf
unct
iont
ocomput
efact
ori
alsusi
ngr
ecur
sion:

(defunfactori
al(N)
"Comput ethefactor
ialofN."
(i
f( =N1)
1
(*N( fact
ori
al(-N1) )
)))
Thei fform checksifNi sone,andret
urnsoneift
hati
sthecase,orel
se
returnsN*( N-1) !
.Severalpoi
ntsar
eworthnot
ing.
Thecondi
ti
onexpr
ession( =N 1)i sarelat
ionalexpressi
on.I
tretur
ns
bool
eanval
uesTorNIL.Inf act
,LISPt
reat
sNI Lasf al
se,andever
ythi
ng
el
seastr
ue.Ot
herr
elat
ionaloperat
orsi
ncl
udet hef
oll
owi ng.
WHAT'
SHASKELL?

Haskel s a pur
li elyf unct
ionalpr
ogr
amming language.I
ni mperat
ive
l
anguagesyougett hi
ngsdonebygi vi
ngthecomput erasequenceof
tasksandthenitexecutesthem.Whil
eexecut
ingthem,itcanchange
state.

Forinst
ance,
yousetvar
iabl
eat
o5andt
hendosomest
uffandt
henseti
t
tosomethi
ngelse.

Haskellislazy.Meanst hatunlessspeci
fi
cal
lytoldot
herwise,Haskel
l
won'texecut
ef unct
ionsandcal
culat
ethi
ngsunti
lit
'sr
eal
lyf
orcedtoshow
youar esul
t.

Exampl
eofaddi
ngnumber
sinHaskel
llanguage

di
gsum

:
:Int
egr
ala

=>a-
>a-
>a

di
gsum base=f0-
>fn

wher
e

fa0=a #f
unct
ionatst
art
fan=f(
a+r
)q #f
unct
ionatl
ast

wher
e

(
a,r
)=n

mai
n::I
O()

mai
n=pr
int$di
gsum n-
-"Fa0,
Far
":15+15=30

Out
put
:

30

Decl
arat
ivel
anguage
Decl
arat
ivelanguages,al
socall
ednonprocedur
alorver yhighl
evel
,ar
e
pr
ogrammingl anguagesi
nwhich(i
deal
ly)aprogram speci
fi
eswhatist
o
bedoneratherthanhowtodoit
.
Insuchlanguagesthereislessdiff
erencebet
weenthespecif
icati
onofa
progr
am and i t
si mpl ementat
ion than inthe pr
ocedur
all anguages
descr
ibedsof ar.Thet wocommonki ndsofdecl
arat
ivel
anguagesar e
l
ogicandfuncti
onallanguages.

Logicprogrammi nglanguages,ofwhi chPROLOG( pr


ogrammi nginlogic)
i
st hebestknown,st ateapr ogram asasetofl ogi
calrel
ations(e.g.,a
grandparentist hepar entofapar entofsomeone) .Suchl anguagesar e
si
mi lartot heSQLdat abasel anguage.A pr ogram isexecuted byan
“i
nferenceengi ne”t hatanswer saquer ybysear chi
ng theser el
ations
systematicall
ytomakei nferencest hatwil
lansweraquer y.PROLOGhas
been used ext ensivelyin nat urallanguage processi
ng and ot herAI
programs.

Funct
ionallanguageshaveamat hemati
calstyl
e.Af uncti
onalprogram i
s
const
ructedbyappl yingfunct
ionstoar gument s.Funct
ionallanguages,
suchasLI SP,ML,andHaskel l,areusedasr esearchtoolsinlanguage
devel
opment ,i
naut omatedmat hemati
caltheorem probers,andinsome
commer ci
alproject
s.
Scr
ipt
ingl
anguages
Script
ing languages ar e someti
mes called l
it
tl
el anguages.They ar e
i
ntended t o solver el
ati
velysmallprogramming pr oblemst hatdo not
requir
et heover headofdat adeclarat
ionsandot herf eat
uresneededt o
make l arge programs manageabl e.Scri
pti
ng languages ar e used f
or
writ
ing operating system uti
li
ti
es,forspecial
-purposef il
e-manipul
ati
on
programs,and,because t hey are easy to l earn,somet imes for
considerablylargerprogr
ams.

Perlwasdevel opedi nt helate1980s,or i


ginal
lyforusewi ththeUNI X
operatingsyst em.I twasi ntendedt ohaveal lthecapabili
ti
esofear li
er
scri
pting l anguages. Per l provided many ways t o state common
operationsandt herebyal l
owedapr ogrammert oadoptanyconveni ent
styl
e.Int he1990si tbecamepopul arasasyst em-progr
ammi ngtool,both
forsmal lutil
it
ypr ogramsandf orpr ot
otypesoflargerones.Togetherwith
other l anguages di scussed bel ow, i t also became popul ar for
programmi ngcomput erWeb“ servers.

WhatAr
eScr
ipt
ingLanguages?

Scri
pting l
anguages can per
for
m diff
erentacti
ons withi
n a parti
cul
ar
runti
meenvi r
onment,suchasaut omat
ingtaskexecuti
on,enhancingthe
functi
onal
ityoftheparentsof
twar
e,per
formingconfi
gurati
ons,ext
racti
ng
datafrom dat
asets,andother
s.

Exampl
esofscr
ipt
ingl
anguagesar
e:

1.JavaScr
ipt
/ECMAScr
ipt

2.PHP

3.Pyt
hon

4.Ruby

5.Gr
oovy

6.Per
l
PROGRAMMI
NGMETHODOLOGY

Programming Met hodol


ogy t eaches the wi dely-
used pr ogramming
l
anguageal ongwi t
hgoodsof t
wareUsedpr ogr
ammi nglanguagealong
with good software engineer
ing pri
nciples. Emphasi si s on good
programmingstyleandt hebui l
t-
infaci
li
tiesoft hel anguage.Itist he
effect
ivepr
ogrammi ngpracti
cesthatr
esultinthedevel opmentofcorrect
programs.
Itcanalsobedef i
nedast heprocessusedbyani ndividualorateam for
devel
opi
ngpr
ogr
am

Goodpr
ogr
ammi
ngmet
hodol
ogy?

A met
hodol
ogy t
hat enabl
es t
he l
owest
-cost and on-
schedul
e
devel
opmentofpr
ogr
amst
hati
scor
rect
,easyt
omai
ntai
n&enhance.
Desi
gnGui
del
ines
 Br
eakyourcodedowni
ntoshor
tandsi
mpl
efunct
ions

 Donotusegl
obal
var
iabl
es

Gl
obal
var
iabl
ear
ethevar
iabl
esweuset
odecl
areout
sidef
unct
ion
i
nta=4;
i
ntb=5;
publ
ici
ntadd(
)
{
r
etur
na+b;
}
aandbar
egl
obal
var
iabl
es
Cor
rectpr
ogr
am?
 Apr
ogr
am wi
thcor
rectsynt
ax&semant
ics

Readabl
epr
ogr
am?
 Apr
ogr
am t
hati
seasyt
oread&under
stand,andt
her
efor
e,easyt
o
mai
ntai
n&enhance
St
epsofPr
ogr
ammi
ng
I
nor
dert
odevel
opagoodpr
ogr
am,
thef
oll
owi
ngst
epsar
etobef
oll
owed:
St
ep1:Anal
ysi
sandunder
standi
ngofpr
obl
ems
St
ep2:desi
gni
ngofal
gor
it
hm f
ort
hepr
obl
em
St
ep3:Test
ingt
hecor
rect
nessoft
heal
gor
it
hm t
omakesur
eitsol
vest
he
pr
obl
em
Ef
fi
cient
lyandaccur
atel
y.
St
ep4:Tr
ansl
ati
ngt
heal
gor
it
hm i
ntoasui
tabl
epr
ogr
ammi
ngl
anguage,
suchas,
Java
St
ep 5:Test
ing and execut
ing t
he pr
ogr
am.Thati
s,t
he pr
ogr
am
devel
opedi
s
Compi
ledandexecut
ed.
St
ep6:document
ingt
hepr
ogr
am,
whi
chi
sver
yessent
ial
inpr
ogr
ammi
ng.
Wehavet
wot
ypesofdocument
ati
on:I
nter
nalandext
ernal
I
nter
nali
nvol
vesput
ti
ngcomment
sandwhi
tespacesi
nourpr
ogr
am
sour
ce
Codeswhi
leext
ernalar
einf
orm ofmanualf
oroper
ati
ngandmai
ntai
ning
t
he
Pr
ogr
am byanyuseroft
hepr
ogr
am.
GoodPr
ogr
ammi
ngst
yles
 Chooseappr
opr
iat
enamesf
oryourvar
iabl
es.

 Speci
alcar
emustbegi
vent
othechoi
ceofnamesf
orpr
ocedur
es,
f
unct
ions,const
ant
sandal
lvar
iabl
esandt
ypesusedi
ndi
ff
erent
par
tsofyourpr
ogr
am.

 Avoi
dusi
ngat
tr
act
ivenameswhosemeani
nghasl
it
tl
eornot
hingt
o
dowi
tht
hepr
obl
em.

 Avoi
dchoosi
ngnamest
hatar
etoocl
oset
oeachot
heri
nspel
li
ngor
ot
her
wiseeasyt
oconf
use,
forexampl
e,Num1,
Num2et
c.

 Becar
efuli
ntheuseofl
ett
eri
(smal
llet
teri
),l
(smal
ll)
,O(
capi
talO)
and0(
zer
o)

 Chooseappr
opr
iat
edat
atypesf
oryourvar
iabl
es

 Thepr
ogr
am mustbewel
lst
ruct
uredf
orr
eadabi
li
ty

 Modul
ari
zet
hepr
ogr
am f
oreasymai
ntenance

 Appr
opr
iat
e document
ati
on f
ormat
s such as comment
s and
whi
tespacesmustbeusedi
nthepr
ogr
am.

 Testt
hepr
ogr
am wi
thdi
ff
erentset
sofdat
a(bot
hval
idandi
nval
id)
Er
ror
sinpr
ogr
ammi
ng
Er
ror
sar
edef
eatorbugsi
napr
ogr
am.
 Test
ing:Thet
asksper
for
medt
odet
ermi
net
heexi
stenceofdef
ect
s
i
napr
ogr
am.

 Debuggi
ng:Thet
asksper
for
med t
o det
ectt
heexactl
ocat
ion of
def
ect
sinapr
ogr
am.

TypesofEr
ror
s
 Synt
axer
ror

 Semant
icer
ror
s.

 Runt
imeer
ror
s

 Logi
cer
ror

 Compi
let
imeer
ror
s
Synt
axEr
ror
s

Theyar
ecausedbyt
hecodet
hatsomehow vi
olat
est
her
ulesoft
he
l
anguage.Easyt
odet
ectandf
ixer
ror
s

Semant
icEr
ror
s
Occurwhenast
atementexecut
esandhasanef
fectnoti
ntendedbyt
he
pr
ogr
ammer
,Har
dtodet
ectdur
ingnor
malt
est
ing·Oft
ent
imesoccuronl
y
i
nunusual&i
nfr
equentci
rcumst
ances.

Run-
TimeEr
ror
s
Occurwhent
hepr
ogr
am i
srunni
ngandt
ri
est
odosomet
hingt
hati
s
agai
nstt
her
ules
Exampl
e:Accessi
nganon-
exi
stentvar
iabl
e,pr
oper
ty,met
hod,obj
ect
,et
c
(
e.g.amet
hodnamei
smi
sspel
led)
·Sour
cesoft
hesecanbedet
ermi
ned
byacar
eful
readi
ngoft
hecode,
butunf
ort
unat
ely,
notal
ways!

Logi
cer
ror
Usual
lymadebypr
ogr
ammer
s.Thepr
ogr
am wi
lldef
ini
tel
ycompi
leand
r
unver
ywel
lbutt
her
esul
t/
out
putgot
tenwi
ll
haveer
ror
s.

Compi
let
imeer
ror
s. They ar
e er
ror
s br
oughtoutdur
ing t
he
execut
ionst
ageoft
hepr
ogr
am devel
opment
.Forexampl
e,whenwet
ryt
o
di
videanumberbyzer
o,i
tcausesmemor
yover
fl
ower
ror
.
Resour
ceMat
eri
al(
s)

S.O.Aki
nol
a,“
Str
uct
uredpr
ogr
ammi
ngwi
thJava”

You might also like