Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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
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 / 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

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

Mutation in Ruby

Mutation-related bugs are some of the most common in the Ruby world. Joël and German explore many of the gotchas related to mutation, how to avoid them, and discuss when mutation might not be necessary at all.

Mutation vs Reassignment

In mutation, the value of an object changes but its identity remains the same:

@JoelQ
JoelQ / list-pattern-matching-elm.md
Last active December 5, 2021 16:39
What does `x :: xs` pattern matching mean in Elm?

What does x :: xs pattern matching mean in Elm?

:: is the list prepend operator in Elm.

3 :: 2 :: 1 :: []

is equivalent to

@JoelQ
JoelQ / ellie_examples.md
Last active July 28, 2021 14:12
List of helpful Ellie's I've written