Skip to content

btihen/East_Oriented_Code

Repository files navigation

East Oriented Code

Better Message Passing == Better Code

BACKGROUND

Definition

Presentation on Messaging with code samples using East Orientation (& Injection)

  • Eastward is sending a message (telling)
  • Westward is receiving a message (usually after asking)

CREDIT

Practices

Enforced Tell - Don't Ask

  1. Always Return 'self' - especially public methods - (factories & initializers exempt)
  2. Objects MAY ONLY QUERY itself - avoid public getters!
  3. Objects MAY ONLY CHANGE their own state - avoid public setters!
  4. Break the Rules sparingly - mostly for output -- then pass a simple object (ideally immutable) - think Structs & View-Models

Rules 2 & 3 are basically unnecessary if rule 1 is followed closely!

HELPFUL & CONTROVERSIAL

EASY & HELPFUL: with a pipeline architecture:

input -> processing -> output

Examples:

  • CLI scripts
  • Background Jobs
  • Data conversions outputs

Use Case - A Data Exchange

CONTROVERSIAL to use with a "controller" architecture - that expects to "control" - the opposite of East Oriented code.

Informal Practice

When Strict East isn't practical

Helpful for daily coding - when East Oriented not practical

  • Tell, don't ask - Could I return self?, What else canI make private?
  • Exceptions common - pass a data for output & formatting - using view-models, value-objects, struct or minimally a hash

I like to explore the practice of getting as close as possible to East Oriented (along with Sandi Metz's Code Complexity Rules & Behavior Injection)

CODE

I don't have access to the Data Exchange I wrote for my previous employer - but Jim Gay's address code can use a similar pipeline flow

  • 01_east_west_address.rb - is east-west, very simple and clear -- great when very simple and flexibility isn't needed
  • 02_east_address.rb - is east only is great when additional for flexible outputs and keeping processing clear (only objects can change and query themselves)

Given Time and Interest

  • 03_east_injection_address.rb - injection and decorators allow lots of flexibility and complexity while preserving the benefits of East Orientated Message passing with one place data is mutated and single purpose for each class.
  • 00_jim_gay_refactor_process.md - Jim Gay's refactoring process from East/West to West

About

Playing with East Oriented Code & Presentation

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published