Laboratório de Desenvolvimento de Software FEUP/MIEIC, 2015/16 Ademar Aguiar Nuno Flores Rui Maranhão Hugo Ferreira Luís Teixeira url: moodle
Ruby on Rails Ruby + MVC = RoR
Rails em produção
Projeto Rails
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
Routes MyApp::Application.routes.draw do end root 'welcome#index' # Example of regular route: get 'products/:id' => 'catalog#view' post 'products/:id/purchase' => 'catalog#purchase http://example.com/products/1 http://example.com/products/1/purchase
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
Links úteis Gems: http://rubygems.org Docs: http://guides.rubyonrails.org Testing: http://guides.rubyonrails.org/testing.html
$rails new ldso_application
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/
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
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()
Multi-paradigm Object-oriented Imperative (procedural) Functional map(), reduce(), filter(), list comprehensions,
More Compiles to bytecode Significant whitespace No semicolons No braces The simplest program: print("hello world")
Libraries Standard library Python Package Index (PyPI) ~38000 packages @ Jan 2014
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
Tools Multi-platform (but better on *nix) Pip Package Installer Virtualenv For creating isolated python environments Pycharm or Eclipse + pydev
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/
Framework Features Object-relational mapper Templates URL Routing Internationalization Schema Evolution (now part of Django 1.7!)
Overview Model-View-Template models.py views.py templates directory urls.py
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
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)
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/
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
Client-side Django + angular.js Django + ember.js
Famous Websites Disqus Pinterest Instagram bitbucket Lanyrd addons.mozilla.org The Onion washingtonpost.com guardian.co.uk
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
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/
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
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
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
Who s Using It Linkedin Twitter FourSquare Coursera Tumblr
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
Resources Official Documentation http://www.scala-lang.org/documentation/ Functional Programming Principles in Scala https://www.coursera.org/course/progfun Free, 7 weeks course
ademar.aguiar@fe.up.pt