Why Best Practices?

259f23c3b129f07b0c496b9f0495f07e?s=47 jeg2
August 04, 2013

Why Best Practices?

This is JEG2's segment of the Ruby Rogues panel form LSRC 2013.

259f23c3b129f07b0c496b9f0495f07e?s=128

jeg2

August 04, 2013
Tweet

Transcript

  1. I Only Have Time to Make One Point The others

    made me include this slide!
  2. .

  3. Thanks!

  4. Why Best Practices?

  5. How Should We Use Struct? class Specialized < Struct.new(:whatever) #

    ... define custom methods here... end Specialized = Struct.new(:whatever) do # ... define custom methods here... end
  6. I Prefer the Block Form But that’s not the point!

  7. Code Similarity and Malleability Specialized = Struct.new(:whatever) do # ...

    define custom methods here... end Trivial = Struct.new(:whatever)
  8. An Extra Class • The anonymous class doesn’t tell us

    much • Code reloading may cause “TypeError: superclass mismatch…” [Specialized, #<Class:0x007f8ba7389d18>, Struct, Enumerable, Object, PP::ObjectMixin, Kernel, BasicObject] class Specialized < Struct.new(:whatever) # ... define custom methods here... end
  9. The “super” Problem class Specialized < Struct.new(:whatever) def whatever super

    || :default end include SomeMixin end Specialized = Struct.new(:whatever) do def whatever self[:whatever] || :default end prepend SomeMixin end
  10. The Point • It’s not about the one right way

    to code • It’s about what we learn in the discussion • This trivial example alone includes: • Code malleability • The ancestor class chain • The value of prepend