Rails Scala Citec Presentation
Upcoming SlideShare
Loading in...5
×

Like this? Share it with your network

Share

Rails Scala Citec Presentation

  • 1,935 views
Uploaded on

In this presentation, Kristian gives an insight into his experiences of using Ruby on Rails and Scala for developing recent projects at Workingmouse. It is aimed at people from a Java background......

In this presentation, Kristian gives an insight into his experiences of using Ruby on Rails and Scala for developing recent projects at Workingmouse. It is aimed at people from a Java background and assumes no prior knowledge of Ruby/Rails or Scala.

The presentation is divided into two sections; Ruby on Rails and Scala. In each section, he gives a brief overview of the features and syntax of the languages before delving into the problems and benefits he discovered while using them. He finishes each section with a guide to the appropriateness of the languages and gives some tips on how to get started.

More in: Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
    Be the first to like this
No Downloads

Views

Total Views
1,935
On Slideshare
1,931
From Embeds
4
Number of Embeds
1

Actions

Shares
Downloads
13
Comments
0
Likes
0

Embeds 4

http://www.slideshare.net 4

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. Experiences with Languages other than Java Kristian Domagala CITEC Technology Day 10th October, 2008 Experiences with languages other than Java 1 © Workingmouse Pty Ltd 2008. All rights reserved
  • 2. Background Technology ● Java/J2EE – Web client/server – WS*/XML/XSD – Processes ● Agile – TDD – Experiences with languages other than Java 2 © Workingmouse Pty Ltd 2008. All rights reserved
  • 3. What is Ruby? Dynamically typed ● Interpreted ● Object Oriented ● Supports common functional idioms ● Meta-programming ● Promotes testing to replace type safety ● Experiences with languages other than Java 3 © Workingmouse Pty Ltd 2008. All rights reserved
  • 4. Object Oriented class Person class Employee < Person attr_reader :name def initialize(name,email,salary) def initialize(name,email) super(name,email) @name = name @salary = salary @email = email end end def increase_salary(pct) def email @salary *= pct @email end end end end emp = Employee.new(quot;Fredquot;,quot;f@xyz.comquot;, 50000) puts emp.name + quot;: quot; + emp.email emp.increase_salary(1.05) Experiences with languages other than Java 4 © Workingmouse Pty Ltd 2008. All rights reserved
  • 5. Dynamic typing class Person class Business ... ... def email def email @email @email end end end end def spam(obj) send_spam_to(obj.email) end spam(person) spam(business) Experiences with languages other than Java 5 © Workingmouse Pty Ltd 2008. All rights reserved
  • 6. Mixins (multiple inheritance) module Payable def pay(amount) account.deposit(amount) end end class Employee < Person class Business include Payable include Payable attr_reader :account attr_reader :account ... ... end end employee.pay(1000) business.pay(100) Experiences with languages other than Java 6 © Workingmouse Pty Ltd 2008. All rights reserved
  • 7. Meta-programming Redefine class/method behaviour at runtime ● method_missing – eval – Experiences with languages other than Java 7 © Workingmouse Pty Ltd 2008. All rights reserved
  • 8. RSpec describe quot;Sending spamquot; do it quot;should send to the person's email addressquot; do person_mock = mock(quot;personquot;) person_mock.should_receive(:email) .and_return(quot;fred@xyz.comquot;) spammer.should_receive(:send_spam_to) .with(quot;fred@xyz.comquot;) .and_return(true) spammer.spam(person_mock).should == true end end Experiences with languages other than Java 8 © Workingmouse Pty Ltd 2008. All rights reserved
  • 9. What is Rails? Web application framework featuring ● MVC – Active record – Template engine – Web server – Code generators – Extensible through plugins ● Open source since 2004 ● Experiences with languages other than Java 9 © Workingmouse Pty Ltd 2008. All rights reserved
  • 10. Convention over Configuration Controllers ● public methods -> actions -> views – Model ● class-name -> table, attribute -> column – auto fields like id, created_at, version – Minimal configuration required ● Conventions can be overridden ● Experiences with languages other than Java 10 © Workingmouse Pty Ltd 2008. All rights reserved
  • 11. Rails projects at Workingmouse Experiences with languages other than Java 11 © Workingmouse Pty Ltd 2008. All rights reserved
  • 12. Rails projects at Workingmouse Experiences with languages other than Java 12 © Workingmouse Pty Ltd 2008. All rights reserved
  • 13. Experiences Code base not very discoverable ● Difficult to locate references and definitions – Unsure what effect code changes will have until – runtime Experiences with languages other than Java 13 © Workingmouse Pty Ltd 2008. All rights reserved
  • 14. Experiences Upgrades to framework/plug-ins risky ● Test coverage not always adequate – Introduction of plug-ins risky ● Can break assumptions on both sides – Experiences with languages other than Java 14 © Workingmouse Pty Ltd 2008. All rights reserved
  • 15. Experiences Things aren't always what they appear to be ● Item.tags – Array of Tag? ● Array of tag names? ● Comma separated list of tag names? ● Experiences with languages other than Java 15 © Workingmouse Pty Ltd 2008. All rights reserved
  • 16. Experiences Few “best practices” universally agreed on ● Rails is very accessible – Strong, sometimes highly opinionated, community – Plethora of tutorials/blogs – difficult to sieve through ● not always good advice! ● Experiences with languages other than Java 16 © Workingmouse Pty Ltd 2008. All rights reserved
  • 17. Common rebuttal Not enough tests! ● Where do you stop? – TDD process doesn't catch all bugs ● Maintaining tests – Language doesn't force tests – Code coverage tools not always adequate ● Experiences with languages other than Java 17 © Workingmouse Pty Ltd 2008. All rights reserved
  • 18. Experiences Still, able to get something up and running ● quickly Experiences with languages other than Java 18 © Workingmouse Pty Ltd 2008. All rights reserved
  • 19. IDE support Eclipse/IDEA ● syntax highlighting – some code-completion – some search capabilities – limited to ability due to dynamic language features – Interactive Ruby/Rails shells ● Read Evaluate Print Loop capability – Experiences with languages other than Java 19 © Workingmouse Pty Ltd 2008. All rights reserved
  • 20. Appropriateness Can be good for ● “green-fields” small project development – prototyping – Had issues with ● long running and non-trivial projects, especially – maintenance ● unfamiliarity of code ● Experiences with languages other than Java 20 © Workingmouse Pty Ltd 2008. All rights reserved
  • 21. Tips for starting Up front study & experimentation ● Books – Agile Web Development with Rails (tutorial) ● The Rails Way (reference) ● Communication ● Pairing/spending time with experienced people – Research ● Investigate basis of claims – Get both sides of the story – Experiences with languages other than Java 21 © Workingmouse Pty Ltd 2008. All rights reserved
  • 22. Questions? Experiences with languages other than Java 22 © Workingmouse Pty Ltd 2008. All rights reserved
  • 23. What is Scala? Statically typed ● Object Oriented ● Functional ● Compiles to JVM byte code (.class files) ● Open source ● First release in 2003 – 2.0 released in 2006 – Experiences with languages other than Java 23 © Workingmouse Pty Ltd 2008. All rights reserved
  • 24. Relation to Java By design, Scala can do virtually everything that ● Java can do classes, methods, interfaces, statics – no forced exception handling ● call Java APIs – Even the (arguably) bad stuff ● nulls, down-casting, reflection – Experiences with languages other than Java 24 © Workingmouse Pty Ltd 2008. All rights reserved
  • 25. Example class Person( val firstName:String, val lastName:String, val birthYear:Int, private var height: Int) { val name = firstName + quot; quot; + lastName def age(year: Int) = birthYear + year def debug { println(name + birthYear + height) } } Experiences with languages other than Java 25 © Workingmouse Pty Ltd 2008. All rights reserved
  • 26. Language features Type inferencer ● First class functions and closures ● XML literals ● Type-safe tuples (allows multiple return values) ● Traits (allows multiple inheritance) ● Experiences with languages other than Java 26 © Workingmouse Pty Ltd 2008. All rights reserved
  • 27. XML literals val bookElt = <book title=quot;Scala for dummiesquot; year=quot;2008quot;> <author>Martin Odersky</author> <author>Tony Morris</author> </book> println(quot;Title: quot; + bookElt.attribute(quot;titlequot;)) (bookElt quot;authorquot;).foreach{a => println(a)} Experiences with languages other than Java 27 © Workingmouse Pty Ltd 2008. All rights reserved
  • 28. Type-safe tuples def nameAndYear(person:Person) = (person.name, person.birthYear) val ny = nameAndYear(person) val firstInitial = ny._1.charAt(0) val genX = (1968 until 1979).contains(ny._2) Experiences with languages other than Java 28 © Workingmouse Pty Ltd 2008. All rights reserved
  • 29. Multiple inheritance trait Payable { def account:Account def pay(amount:Int) { account.deposit(amount) } } class Employee extends Person class Business with Payable { extends Payable { def account = ... def account = ... } } employee.pay(1000) business.pay(100) Experiences with languages other than Java 29 © Workingmouse Pty Ltd 2008. All rights reserved
  • 30. Type system Useful for detecting common bugs ● Simple things like NullPointerExceptions – Through to enforcing concurrency constraints – Constraints can be better implied with types ● Removes some of the need for defensive ● programming fail fast often done at the compiler – Experiences with languages other than Java 30 © Workingmouse Pty Ltd 2008. All rights reserved
  • 31. Scala projects at Workingmouse Scoodi Ads engine ● Scoodi online help webapp ● Slinky web application framework ● Experiences with languages other than Java 31 © Workingmouse Pty Ltd 2008. All rights reserved
  • 32. Experiences To get full benefit, need to change the way you ● think Functional programming concepts difficult to get ● a grasp of, but very powerful once understood Experiences with languages other than Java 32 © Workingmouse Pty Ltd 2008. All rights reserved
  • 33. Experiences Easy to trace code definitions and usage ● Type system helps find dead code and prevents – invalid changes and assumptions Sometimes difficult to get compiling ● but more often than not, once it compiled it was – correct Experiences with languages other than Java 33 © Workingmouse Pty Ltd 2008. All rights reserved
  • 34. Experiences Scala to Java integration is practical ● sometimes more type annotations and down- – casting required Java to Scala integration theoretically possible ● practical implications can make it infeasible – Experiences with languages other than Java 34 © Workingmouse Pty Ltd 2008. All rights reserved
  • 35. Java integration example import javax.servlet.http._ class MyServlet extends HttpServlet { override def service( req: HttpServletRequest, resp: HttpServletResponse) { val name = req.getParameter(quot;namequot;) ... } } Experiences with languages other than Java 35 © Workingmouse Pty Ltd 2008. All rights reserved
  • 36. IDE support Eclipse/IDEA ● primitive support (syntax highlighting) – plug-ins actively developed (esp IDEA) – buggy for our use ● Interactive Scala shell ● REPL capability – Can also use for invoking Java libraries – Experiences with languages other than Java 36 © Workingmouse Pty Ltd 2008. All rights reserved
  • 37. Appropriateness Can be used anywhere that Java is used ● Added benefits ● better expressiveness with 1st class functions – safer code with type system and APIs that – encourage immutability better rate of code reuse with higher kinds – less verbosity with syntax and inferencer – Experiences with languages other than Java 37 © Workingmouse Pty Ltd 2008. All rights reserved
  • 38. Tips for starting Workingmouse Scala training course :-) ● Start by imitating Java ● Explicitly specifying types will help most compilation – issues Full benefit of functional aspects made easier ● by learning a pure functional language as well Experiences with languages other than Java 38 © Workingmouse Pty Ltd 2008. All rights reserved
  • 39. Questions? Experiences with languages other than Java 39 © Workingmouse Pty Ltd 2008. All rights reserved
  • 40. Thanks! http://workingmouse.com http://wiki.workingmouse.com Experiences with languages other than Java 40 © Workingmouse Pty Ltd 2008. All rights reserved