22
– Martin Mazur: http://youtu.be/FPBVxpl8NMo @ DevDay “Why you should talk to strangers?”

Scala vs ruby

Embed Size (px)

Citation preview

Page 1: Scala vs ruby

– Martin Mazur: http://youtu.be/FPBVxpl8NMo @ DevDay

“Why you should talk to strangers?”

Page 2: Scala vs ruby

Ruby vs Scala

• Designed for humans, not machines • Extreme flexibility: if you mess up, it’s on you • Everything has to be easy, elegant and fun • DSL on top of DSLs on top of DSLs • Testing is critical • Things move quickly, learn to keep up • Passionate and vibrant community

• Have the best of both object oriented and functional programming worlds

• Let the compiler do some of the work for you • Concurrency matters • Less ceremony than Java, but aiming for same or better

performance • Live in harmony with the Java ecosystem

Page 3: Scala vs ruby

Installation

brew install ruby

brew \curl -sSL https://get.rvm.io | bash -s stable ruby

or

brew install scala

orcurl -O http://downloads.typesafe.com/scala/2.11.7/scala-2.11.7.tgz \

| tar -xvf -

Page 4: Scala vs ruby

Packages

addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.2.7")

build.sbt (obligate versioning)

sbt compile

gem 'rails', '~> 5.0.0'

Gemfile (optional versioning) + Gemfile.lock (locked versions)

bundle

Page 5: Scala vs ruby
Page 6: Scala vs ruby

filter_and_reduce

Page 7: Scala vs ruby

named_arguments

Page 8: Scala vs ruby

partial_functions

Page 9: Scala vs ruby

pattern_matching

Page 10: Scala vs ruby

random_from_array

Page 11: Scala vs ruby

monkey_patching

Page 12: Scala vs ruby

mixins

Page 13: Scala vs ruby

Rails vs Play!

Page 14: Scala vs ruby

Boilerplate

rails new example

play new example

Page 15: Scala vs ruby

Routing

get '/clients/all', to: 'clients#index'

get '/clients/:id', to: 'clients#show'

root 'application#home'

GET /clients/all controllers.Clients.index()

GET /clients/:id controllers.Clients.show(id: Long)

GET / controllers.Application.home()

Page 16: Scala vs ruby

Templates

<ul> @(3 times) { <li>list item</li> } </ul>

// Scala Template Engine

<ul> <% 3.times do %> <li>list item</li> <% end %> </ul>

# Embedded Ruby

Page 17: Scala vs ruby

Unit Tests

test 'my test' do array = [1, 2, 3] assert_equal 1, array.first end

@Test def myTest { val array = List(1, 2, 3) assert(array(0) === 1) }

Page 18: Scala vs ruby

Specs

describe 'HelloWorld spec' do context "The 'Hello world' string should" do it 'contain 11 characters' do 'Hello world'.size.should be 11 end

it "end with 'world'" do 'Hello world'.should end_with('world') end end end

class HelloWorldSpec extends Specification { "The 'Hello world' string" should { "contain 11 characters" in { 'Hello world' must have size(11) }

"end with 'world'" in { 'Hello world'.should end_with('world') } } }

Page 19: Scala vs ruby

JSON rendering

def index render json: { message: 'Hello world' } end

def index = Json("{message: 'Hello world'}")

Page 20: Scala vs ruby

Documentation

Page 21: Scala vs ruby

Coursera Twitter LinkedIn Guardian Foursquare

Apache Spark

Rails Vagrant Homebrew RSpec Chef Puppet

Basecamp Slideshare GitHub Freckle Shopify Imgur Heroku

Flag products

Page 22: Scala vs ruby

Resources:https://github.com/KamilLelonek/scala-vs-ruby

https://blog.lelonek.me/