Scala vs ruby

Preview:

Citation preview

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

“Why you should talk to strangers?”

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

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 -

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

filter_and_reduce

named_arguments

partial_functions

pattern_matching

random_from_array

monkey_patching

mixins

Rails vs Play!

Boilerplate

rails new example

play new example

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()

Templates

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

// Scala Template Engine

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

# Embedded 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) }

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') } } }

JSON rendering

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

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

Documentation

Coursera Twitter LinkedIn Guardian Foursquare

Apache Spark

Rails Vagrant Homebrew RSpec Chef Puppet

Basecamp Slideshare GitHub Freckle Shopify Imgur Heroku

Flag products

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

https://blog.lelonek.me/

Recommended