20
Refactoring Rails Applications Jonathan Weiss, 26.05.2009 Peritor GmbH

Refactoring Ruby on Rails Applications

Embed Size (px)

DESCRIPTION

Writing good, maintainable code is hard. You need a lot of experience with the framework to know the little tricks and pit-falls. In this session we take messy code and make it beautiful. We do this by going through examples and refactor them to be more resilient, easier to read, easier to test, and easier to maintain.

Citation preview

Page 1: Refactoring Ruby on Rails Applications

Refactoring Rails Applications

Jonathan Weiss, 26.05.2009

Peritor GmbH

Page 2: Refactoring Ruby on Rails Applications

2

Who am I ?

Jonathan Weiss

•  Consultant for Peritor GmbH in Berlin

•  Specialized in Rails, Scaling, Deployment, and Code Review

•  Webistrano - Rails deployment tool

•  FreeBSD Rubygems and Ruby on Rails maintainer

http://www.peritor.com

http://blog.innerewut.de

Page 3: Refactoring Ruby on Rails Applications

3

Refactoring

A Definition:

Refactoring is the process of changing internal structure without modifying its external functional behavior or existing functionality with the goals of readability, maintainability, performance, extensibility, and simplicity.

Wikipedia

Page 4: Refactoring Ruby on Rails Applications

4

From

Page 5: Refactoring Ruby on Rails Applications

5

To

Page 6: Refactoring Ruby on Rails Applications

6

(To)

Page 7: Refactoring Ruby on Rails Applications

7

How?

Page 8: Refactoring Ruby on Rails Applications

8

Live Coding Experiment

Page 9: Refactoring Ruby on Rails Applications

9

Principles

Page 10: Refactoring Ruby on Rails Applications

10

MVC

Page 11: Refactoring Ruby on Rails Applications

11

Model

Core business model

Domain logic

Reusable

Page 12: Refactoring Ruby on Rails Applications

12

View

Dumb representation to the outside

Targeted at specific use case

Displays desired information

Different views of one model

Page 13: Refactoring Ruby on Rails Applications

13

Controller

Conductor & connector

Brokers client requests to backend

Decide & delegate rather then labor

Page 14: Refactoring Ruby on Rails Applications

14

Principles D R Y

Page 15: Refactoring Ruby on Rails Applications

15

You Ain’t Gonna Need It

Ron Jeffries:

Always implement things when you actually need them, never when you just foresee that you need them.

Page 16: Refactoring Ruby on Rails Applications

16

Live Coding Experiment

Page 17: Refactoring Ruby on Rails Applications

17

Redmine

•  A load-balancer distributes the incoming requests

•  Some load-balancers will deliver static requests themselves

•  Several Rails instances handle all requests

•  Number of concurrent requests equals number of Rails instances

Page 18: Refactoring Ruby on Rails Applications

18

Redmine

•  Multiple projects support

•  Flexible role based access control

•  Flexible issue tracking system

•  Gantt chart and calendar

•  News, documents & files management

•  Feeds & email notifications

•  Per project wiki

•  Per project forums

•  Time tracking

•  SCM integration (SVN, CVS, Git, Mercurial, Bazaar and Darcs)

Page 19: Refactoring Ruby on Rails Applications

19

Q & A

Page 20: Refactoring Ruby on Rails Applications

20

20

Peritor GmbH

Teutonenstraße 16 14129 Berlin

Telefon: +49 (0)30 69 20 09 84 0 Telefax: +49 (0)30 69 20 09 84 9

Internet: www.peritor.com E-Mail: [email protected]

Peritor GmbH - Alle Rechte vorbehalten