my month with ruby

30
My month with Ruby

Upload: alextomovski

Post on 19-Jul-2015

79 views

Category:

Software


0 download

TRANSCRIPT

My month with Ruby

Who is this guy?

- Alex Tomovski

- Backend Developer (primarily)

- Scala, Java, Groovy

- Recently crossed to the dark side… JS

How did I end up coding Ruby?

- Joined Wix in the summer.

- No project was waiting for me.

- Finally after two weeks I got a call…

How did the colleagues react when I

told them I’ll be doing Ruby?

Some of them got creative :)

What was I supposed to build?

- Thin Rest Wrapper

- But why?- Make developers life easier.

- Annoying request signing logic

- Document and provide examples for the APIs

The API

Where do you start???

- Book: The Ruby Programming language

- IRB

- Setup the project

- Look at other examples/tools- www.ruby-toolbox.com

Setting up the project

- Bundler and Rake

- Love at first sight (especially for bundler)

I want less of this: and more of this:

Hello World!

- Tests- RSpec + Guard

- Tests run in the background

- Immediate feedback

- WIN!

Testing a dynamic language

- Paranoia!- What happens if someone

passes the wrong type?

- Guard statements

everywhere?

- Wait do I care?

Integration (e2e) Tests

- Easier refactoring

- Faster bug discovery

- VCR- https://github.com/vcr/vcr

- Records HTTP Interactions

- Fast re-execution

- Helps with debugging

VCR Cassette

First Impressions

- Easy to learn

- Readability

- Super FUN!

Guard Statements!

Mutability

- Hard to come back to it

- Side effects

- Freeze?

Blocks? Lambdas? Procs?

Vision

- One entry point (the client)- Minimal configuration

- Optional extensive configuration

Structuring the gem

- Modules - Mixins

REST Client VS. Faraday

- Ease of use

- Extensibility

- Plugable middleware

- Configuration

Faraday

Classes or Hashes?

- Response handling

Classes

- Easy data access

- Hard to create

Introducing Hashie

- Best of two worlds- https://github.com/intridea/hashie

Hashie Example

Too much magic

- It was all great until this:

/hashie/dash.rb:41:in `block in property': wrong number of arguments (1 for 0)

(ArgumentError)

from /hashie-3.2.0/lib/hashie/hash.rb:48:in `flexibly_convert_to_hash'

from /hashie-3.2.0/lib/hashie/hash.rb:34:in `block in to_hash'

from /hashie-3.2.0/lib/hashie/hash.rb:20:in `each'

from /hashie-3.2.0/lib/hashie/hash.rb:20:in `to_hash'

from /hashie-3.2.0/lib/hashie/hash.rb:42:in `to_json'

A day latter…

Monkey Patching

And we’re Almost :) done

- Final thoughts:- Threading

- Meta programming

- Would I use Ruby again?

Thank you!

Questions, Comments?

Repo: https://github.com/wix/wix-hive-ruby