Laboratório de Desenvolvimento de Software FEUP/MIEIC, 2015/16 Ademar Aguiar Nuno Flores Rui Maranhão Hugo Ferreira Luís Teixeira url: moodle FEUP/MIEIC ● Ademar Aguiar ● Laboratório de Desenvolvimento de Software, 2015/16 Ruby on Rails Ruby + MVC = RoR FEUP/MIEIC ● Ademar Aguiar ● Laboratório de Desenvolvimento de Software, 2015/16 Rails em produção FEUP/MIEIC ● Ademar Aguiar ● Laboratório de Desenvolvimento de Software, 2015/16 Projeto Rails FEUP/MIEIC ● Ademar Aguiar ● Laboratório de Desenvolvimento de Software, 2015/16 Plugins, Packages, Tools, etc. #File ./Gemfile gem 'rails', '4.0.2' gem 'sqlite3’ gem 'uglifier', '>= 1.3.0' gem 'jquery-rails’ gem 'bootstrap-sass-rails', '~> 3.0.3.0’ gem 'debugger’ # Run on console: # $bundle install FEUP/MIEIC ● Ademar Aguiar ● Laboratório de Desenvolvimento de Software, 2015/16 Routes MyApp::Application.routes.draw do root 'welcome#index' # Example of regular route: get 'products/:id' => 'catalog#view' post 'products/:id/purchase' => 'catalog#purchase’ end § http://example.com/products/1 § http://example.com/products/1/purchase FEUP/MIEIC ● Ademar Aguiar ● Laboratório de Desenvolvimento de Software, 2015/16 Controllers Class CatalogController < ApplicationController def view @product = Product.find(params[:id]) # render view.html end def purchase @product = Product.find(params[:id]) @product.purchase() # render purchase.html end end FEUP/MIEIC ● Ademar Aguiar ● Laboratório de Desenvolvimento de Software, 2015/16 Links úteis § Gems: http://rubygems.org § Docs: http://guides.rubyonrails.org § Testing: http://guides.rubyonrails.org/testing.html FEUP/MIEIC ● Ademar Aguiar ● Laboratório de Desenvolvimento de Software, 2015/16 $rails new ldso_application FEUP/MIEIC ● Ademar Aguiar ● Laboratório de Desenvolvimento de Software, 2015/16 FEUP/MIEIC ● Ademar Aguiar ● Laboratório de Desenvolvimento de Software, 2015/16 The Zen of Python § Beautiful is better than ugly § Explicit is better than implicit § Simple is better than complex § Complex is better than complicated § Readability counts §… http://legacy.python.org/dev/peps/pep-0020/ FEUP/MIEIC ● Ademar Aguiar ● Laboratório de Desenvolvimento de Software, 2015/16 Dynamic Typing § Variable types change with assignment a = 10 a = “ten” § Different from automatic type conversions! 10 + “ objects” in javascript or PHP results in ”10 objects” § No method overloading def my_method(param1, param2): […] return xpto FEUP/MIEIC ● Ademar Aguiar ● Laboratório de Desenvolvimento de Software, 2015/16 Duck Typing class Duck: def quack(self): print("Quaaaaaack!") class Parrot: def quack(self): print("The parrot imitates a duck.") def make_animal_quack(animal): animal.quack() FEUP/MIEIC ● Ademar Aguiar ● Laboratório de Desenvolvimento de Software, 2015/16 Multi-paradigm § Object-oriented § Imperative (procedural) § Functional map(), reduce(), filter(), list comprehensions, … FEUP/MIEIC ● Ademar Aguiar ● Laboratório de Desenvolvimento de Software, 2015/16 More … § Compiles to bytecode § Significant whitespace § No semicolons § No braces § The simplest program: print("Hello world") FEUP/MIEIC ● Ademar Aguiar ● Laboratório de Desenvolvimento de Software, 2015/16 Libraries § Standard library § Python Package Index (PyPI) ~38000 packages @ Jan 2014 FEUP/MIEIC ● Ademar Aguiar ● Laboratório de Desenvolvimento de Software, 2015/16 Command Line Interpreter $ python Python 2.4.4 (#1, Oct 18 2006, 10:34:39) [GCC 4.0.1 (Apple Computer, Inc. build 5341)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> >>> a = 'hello' >>> a 'hello' >>> a = 1 # Changing a variable type. GC takes care of 'hello’ >>> b = 2 >>> c = a + b >>> c 3 >>> g Traceback (most recent call last): File "", line 1, in ? NameError: name ‘g' is not defined FEUP/MIEIC ● Ademar Aguiar ● Laboratório de Desenvolvimento de Software, 2015/16 Tools § Multi-platform (but better on *nix) § Pip Package Installer § Virtualenv For creating isolated python environments § Pycharm or Eclipse + pydev FEUP/MIEIC ● Ademar Aguiar ● Laboratório de Desenvolvimento de Software, 2015/16 Docs § The free book “Dive Into Python” http://www.diveintopython.net/ § Google's Python Class https://developers.google.com/edu/python/ § Python in one easy lesson http://cs.stanford.edu/people/nick/python-in-one-easy-lesson/ § Official Docs http://docs.python.org/ FEUP/MIEIC ● Ademar Aguiar ● Laboratório de Desenvolvimento de Software, 2015/16 FEUP/MIEIC ● Ademar Aguiar ● Laboratório de Desenvolvimento de Software, 2015/16 Framework Features § Object-relational mapper § Templates § URL Routing § Internationalization § Schema Evolution (now part of Django 1.7!) FEUP/MIEIC ● Ademar Aguiar ● Laboratório de Desenvolvimento de Software, 2015/16 Overview § Model-View-Template •models.py •views.py •templates directory… •urls.py FEUP/MIEIC ● Ademar Aguiar ● Laboratório de Desenvolvimento de Software, 2015/16 Misc § Database schema created from models.py $ python manage.py makemigrations $ python manage.py migrate § Supports schema migration (new in django 1.7) § Default database engine: sqlite (postgresql is better) § Internal development server $ python manage.py runserver § Supports pluggable apps FEUP/MIEIC ● Ademar Aguiar ● Laboratório de Desenvolvimento de Software, 2015/16 Projects Vs Apps § Supports pluggable apps •Ex: forum, blog, shopping cart, … § Built-in django apps •admin – “Automatic” Backoffice •auth – Users and authentication •formtools – Building forms into webpages •syndication – Building feeds (rss, atom, …) •gis – Handling geographic data (GeoDjango) FEUP/MIEIC ● Ademar Aguiar ● Laboratório de Desenvolvimento de Software, 2015/16 Popular Django Apps § Celery – task queue (supports RabbitMQ, and Redis) § Haystack – full text search § Feincms – content management system § django-reversion – versioning § django-guardian – object-level permissions § django-extensions – misc… § djangorestframework & django-tastypie – REST https://www.djangopackages.com/categories/apps/ FEUP/MIEIC ● Ademar Aguiar ● Laboratório de Desenvolvimento de Software, 2015/16 Tutorial djangoproject.com > Documentation > Tutorial > •Part 1: Object model and “models.py” •Part 2: Admin module •Part 3: Public views “urls.py” and “views.py” •Part 4: Form processing FEUP/MIEIC ● Ademar Aguiar ● Laboratório de Desenvolvimento de Software, 2015/16 Client-side § Django + angular.js § Django + ember.js §… FEUP/MIEIC ● Ademar Aguiar ● Laboratório de Desenvolvimento de Software, 2015/16 Famous Websites § Disqus § Pinterest § Instagram § bitbucket § Lanyrd § addons.mozilla.org § The Onion § washingtonpost.com § guardian.co.uk FEUP/MIEIC ● Ademar Aguiar ● Laboratório de Desenvolvimento de Software, 2015/16 FEUP/MIEIC ● Ademar Aguiar ● Laboratório de Desenvolvimento de Software, 2015/16 About Scala § Object-functional § Runs on the JVM § Sophisticated static type system § Functional features •Immutability (avoids side-effects) •Lazy evaluation •Anonymous functions •List comprehensions •Pattern matching •Tail recursion FEUP/MIEIC ● Ademar Aguiar ● Laboratório de Desenvolvimento de Software, 2015/16 Scala is Reactive! Today applications are deployed on everything from mobile devices to cloud-based clusters running thousands of multi-core processors. Users expect millisecond response times and 100% uptime. Data is measured in Petabytes. Today's demands are simply not met by yesterday’s software architectures. Reactive Systems Responsive, Resilient, Elastic and Message Driven http://www.reactivemanifesto.org/ FEUP/MIEIC ● Ademar Aguiar ● Laboratório de Desenvolvimento de Software, 2015/16 Benefits § Interoperates with Java § Supports Traits § Concurrency using the Actor Model (Akka) § Prepared to scale •Concurrent and synchronous processing •Really takes advantage of multiple cores FEUP/MIEIC ● Ademar Aguiar ● Laboratório de Desenvolvimento de Software, 2015/16 Tools § IntelliJ or Eclipse § SBT •Dependency management •Build the system, run the tests, run static analysis, ... •Many plugins available http://www.scala-sbt.org/0.13/docs/Community-Plugins.html § The Scala shell FEUP/MIEIC ● Ademar Aguiar ● Laboratório de Desenvolvimento de Software, 2015/16 The Scala Shell $ scala This is a Scala shell. Type in expressions to have them evaluated. Type :help for more information. scala> object HelloWorld { | def main(args: Array[String]) { | println("Hello, world!") | } | } defined module HelloWorld scala> HelloWorld.main(null) Hello, world! unnamed0: Unit = () scala>:q FEUP/MIEIC ● Ademar Aguiar ● Laboratório de Desenvolvimento de Software, 2015/16 Who’s Using It § Linkedin § Twitter § FourSquare § Coursera § Tumblr §… FEUP/MIEIC ● Ademar Aguiar ● Laboratório de Desenvolvimento de Software, 2015/16 FEUP/MIEIC ● Ademar Aguiar ● Laboratório de Desenvolvimento de Software, 2015/16 About Play § Similar/inspired by Ruby on Rails and Django Supports creating websites with HTML processed on the server-side § Written in Scala (initially in Java) § JBoss Netty (built-in web server) § No ORM, but possible to use Anorm (Scala), Ebean (Java) or Slick (Scala) § Template language is Scala § Hot-reloading § Part of the typesafe stack: Scala + Akka + Play FEUP/MIEIC ● Ademar Aguiar ● Laboratório de Desenvolvimento de Software, 2015/16 Resources § Official Documentation http://www.scala-lang.org/documentation/ § Functional Programming Principles in Scala https://www.coursera.org/course/progfun Free, 7 weeks course FEUP/MIEIC ● Ademar Aguiar ● Laboratório de Desenvolvimento de Software, 2015/16 [email protected] FEUP/MIEIC ● Ademar Aguiar ● Laboratório de Desenvolvimento de Software, 2015/16