introducere n.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
Introducere PowerPoint Presentation
Download Presentation
Introducere

Loading in 2 Seconds...

play fullscreen
1 / 33

Introducere - PowerPoint PPT Presentation


  • 84 Views
  • Uploaded on

Introducere. Paradigme de programare Mihai Zaharia. Obiectivele cursului. Intelegerea principalelor paradigme de programare folosite in dezvoltarea aplicatiilor la aceasta ora. Familiarizarea cu diferite limbaje de programare care implementeaza una sau mai multe paradigme simultan

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

Introducere


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
introducere

Introducere

Paradigme de programare

Mihai Zaharia

obiectivele cursului
Obiectivelecursului
  • Intelegerea principalelor paradigme de programare folosite in dezvoltarea aplicatiilor la aceasta ora.
  • Familiarizarea cu diferite limbaje de programare care implementeaza una sau mai multe paradigme simultan
  • Stabilirea tipurilor de probleme unde sunt folosite diverse paradigme functie de context
  • Invatarea unor instrumente noi de programare
  • Limbajele care vor fi folositea de-a lungul cursului sunt
    • UML
    • C/C++
    • Java,
    • Java Beans
    • LabWindows
    • Python
    • Haskel
    • Prolog
criterii folosite in evaluarea activitatii
Criteriifolosite in evaluareaactivitatii
  • Participareala orele de curs si de laborator:
    • Neparticiparea la maimult de 14% din laboratoare conduce la refacereadisciplinei
  • Activitatea de laborator(nu e de ajunssaitiaducicorpul la laborator = participare) 25%
  • Temeacasala majoritatealaboratorelor 25%
  • Examen final 50% (este o singura nota) defalcatastfel:
    • Proba de laborator – ELIMINATORIE 25% cu biletesi 2 ore maxim la dispozitie. Un subiect din douatrebuiesa fie indeplinit integral pentru a se putea nota (min 5)
    • Probateoretica– 25% - test docimologic - continesiintrebari cu caracterpracticspecficelaboratorului (min 5)
indatoririle studentului
Indatoririlestudentului

Cititimaterialelerecomandate cu o ziinainte de fiecare curs – elaborati o lista de intrebari eventual

Rezolvatitemelepeacasa in saptamana in care le-atiprimit

Participatila cursuri (suportul de curs livratvacontinenumaidesenele/cod din slide-uri)

Rezervati un minim de 2-4 ore de studiu individual pesaptamanapentruaceastamaterie

Verificatiintelegereateoreticasipracticaa notiunilorasimilateprinajutareacolegilor cu raspunsuri legate de parteateoreticasauajutor (nu temacopiata) in rezolvareaproblemelor practice

Caviitoriinginerieste de asteptatesaRespectaticodul etic minim al IEEE http://www.ieee.org/about/corporate/governance/p7-8.html

sintaxa
Sintaxa
  • Definestesimbolurilesigramaticaunuilimbaj
    • BNF sau
    • EBNF

if-statement ::= if ( expression ) statement-block

[ else statement-block ]

statement-block ::= statement ';'

| '{' statement ';' [...] '}'

statement ::= if-statement | assignment-statement |

while-statement | ...etc...

strategii de implementare
Strategii de implementare

Compilator:

Interpretor:

Hibrid:

compilarea unui program
Compilareaunui program

file.c

main() {

printf("hello");

exit(0);

}

Cod sursa

Preprocesor

AnalizorLexical, etc

file.obj

.sym printf

FE048C7138

029845AAAF

...

Object Code

Compilator

Executable

Program

Link-Editor

printf.obj

<obj. code for

printf function>

file.exe

<hardware instructions>

