Sunday, November 4, 2007

RubyConf 2007: Cleanliness Is Next to Domain Specificity

Ben Scofield is a senior developer at Viget Labs (blog)

There really has been no discussion of why you would want to create a DSL.

Part 1: Linguistics

Categories
  • Language (for the sake of discussion, it is Vocabulary and Grammar)
  • Dialects
  • Jargon
  • Pidgins and Creoles
Regional Dialects Example: Generic Names for Soft Drinks
Regional Dialects Example: Little Bunny Foo Foo
Jargons Example: Waitress-speak
Cants Example: Class languages in D&D
Pidgins and Creoles: linguistic hacks and evolved linguistic hacks, respectively

Most "DSLs" are not different languages, because they only have a different vocabulary, and not a different grammar.
  • ActiveRecord
  • RSpec
Who cares? DSLs intimidate and frighten.
Write a Parser? No, thanks (Matz did it already).
API vs. Dialect

Sapir–Whorf hypothesis (and programming languages)
  • Linguistic Determinism (the strong version; it's crap)
  • Linguistic Relativism (the weaker version; influence instead of determine)
The Great Eskimo Vocabulary Hoax (Wikipedia)

Color Perception
  • Direction of Causality (language and thinking)
  • Degree of Influence (were you able to distinguish the colors before being given the words)
RSpec loves Sapir-Whorf. Specifications come first. RSpec leads you in the right direction. Domain Specific Dialects (DSDs) are built on Linguistic Relativism. Keep your head in the domain (foo/bar/baz vs. roll/pitch/yaw).

Part 2: Refactoring

Proviso: when dealing with domain-specificity, tastes vary.

Finding a ticket. Some sites became travel search site aggregators (kayak.com, sidestep.com). Kayak provides a search API and a Ruby sample. Someone from the audience: It tastes like burning. It looks like PHP. Strategy when writing a DSD: start at the end.

I want to find flights from CLT to RDU leaving today and returning in one week.

find :flights, :from => :CLT, to => :RDU, leaving => Date.today, returning => Date.today + 7

What is sent from their API to their web service? Set up expectations (mocks). When writing domain-specific code, you will never be done (modeling reality problem). There is always room for improvement.

Tips
  • use symbols (reads like English; quotes would distract you)
  • optional parenthesis (looks like a sentence)
  • blocks for all
  • splat operator (* arrays from anything)
  • optional braces (not that common; Rubinius guys don't like this)
Keys
  • Start modestly
  • Stay in the domain
  • Get better
http://www.extendviget.com/
http://www.culann.com/

We throw around the word language too easily and don't use it precisely, as Ben does (with his linguistic background).

Domain-Driven Design

RubyConf 2007: JRuby in the Wild

Kyle Maxwell works at CastTV

Video Search is hard.

$ jirb -rjava
> import java.util.TreeMap
> map = TreeMap.new
> map[1] = 4
> map[2] = 7
> map.inject(0){|memo, (key,value)|
> memo += key + value
> }
# 14


Why use it? Yet another war (deployment). Familiar tools (java).

JRuby is not perfect. Use the right tool for the right job. There are organizational (are you already a java shop?) and situational concerns.

Ruby is missing a few things in its current incarnation: performance and library support. There is some room for improvement, but not by us. You can make the choice of moving things down to the C-level. Want to solve the problem in the highest-level language possible. Java.

Choices I've made:
  • Rails (sticking to MRI, for now)
    • possible performance issues
    • regex library
    • already working in CRuby
    • experience with standard deployment
  • Search (JRuby/Java)
    • Decided to take an open source search engine and build heavily upon that
    • initially tried MRI/ferret (extending the C was a nightmare)
    • then tried CRuby/Solr (didn't want the extra overhead of another java server and concerns about maintainability)
    • finally Lucene/JRuby (easy to maintain; clear method of extension; less to break; JRuby is an active project)
  • Spellchecker (JRuby/Java)
    • performance is at a premium (look at the performance of your algorithms before you look at the performance of your language)
    • ternary search trie algorithm
    • tried it in ruby first (creating a million nodes takes ten seconds; also, there was a large memory overhead)
    • same reasons as above for skipping C
    • java (tried to do inline java and it was too painful; access java objects from ruby)
port, api, or binding?
  • never port anything (most overheard and is error prone)
  • api has the overhead of building the needed layers
  • binding had least overhead
an off-the-cuff benchmark (load the unix dictionary into a hash, ten times)
  • MRI 12.9s and 144MB
  • JRuby (with J-server) on the Sun 1.5 JVM 9.0s and 72MB
  • Java 1.5 4.1s and 61MB
  • Perl 4.1s and 19MB
getting started
  • easy install (personally, works off of trunk)
  • jruby -S [gem, rake, ...]
    • unless it is a gem that requires a C extension, it will work (hpricot was ported)
  • get the extras
  • textmate not advised (personally, works in eclipse)
  • a sane build strategy
  • jar2gem.rb
gotchas
  • casting can be tricky (e.g. float, arrays (see to_java))
require "java"
A.new 1.99 # will be passed as a double and won't cast
A.new java.lang.Float.new(1.99) # works


Is there anything you wanted to do in JRuby, but couldn't? Yes, and this will hopefully be fixed. Interacting with POSIX operating systems (file permissions, etc).

Have you evaluated Groovy? No.

We're running all our JRuby processes as standalone daemons.

Man, I really need to work on my public speaking skills. I sputtered through asking my question to Kyle.

Have you dealt with JRuby in the context of a legacy (non-greenfield) Java System? Any problems there? No. Someone from the audience brings up the issue of the production staff only dealing with java deployments. I have a feeling that there have to be issues, just no one here has run into them. Related to this is that there don't seem to be many language agnostic people here.

RubyConf 2007: Ruby and Identity: OpenID, CAS and Information Card

Justin Gehtland is the president of Relevance.

There will be twelve slides and then we're going to code.
  1. rails myapp (camping, whatever)
  2. ruby script/plugin install acts_as_authenticated
  3. There is not step 3!
This leads to redundant implementations, no shared authentication, and comingled storage (sensitive and non-sensitive data in the same place).

What do you get for giving $2 million to RSA? Someone to sue.

Two types of central authentication: private and public. The difference? Trust.

OpenId (public)
  • free, open central id
  • vendor-supported, but not controlled
ruby-openid has dependencies on
  • net transports
  • yadis (openid + directory service)
CAS (private)
  • central authentication service
  • foss
  • java-based
rubycas-client and rubycas-server

What about
  • LDAP?
  • NTLM?
  • Commercial SSOs?
Ruby has bindings for these (ActiveLDAP, rldap, ...).

OpenID demo.

Caveat: the shipping openid plugin returns :false (the symbol), if the user is not logged in.

This is all authentication. NEVER punt authorization rules to a third-party server. They are coupled to the domain or application.

CAS demo.

You need a certificate to run the server. All traffic to a single sign-on must go over SSL.

rubycas-server is done in camping.

Biggest problem he has seen in rails shops is domain explosion. Example: a notes application is released and now the business people want a memo application, but you can't make a separate application because that would necessitate multiple logins.

CAS uses ssl for everything, except token generation: "#{Time.now.to_i}r%X" % rand(10**32)

RubyConf 2007: Next-Gen VoIP Development with Ruby and Adhearsion

Jay Phillips

Asterisk telephony development sucks. Painful configuration. Tons of jargon (What? Any discipline has jargon. He even uses some jargon during the talk.). Hacky culture. Few good programmers. Software quality fluctuates. Too many disparate pieces. Geezers. Wow, this guy is making some broad sweeping statements.

Fun VoIP projects:
  • Your mobile as a universal remote or gamepad
  • Home automation
  • Phone controlled Roomba
Mischief:
  • spoofing caller id (easy)
  • confuse automated telemarketers
  • third party call control, so you aren't making the outgoing call
  • "Get Things Done"
Benefits:
  • abstract
  • simple
  • extensible
Adhearsion 0.8.0 is in the svn trunk.
  • call routing dsl
  • FreeSWITCH integration
  • better rails app integration
Co-authoring "Ruby and Telephony"

TODO:
  • Richer abstractions
  • Capistrano to configure Asterisk
  • Phone provisioning
  • Gaining more control with Asterisk 1.6
  • Seamless FreeSWITCH integration
  • VoIP functional tests
  • "Pure-Ruby" VoIP features
Demo

RubyConf 2007: Behaviour Driven Development with RSpec

David Chelimsky works at Articulated Man, Inc. Dave Astels works at Google.

Test Driven Development
  • incremental process
  • drives implementation with tests
  • results in an exhaustive regression test suite
  • should focus on design
  • should focus on documentation
  • should focus on behavior
Behavior Driven Development is like TDD, but with the following added:
  • includes focus on design
  • includes focus on documentation
  • includes focus on behavior
Short demo on ping-pong pair programming. You write the smallest test you can to cause failure. The other person writes the simplest code to make the test pass.

Overview of the BDD/RSpec Timeline.

November 2007 (knock on wood): RSpec-1.1.0
  • Introduce Story Framework
  • Beginning of Test::Unit compatibility
    • More work on this for 1.1.1 release
Customer to Code Agile Process:
  • Domain Driven Design
  • Acceptance Test Planning
  • Test Driven Development
  • Start by specifying at the highest levels
    • He starts out with the views, mocks out everything, and goes from there.
Story Framework - Executable User Stories

Something about rbehave flashed on the screen.

Demo of the Story Framework. Testing that read as prose (same concepts as Hoare Logic, but reads better). This looks pretty cool and useful.

Demo of a tool in its infancy that Tech Support, QA, and business people can use to poke the system.

Quick look at RSpec Results. You can have pending tests.

Something about integrating with legacy projects flashed on the screen.

miniunit/minirspec will be shipped with Ruby 1.9.

New hosting: rspec.lighthouseapp.com

Q1 2008: "Behavior Driven Development in Ruby with RSpec" (The Pragmatic Programmers)

RubyConf 2007: Use Ruby to Generate More Ruby - RubiGen is Everywhere

Dr Nic

Opening Theme: A-Team

Ryan Bates' video on writing your generator

He's moving too fast for me to live blog.

He pulled generators out of Rails, so that Ruby projects can make use of them.

It's been integrated into Merb, NewGem, RubyCocoa, and Airake.

Pseudo-live, he modifies sow to make use of generators, instead of printing text directly to a file.

TODO:
  • replace rails_generator with rubigen dependency
  • gereators pick dependencies based on which scopes are available (different ORMs and different test suites)
I love it when a plan comes together.

Werewolf

After Matz's keynote, last night, I joined an insanely fun game called Werewolf (aka Mafia).

As Andrew Plotkin says on his werewolf page, "Werewolf is a simple game for a large group of people (seven or more.) It requires no equipment besides some bits of paper; you can play it just sitting in a circle. I'd call it a party game, except that it's a game of accusations, lying, bluffing, second-guessing, assassination, and mob hysteria."

The base rules are very simple. For a group of ten people, you have two werewolves, one seer, and seven villagers. There are day cycles and night cycles. In night cycles, werewolves get to choose one person to kill, and the seer gets to find out if a player is a werewolf. In the day cycles, the village debates and lynches one member. The humans win if they kill all werewolves. The werewolves win if they get the human:werewolf ratio down to 1:1.

The rules are very simple. The game can become as complex as you let it. Discussions of human behavior, logic chains, misdirection, trust, psychology, ethics, and more break out. If you are not careful, you can get lost in discussions about the meta-game, discussing the overarching game instead of discussing observations and thoughts as villagers.

Some IRC Werewolf sessions.

One point to add is that if you are spectating a game of Werewolf, you not only have to stay quiet and suppress your reactions when someone is lynched or killed. You also have to be wary of the body language you are giving off.

I was a spectator for parts of the four hour werewolf exhibition game last night. Participating were long-term addicts like Chad Fowler, Jay Phillips, Jim Weirich, Marcel Molina, and a dozen others. It was a no reveal game, meaning that when someone is lynched or killed, you do not get to find out what class they were, so until the very end, you cannot be certain about anything. It was definitely entertaining for the spectators; probably more so than for the players.

Charles Nutter's concerns about Werewolf and Conference Hacking.