Slide 1

Slide 1 text

Alba: Why, How and What's So Interesting ౦ژRubyձٞ12 લ໷ࡇ OKURA Masafumi, 2025-01-17

Slide 2

Slide 2 text

self.pretty_print • Name: OKURA Masafumi • Work: Freelance web developer • Activities: Kaigi on Rails, TokyoWomen.rb, Rubygems code reading club, organizing Regional.rb and the Tokyo Metropolis

Slide 3

Slide 3 text

Agenda • 0. What is Alba? • 1. Why did I create Alba? • 2. How was it achieved? • 3. What’s so interesting about it?

Slide 4

Slide 4 text

0. What is Alba?

Slide 5

Slide 5 text

No content

Slide 6

Slide 6 text

What is Alba? • https://github.com/okuramasafumi/alba • A JSON serializer for Ruby, JRuby and Truf fl eRuby • Core values: Performance, easy-to-use, feature-rich • Total download: About 1,350,000 • GitHub Stars: About 960

Slide 7

Slide 7 text

Core values of Alba

Slide 8

Slide 8 text

Performance

Slide 9

Slide 9 text

https://github.com/ okuramasafumi/ alba/tree/main/ benchmark

Slide 10

Slide 10 text

No content

Slide 11

Slide 11 text

13x faster than ActiveModelSeri alizers!

Slide 12

Slide 12 text

2.50x slower

Slide 13

Slide 13 text

https://commons.wikimedia.org/wiki/File:C_Programming_Language.svg

Slide 14

Slide 14 text

Alba is one of the fastest among other Ruby implementations

Slide 15

Slide 15 text

Easy-to-use

Slide 16

Slide 16 text

No content

Slide 17

Slide 17 text

Minimal API to serialize objects into JSON • `attributes` DSL to use underlying object’s attribute directly • `attribute` DSL to compute the result from object’s attribute • `root_key` DSL to de fi ne root key • `association` DSL to embed other serializers’ result

Slide 18

Slide 18 text

Feature-rich

Slide 19

Slide 19 text

Advanced features of Alba • Type support • “Typelizer” gem adds the ability to generate TypeScript types • Conditional attributes • Serializing heterogeneous collections • Filtering • etc.

Slide 20

Slide 20 text

1. Why did I create Alba?

Slide 21

Slide 21 text

2020

Slide 22

Slide 22 text

Because there was no de fi nitive JSON serializer

Slide 23

Slide 23 text

Because there was nothing I’d like to use

Slide 24

Slide 24 text

I wanted something that is Ruby-ish

Slide 25

Slide 25 text

No content

Slide 26

Slide 26 text

What is “Ruby-ish” like?

Slide 27

Slide 27 text

“Yugui: ͦΕ͸ɺίϨΫγϣϯ͕ ͋ͬͯγϟοϑϧ͍ͨ͠ͱࢥͬͨ Βɺshuf fl eͱॻ͍ͯɺͦΕͰಈ ͔ͳ͖Ό͍͚ͳ͍ΜͰ͢Αɻ” https://atmarkit.itmedia.co.jp/news/200907/24/ruby2.html

Slide 28

Slide 28 text

“·ͭ΋ͱɿ͋ͬ͸ͬ͸ɻ γϟοϑϧͰ͖Δ͸ͣͩ ͱɻͰ͖ͳ͚Ε͹Rubyͷό άͩͱɻ” https://atmarkit.itmedia.co.jp/news/200907/24/ruby2.html

Slide 29

Slide 29 text

When we want to do “A”, just write “A” and it should work

Slide 30

Slide 30 text

2. How was it achieved?

Slide 31

Slide 31 text

use case driven development

Slide 32

Slide 32 text

use case driven development • It’s one of the forms of TDD (Test Driven Development) • Follow these steps: 1. Write use cases as test cases 2. Consider if Alba should support these use cases 3. If yes, implement it

Slide 33

Slide 33 text

Q. Where do use cases come from?

Slide 34

Slide 34 text

A. Issues, discussions and my imagination

Slide 35

Slide 35 text

https://github.com/okuramasafumi/alba/issues/335

Slide 36

Slide 36 text

https://github.com/okuramasafumi/alba/issues/182

Slide 37

Slide 37 text

3. What’s so interesting about it?

Slide 38

Slide 38 text

Ruby allows us to create Ruby-ish libraries

Slide 39

Slide 39 text

Conditional Attribute

Slide 40

Slide 40 text

No content

Slide 41

Slide 41 text

No content

Slide 42

Slide 42 text

Module-level alias

Slide 43

Slide 43 text

No content

Slide 44

Slide 44 text

No content

Slide 45

Slide 45 text

Bring in fl ector to infer names

Slide 46

Slide 46 text

No content

Slide 47

Slide 47 text

No content

Slide 48

Slide 48 text

DRY variables with meta- programming

Slide 49

Slide 49 text

No content

Slide 50

Slide 50 text

Count lines of code with `cloc`

Slide 51

Slide 51 text

833

Slide 52

Slide 52 text

Ruby allows us to create Ruby-ish libraries

Slide 53

Slide 53 text

Ruby guides us to write Ruby-ish code

Slide 54

Slide 54 text

Concusion

Slide 55

Slide 55 text

We can enjoy Ruby more by writing Ruby-ish code

Slide 56

Slide 56 text

Let Ruby guide us

Slide 57

Slide 57 text

Find your own problem

Slide 58

Slide 58 text

Solve it with Ruby-ish way

Slide 59

Slide 59 text

Happy hacking!