Biblioteci (pentru cod obiect

java o strategie hibrida

‘Escu.java

Java: o strategiehibrida

Biblioteci

Executare program

Sunt ‘escu!

javac

Hello.class

java

Program sursa Java

compilator

byte code

  • MVJ:
  • Verificarebyte cod
  • - Incarcareclase
  • - interpretor

Java Runtime Environment (JRE)

exemple de erori java
public int cmmdc ( int v# ) // eroare lexicala

{

int z = value

y = v;

while ( y >= 0 )

{ int t = y;

y = z % y;

z = t;

}

return y;

}

Exemple de erori (Java):
executia instructiunilor pe un cpu
Executiainstructiunilorpe un CPU

0010110010100010

0001011110000000

0010110000011000

1101100001011001

0011001010001011

0000011101001111

1101100001100001

0010110100010001

0001011100001110

…etc…

executarea unui program
Executareaunui program

Registriinterni

RAM

Cache

Contorulprogramului

ce instructiuni de baza poate interpreta un procesor
Ceinstructiuni de bazapoateinterpreta un procesor?

LOAD

SAVE

MOVE

ADD

MULT

COMPARE

TEST

JUMPTO

java code bytecode pentru jvm

0: iconst_2 //incepe for

1: istore_1

2: iload_1

3: sipush 1000

6: if_icmpge 44 //comparatia cu 1000

9: iconst_2 //incepe for

10: istore_2

11: iload_2

12: iload_1

13: if_icmpge 31 // compartia cu i

16: iload_1 //incepe if

17: iload_2

18: irem

19: ifne 25 // comparatia cu 0

22: goto 38

25: iinc 2, 1 //j++

28: goto 11

31: getstatic #84; //apelPrintStream

34: iload_1

35: invokevirtual #85; //PrintStream.println:(I)V

38: iinc 1, 1 // i++

41: goto 2

44: return

Java code/bytecodepentru JVM

De ce nu sunt continue numerele/adresele de la bytecode?

outer:

for (int i = 2; i < 1000; i++)

{

for (int j = 2; j < i; j++)

{

if(i % j == 0) continue outer;

}

System.out.println(i);

}

primele incercari de abstractizare
Primeleincercari de abstractizare

@echo off cls

echoPressanykeyto start AProgram.exe!

pause > nul

AProgram.exe %1

iferrorlevel 1

gotoerror

echoAProgramhasfinishedwhateverit wasdoing.

gotoend

error:echoSomethingwentwrongwithAprogram

end

PROGRAM EXEMPLU ! VERSION 0.0.

CALL HELLO!apelareasubrutineiHELLO.

CONTAINS !CONTAINS incheie program principal siincepedefinireasubrutinelor

SUBROUTINE HELLO!definireacorp SUBROUTINA

WRITE(*,*) "HELLO WORLD!“!afisez"HELLO WORLD!" la CONSOLA.

END SUBROUTINE HELLO!SfarsitSUBROUTINA

END PROGRAM EXEMPLU!sfarsit PROGRAM

Fortran, primul limbaj de nivel înalt,

cele mai cunoscute limbaje din generatia a treia
Celemaicunoscutelimbaje din generatia a treia

Functie de tipul de paradigmafolosit in rezolvareaproblemelor

  • Imperative: FORTRAN, COBOL, BASIC, C, Pascal
  • Functionale: Scheme, Lisp
  • LimbajeLogice: Prolog
  • Orientate obiect:
    • Orientate obiect pure:Java, Python
    • Orientate obiectsi imperative : C++, Perl, Visual Basic
limbaje din generatia a patra
Limbaje din generatia a patra

Acesteasuntdeja orientate peanumitetipuri de aplicatii

SQLpentrubaze de date

Limbajul Postscriptpentrudescriereauneipaginifolosit de imprimante

PDFpentrudocumente on-line

HTML and PHPpentrucontinutWorld Wide Web

Mathematica

exemple sql
Exemple - SQL

Inserareaunui table intr-o baza de date:

INSERT INTOangajati(id, Nume, Prenume, functie)VALUES (1445, ‘John’,’Smith',’manager’);

Extragere de informatiifunctie de un criteriudintr-un tabel:

SELECT id, Prenume, salariuFROMangajatiWHERE ( Job = ‘manager’ );

SQL esteconsiderat a fi declarativ

ce este o paradigma de programare
Ceeste o paradigma de programare?
  • D1 (generală) Caz exemplar, model, prototip, situaţie ideală, structură tip, arhetip standard ş.a.
  • D2. (în filozofie, la L.Wittgenstein)Modelele filosofice, acele "tipare" care orientează gândirea noastră în direcţii predeterminate.,
  • D3 (în filozofia limbajului) Listă de cazuri tipice de jocuri lingvistice prin care putem înţelege conceptul general..."
paradigme de programare wiki
Paradigme de programare (wiki)

Action

Agent-oriented

Aspect-oriented

Automata-based

Component-based

Flow-based

Pipelined

Concatenative

Concurrentcomputing

Relativisticprogramming

Data-driven

Declarative (contrast: Imperative)

Constraint

Dataflow

Cell-oriented (spreadsheets)

Reactive

Intensional

Functional

Logic

Abductive logic

Answer set

Constraint logic

Functional logic

Inductive logic

End-userprogramming

Event-driven

Service-oriented

Time-driven

Expression-oriented

Feature-oriented

Function-level (contrast: Value-level)

Generic

Imperative (contrast: Declarative)

Procedural

Language-oriented

Discipline-specific

Domain-specific

Grammar-oriented

Dialecting

Intentional

Metaprogramming

Automatic

Reflective

Attribute-oriented

Homoiconic

Template

Policy-based

Non-structured (contrast: Structured)

Array

Nondeterministic

Parallelcomputing

Process-oriented

Programming in the large andsmall

Semantic

Structured (contrast: Non-structured)

Modular (contrast: Monolithic)

Object-oriented (OOP)

Byseparation of concerns:

Aspect-oriented

Role-oriented

Subject-oriented

Class-based

Prototype-based

Recursive

Value-level(contrast: Function-level)

Probabilistic

programarea nestructurat
Programarea nestructurată

ASM

.model small

.stack 1024

. data

z db? ; n

MOV AX, @data

MOV DS, AX

MOV al, 3 ; m=3

ADD al,5 ; m=m+5

Jmpetl

etl: MOVz,al ; n=5

MOV al,z

MOV ah, 4ch

INT 21h

end start

Basic

10 rem program exemplu

20 m=3

30 m=m+5

40 goto 50

50 n=5

60 m=n

60 end

Bloc continuu

Salt direct

slide22

TIOBE Programming Community Index for August 2013

http://www.tiobe.com/content/paperinfo/tpci/index.html

cmmdc structurat in c
#include <stdio.h>

intmain()

{

int a=1574, b=56, t, cmmdc;

while(b != 0)

{

t = b;

b = a % b;

a = t;

}

cmmdc= a;

printf("Greatestcommondivisior of %dand%d = %d\n", a, b, cmmdc);

getch();

}

CmmdcStructurat in C
procedural java script cmmdc
Procedural Java Script cmmdc

function calculate()

{

var x = 167; var y = 3; var output;

output = cmmdc(Math.abs(x), Math.abs(y))

}

functioncmmdc(x, y)

{

while(y != 0)

{

var z = x % y;

x = y;

y = z;

}

returnx;

}

functional in c
#include <stdio.h>

int cmmdc(int u, int v)

{

if (v == 0)

return u;

else

return cmmdc (v, u % v);

}

intmain(void)

{

int x =9, y=6;

printf("The gcd of %d and %d is %d\n",x,y,cmmdc(x,y));

return 0;

}

Functional in C
functional cmmdc in scheme
(define (cmmdcu v)

(if (= v 0) u

(cmmdcv (modulo u v) )

)

)

Functional cmmdc in Scheme

Sintaxa Scheme pentru o functie:

( define ( function-name param1 param2 ... )

body of function definition

)

functional cmmdc in scheme1
(define (euclid)

(display "enter two integers:")

(let ((u (read)) (v (read)))

(display "the gcd of ")

(display u)

(display " and ")

(display v)

(display " is ")

(display (gcd u v))

(newline)

)

)

Functional cmmdc in Scheme
imperativ in java cmmdc
public class oarescare{

private static long cmmdc(long u, long v) {

long remainder;

if (v < 0) v = -v;

while ( v != 0 ) {

remainder = u % v;

u = v;

v = remainder;

}

if ( u == 0 ) return 1; // cmmdc(0,x) = 1

else return (u>0)? u : -u; // modul

}

... Restulclasei nu are importanta

Imperativ in Java: cmmdc
imperativ original fortran 77
INTEGER FUNCTION IGCD(U,V)

INTEGER U, V, TMP

DO WHILE ( V .NE. 0 )

TMP = V

V = MOD(U,V)

U = TMP

END DO

IGCD = V

RETURN

END

PROGRAM MAIN

WRITE(6,*) "Input two integers:"

READ(5,*) I, J

WRITE(6,100) I, J, IGCD(I,J)

100 FORMAT("GCD of ",I4," and ",I4," is ",I4)

STOP

END

Imperativoriginal:FORTRAN77
oop java cmmdc
public class CMMDC{

private final int value;

public CMMDC( int value )

{ this.value = value; }

public int cmmdc ( int v ) {

int u = value;

while ( v != 0 ) {

int t = u % v;

u = v;

v = t;

}

return u;

}

}

Oop Java cmmdc
cmmdc in programare logica prolog
cmmdc(U, V, U) :- V = 0.

cmmdc(U, V, X) :- not (V = 0),

Y is U mod V,

gcd(V, Y, X).

Cmmdc in programarelogica Prolog

/* calculcmmdc(288,60) */

cmmdc(288, 60, X).

consequence :- a, b, c.

concluzii
Concluzii

Paradigmelesuntnecesare