Ruby for .NET developer

Mirosław Pragłowski / @mpraglowski

Who is...

What I've had changed

hardware:
PC to MBA

operating system:
Win to OSX

language:
C# to Ruby

technology:
ASP.NET to Rails

... and a few non technical things

work time:
9-5 to
when you want

location:
office to remote

quite nice list of changes ;)

Why

Canon EOS 5d Mark II

MBA & OSX

Martin Mazur


"Why you should talk to strangers" at DevDay’12

Pet project in Node.js

DRUG meetup

… and my own curiosity & “new things like”

But why leaving .NET?

Just DON’T

it’s not about leaving or not

it’s all about learning

So what really changed

ruby vs c#

code is very readable and mostly self-documenting

convention over configuration

if you need something there probably is a gem for that

dynamic and open type system

strong focus on testing

the same language family

some concepts “not translatable”

forelsket - Danish word which meaning: The euphoria you experience when you’re first falling in love.

schadenfreude another example

there is no concept like this in other languages, all traslations are "workaround"

Ruby blocks


1  def do_something(text)
2    reversed = text.reverse
3    yield reversed
4    reversed
5  end
6
7  test = do_something 'KGD.NET' do |txt|
8    txt.downcase!
9  end
10
11 puts test

=> ten.dgk

tooling

VS.NET is great IDE especially with R#

You could have similar experience with Ruby/Rails

RubyMine is a great IDE - a lot of your experience from VS+R# will be preserved

... but at some time I felt "owned" by the tools

VIM #FTW

community

gained a lot of populatity with startup boom

@dhh

seems to be more "remote friendly"

#DRAMA

philosophy

anti-java

designed to make programmers happy

principles of Conciseness, Consistency & Flexibility

DRY

let’s try simple web app

... from scratch

Installing version manager


Ruby: rvm (from https://rvm.io)
.net: kvm (from https://github.com/aspnet/home#getting-started)

Installing platform


Ruby: rvm install ruby
.net: kvm upgrade (to install latest version the K Runtime Environment (KRE))

Getting dependencies


ruby: bundle install
.net: kpm restore

ruby: gem install XXX
.net: kpm install XXX

Scaffold


ruby: rails new XXX
      rails generate controller SomeController
      rails g view SomeView
      rails g model SomeClass
.net: yo aspnet (and name entered later)
      yo aspnet:MvcController SomeController
      yo aspnet:MvcView SomeView
      yo aspnet:Class SomeClass

let’s go into code structure

compare all the things

RailsWay

good sides

  • for business/coding people to prototype
  • for less-experienced devs - to quickly get results
  • for geniuses - they will handle any code
  • mostly-CRUD apps
  • logic-less systems

bad sides

  • for advanced developers
  • complex business logic
  • long living business processes
  • multiple teams
  • predicable speed of work

NextWay - going out of Rails

  • service objects
  • repositories
  • form objects
  • adapters
  • domain objects
  • events

The Next Way is heavily influenced by DDD and classical OOP patterns

It reduces the Rails magic

Why it is important

What I like

lack of compilation / build step

... just save & refresh page

TDD all the thing culture

dynamic typing ... no need to care about types definition

rails console ... to quickly check ideas

Active Record and its models that "just works"

What I don’t like

lack of compilation / build step

... and finding typos only after run the tests

TDD all the thing... because this is the only way to check it

dynamic typing ... and finding decimal where integer was expected

rails console ... and changing things on production server

Active Record and need to look at database schema to find out attributes

Beware of…

raise TooMuchMagicError

Or translated to .NET:
throw new TooMuchMagicException();

So again… what really changes?

It’s just a hammer

This is also a hammer

use the right tool for your job

Learn from others

?

THX

Available at:
http://praglowski.com/presentations/rubyfordotnetdev