Download - Web frameworks

Transcript
Page 1: Web frameworks

Web FrameworksA brief overview

Gianfranco Reppucci@giefferre

martedì 29 ottobre 13

Page 2: Web frameworks

So, what?

• Cos’è un framework web?

• Quale framework utilizzare?

• Qualche esempio pratico

• Alcune considerazioni

martedì 29 ottobre 13

Page 3: Web frameworks

OK, ma perché parlare di web framework?

Non tutto quello che viene considerato “web development” si riduce a “creare siti”

• Web Application

• Social Network Apps & Mashup

• Web services

• ...

martedì 29 ottobre 13

Page 4: Web frameworks

Framework = ?

• I primi siti web erano una collezione di pagine HTML statiche

• Ogni aggiornamento richiedeva un cambiamento manuale

<html><head>

<title>My wonderful website</title></head><body>

<h1>Hello World!</h1><p>This is my ancient website. Enjoy your time here.</p><a href=”page2.html”>Click here to open page 2</a>

</body></html>

martedì 29 ottobre 13

Page 5: Web frameworks

Framework = ?

• Per creare pagine web dinamiche sono stati introdotti i linguaggi di programmazione “server-side”

<%@ language="vbscript" %><html>...<body> <h1>Un esempio di codice dinamico</h1> <% For i = 1 to 10 Step 1 response.write("Questo messaggio sarà stampato 10 volte") Next %></body></html>

martedì 29 ottobre 13

Page 6: Web frameworks

Framework = ?

Col crescere delle esigenze e con l’evolversi dei design patterns, sono aumentate le possibilità e le complicazioni

• Database

• Manipolazione immagini

• Elaborazione files

• ...

martedì 29 ottobre 13

Page 7: Web frameworks

Framework = ?

• Un framework è un software che permette di supportare la fase di sviluppo di siti, web application o web services.

• Lo scopo di un framework è ridurre l’overhead di un programmatore nello scrivere parti di codice comuni (gestione database, templating, sessioni, ecc)

martedì 29 ottobre 13

Page 8: Web frameworks

Ovvero

Un framework è una collezione di “strati” di software, ognuno dei

quali esegue compiti diversi

martedì 29 ottobre 13

Page 9: Web frameworks

Caratteristiche

• Database configuration, access, mapping (Object-Relational Mapping)

• URL mapping

• Templating

martedì 29 ottobre 13

Page 10: Web frameworks

Caratteristiche

• Caching

• Security

• AJAX

• Helpers

martedì 29 ottobre 13

Page 11: Web frameworks

Framework != CMS

• È un errore molto frequente quello di confondere il concetto di Content Management System con quello di Framework.

• Solitamente (ma non sempre!) un CMS è qualcosa di più specifico e complesso di un framework

martedì 29 ottobre 13

Page 12: Web frameworks

Framework != CMS

Il CMS è un’applicazione “pronta all’uso” che solitamente serve per creare facilmente siti e webapp:

• È un contenitore(di pagine, articoli, contenuti multimediali, ecc.)

• Il backend è più o meno standard

• Ha un proprio sistema di templating

• Di solito customizzabili solo tramite l’uso di plugin specifici

martedì 29 ottobre 13

Page 13: Web frameworks

Quale framework utilizzare?

Dipende da:

• Linguaggio di sviluppo che si vuole adoperare

• Necessità strutturali del progetto

martedì 29 ottobre 13

Page 14: Web frameworks

PHP

Python

Asp.NET

Ruby

Java

JavascriptErlang

Smalltalk

Clojure

C

martedì 29 ottobre 13

Page 15: Web frameworks

Per ognuno dei linguaggi esistenti esistono diversi framework

martedì 29 ottobre 13

Page 16: Web frameworks

Python

• Django

• Flask

• TurboGear

• Zope 2

martedì 29 ottobre 13

Page 17: Web frameworks

PHP

• Zend

• CodeIgniter

• Symphony

• Slim

• CakePHP

martedì 29 ottobre 13

Page 18: Web frameworks

Ruby

• Ruby on Rails

• Sinatra

• Ramaze

martedì 29 ottobre 13

Page 19: Web frameworks

Javascript

• node.js

• meteor JS

• SproutCore

martedì 29 ottobre 13

Page 20: Web frameworks

Punti in comune

• Paradigma Model-View-Controller

• Strutturazione “Three-tier”(client, application, database)

• A volte, sono molto simili

Infatti...

martedì 29 ottobre 13

Page 21: Web frameworks

Un esempio pratico

• PHP: Slim

• Python: Flask

• Javascript: node.js + Express JS

martedì 29 ottobre 13

Page 22: Web frameworks

Installazione: Slim

user@host:projectA$ curl -s https://getcomposer.org/installer | php

Create un file composer.json{ "require": { "slim/slim": "2.*" }}

Da shell:

user@host:projectA$ php composer.phar install

Da shell:

martedì 29 ottobre 13

Page 23: Web frameworks

Installazione: ExpressJS

Create un file package.json{ "name": "node-express-test", "description": "NodeJS + ExpressJS test", "version": "0.0.1", "private": true, "dependencies": { "express": "3.x" }}

Scaricate ed installate node.js

user@host:projectB$ npm install

Da shell:

martedì 29 ottobre 13

Page 24: Web frameworks

Installazione: Flask

user@host:projectC$ pip install flask

Da shell:

EPIC WIN

martedì 29 ottobre 13

Page 25: Web frameworks

Hello world: Slim

<?phprequire 'vendor/autoload.php';

$app = new \Slim\Slim();$app->get('/', function () { echo "Hello World!";});

$app->run();?>

index.php

martedì 29 ottobre 13

Page 26: Web frameworks

Hello world: ExpressJS

var express = require('express');var app = express();

app.get('/', function(req, res){ res.send('Hello World!');});

app.listen(8002);

index.js

martedì 29 ottobre 13

Page 27: Web frameworks

Hello world: Flask

from flask import Flaskapp = Flask(__name__)

@app.route('/')def hello_world(): return 'Hello World!'

if __name__ == '__main__': app.run(port=8003)

index.py

martedì 29 ottobre 13

Page 28: Web frameworks

Development server: PHP

user@host:projectA$ php -S localhost:8001

Da shell (PHP >= 5.4):

Altrimenti bisogna installare un classico stack *AMP

martedì 29 ottobre 13

Page 29: Web frameworks

Development server: node.js

user@host:projectB$ node index.js

Da shell:

martedì 29 ottobre 13

Page 30: Web frameworks

Development server: Python

user@host:projectC$ python index.py

Da shell:

martedì 29 ottobre 13

Page 31: Web frameworks

Alcune considerazioni

I costrutti dei vari framework iniziano a somigliarsi tantissimo

martedì 29 ottobre 13

Page 32: Web frameworks

Alcune considerazioni

Va bene specializzarsi con una tecnologia, ma è necessario “cambiare aria” ogni tanto

martedì 29 ottobre 13

Page 33: Web frameworks

Alcune considerazioni

Scegliete il framework rispetto al progetto che dovete sviluppare

martedì 29 ottobre 13

Page 35: Web frameworks

@giefferre

http://gdlabs.it

Graziedell’attenzione

martedì 29 ottobre 13


Top Related