Skip to content

Instantly share code, notes, and snippets.

Thoughtbot's Approach to Ruby

We've been writing Ruby for years on lots of different projects and in many different environments. This has led to thoughtbot's Ruby style to be somewhat different to the rest of the community's. In particular, we tend to focus on a sub-set of Ruby's features. Derek and Joël some of those differences and the reasoning behind them.

Style guide: https://github.com/thoughtbot/guides

@JoelQ
JoelQ / RandomToTask.elm
Last active September 30, 2021 07:16
Turn an Elm random generator into task, allowing it to be chained with other side effects.
-- 0.19
randomToTask : Generator a -> Task x a
randomToTask generator =
Time.now
|> Task.map (Tuple.first << Random.step generator << Random.initialSeed << Time.posixToMillis)
-- 0.18
delay : Time -> a -> Cmd a
delay t x =
Task.perform (always x) <| Process.sleep t
cmd : msg -> Cmd msg
cmd msg =
Task.perform (always msg) (Task.succeed msg)
initSeed = 100
@JoelQ
JoelQ / ENUM.md
Created August 4, 2017 14:31
Proposed Weekly Iteration on Enums with examples in Elm

Weekly Iteration - Enums

Outline

  • Intro
  • Describe Enums as a concept
  • Look some Enum refactorings in Elm
  • Enums vs strings
  • Compare with Enums in other languages (Swift, C)
  • Discuss mapping to numbers
@JoelQ
JoelQ / NEWTYPE.md
Last active October 5, 2017 18:23
Wrapping primitives in custom types in Elm

Domain-Specific Types in Elm

Compilers are powerful helpers but they can only do so much with primitives. Joël and Stephanie fix a bug by introducing domain-specific types. Learn about how these encode real-world context, what are the downsides, and how some functional programming concepts can make those downsides go away.

Primitive Obsession

Previously discussed, don't depend too heavily on low-level constructs.

Dangerous

@JoelQ
JoelQ / PRIMITIVE_OBSESSION.md
Last active September 14, 2017 14:36
Weekly Iteration - Primitive Obsession

Weekly Iteration - Primitive Obsession

Our languages give us great tools in the form of primitives: things like integers, strings, and arrays. However, over-relying on these leads to problems. This practice even has it's own fancy code smell name: Primitive Obssession. In this video, Derek and Joël take a look at Primitive Obsession and the various abstraction tools languages provide to deal with it.

What does it look like in Ruby?

Over relying on hashes/arrays

Representing dollars/cents as an two-element array:

@JoelQ
JoelQ / MUTATION.md
Last active July 14, 2017 18:55
Proposed Weekly Iteration on mutation in Ruby

Weekly Iteration - Mutation

Outline

  • Intro
  • Explain mutation vs re-assignment
  • Discuss Gotchas
    • Mutating a value in a list
    • Array constructor
    • Hash constructor
@JoelQ
JoelQ / README.md
Last active June 2, 2017 19:56
Script to generate domain-specific Elm types wrapping primitives (see https://robots.thoughtbot.com/lessons-learned-avoiding-primitives-in-elm for why this is a good idea)

Modeling Data with Algebraic Data Types

Abstract

Provide a concise description for the program limited to 600 characters or less.

What is "good code"? You've probably heard something like "readable, easy to change, modular, and correct". But what does that look like in practice?

Mapping the world

Abstract

Provide a concise description for the program limited to 600 characters or less.

From the earliest cave paintings to today's GPS-assisted smartphone apps, maps have been an important part of we have described the world around us. But what goes into turning the life-size 3d world into a 2d image that fits in your