Slide 1

Slide 1 text

Building the Ruby × Elixir Conf App

Slide 2

Slide 2 text

皰玡㳓 @zetavg ‣ Բ狝夺䌌Ꭺ಑褾 Developer ‣ Ruby, JavaScript, Elixir, ReasonML, C ‣ ࡅ稭碝ᄤ獖槹ጱದ蔩 蚤桽螂犋݄ ‣ 磧蜱ࣁሻӞ犚 Functional 承᥺ ‣ 瓵మฎአ硳ሲ牏ߝ搡膏硳胼ٍّጱොୗ樄咳敟誢

Slide 3

Slide 3 text

Conference apps ‣ Schedule, personal schedule, map, events, announcements ‣ Facebook F8 ‣ Google I/O ‣ Apple WWDC ‣ Web Summit ‣ Build-in chat for attendees

Slide 4

Slide 4 text

Let's build one for Ruby × Elixir Conf!

Slide 5

Slide 5 text

What to use? ‣ App: ReasonML ‣ Backend: Elixir ‣ API: GraphQL ...why so many new things?

Slide 6

Slide 6 text

A helpful programming language can teach you how to write robust programes

Slide 7

Slide 7 text

Some of them restricts you with human defined rules ̿纷ୗ݈翥捌犋螂ԧ牧অ簡̀

Slide 8

Slide 8 text

Others teaches you some CS ways to think: data structures, theory of computation, type theory, formal methods ̿߶牧ܻ㬵౯䛑扗蝡䰬௏ᘍ㺔氂牏蝡愊మဩ磪綠笙牧憽஑݈蝱ྍԧ̀

Slide 9

Slide 9 text

Elixir Functional, Concurrent, Fault-tolerance, Extendable via macros, Based on Erlang

Slide 10

Slide 10 text

Functional “I don’t want to hide data. I want to transform it.” (Quoted from “Programming Elixir” by Dave Thomas)

Slide 11

Slide 11 text

Concurrent “Most programmers treat threads and processes as a necessary evil; Elixir developers feel they are an important simplification.” (Quoted from “Programming Elixir” by Dave Thomas)

Slide 12

Slide 12 text

Concurrent https://hashrocket.com/blog/posts/websocket-shootout

Slide 13

Slide 13 text

Concurrent https://hashrocket.com/blog/posts/websocket-shootout

Slide 14

Slide 14 text

Expectable Conventions length [1, 2, 3] # "length" tuple_size {:ok, "hello"} # "size" ̴ https://elixir-lang.org/getting-started/basic-types.html#lists-or-tuples

Slide 15

Slide 15 text

More about Elixir (౯ᛔ૩ጱ殼ଧ) 1. elixirschool.com物獈槹ݻጱ承ဩ硽䋊 2. elixir-lang.org物ਥො guides 䌃஑盄অ 3. 獢碍ୗ翥纷: ℂ Elixir & Phoenix 獈槹牐 羬ڜ物य़വ牧Ӿ෈牧অ捝ฃ睞 4. Programming Elixir物౯ፓ獮ݝ磪፡蝡Ӟ๜ (ׯ) ୌ捍䷱䌃螂 Functional ጱ๏݋獨ݝ捝 1 ~ 2牧ݢ犥捝ک 3 ౲ 4ҁ౲ℂ 3牏4 樄ত 捝҂ٚ㵕ಋ牧犋簁䨝ᤩ২֦̿蝡䰬䌃疰 OO 眖ࠡ牐̀ҁ藮

Slide 16

Slide 16 text

ݢ犥肯䔶ᘏ౯ݶԪࣁ Ruby × Elixir Conf 拻 Elixir ጱ捍纷 ᒫӞॠӥ܌ࣁ 1001

Slide 17

Slide 17 text

ReasonML Write type safe, functional, fast code with the help form OCaml. Compiles to JavaScript.

Slide 18

Slide 18 text

ReasonML ‣ Reason (syntax): JavaScript-developer-friendly syntax of OCaml ‣ BuckleScript: OCaml to JavaScript compiler

Slide 19

Slide 19 text

Benefits form OCaml ‣ Battle-tested language created in 1996 ‣ Functional and immutable by default ‣ Solid type system: structural, inferred and sound ‣ Flow is written in OCaml! ‣ Ecosystem & tooling ‣ ocaml-language-server

Slide 20

Slide 20 text

Why ReasonML ‣ Type safety ‣ Fast compile time ‣ Generates fast code ‣ The language of React ‣ When Reason's creator created React, the prototype was written in Standard ML1 ‣ ReasonReact: All your ReactJS knowledge, codified ‣ Fun 1 OCaml is also a member of the ML programming language family.

Slide 21

Slide 21 text

Pattern Matching

Slide 22

Slide 22 text

Pattern Matching - Switch

Slide 23

Slide 23 text

Pattern Matching - Switch in function ‣ ଉ憎አဩ

Slide 24

Slide 24 text

Pattern Matching - Function ‣ 䌘㻌㮆 argument ፗ矑狶 pattern matching 犖ݢ犥አ fun ጱ䌃ဩ

Slide 25

Slide 25 text

Varient Type ‣ ݢ犥ቘ薹౮胼癲独ጱ enum ‣ አ type 㬵狶 pattern matching ‣ 犖胼አ㬵玟獤㻌֖2 e.g.: Pt(2.)牏Px(12.) 2 Mars Climate Orbiter, costed hundreds of millions of US dollars, crashed because of a pound-force-seconds and newton-seconds type mismatch in 1999.

Slide 26

Slide 26 text

"Option" for nullable ‣ 疰ฎ Haskell 愊ጱ Maybe a = Just a | Nothing

Slide 27

Slide 27 text

Type System ‣ Prevent mistakes such as typo, null, wrong argument... ‣ Prevent unexpected behavior changes when adding new features ‣ Document!

Slide 28

Slide 28 text

Type system: Structural v.s. Nominal (* These functions takes a list of and returns a . *) let first: 'a list -> 'a = fun (item::_) -> item let second: 'a list -> 'a = fun (_::item::_) -> item (* * The type of function that takes a list of string and returns a string. * Note that this type signature is different from the two functions above. *) type listOfStringSelector = string list -> string (* A function that applies a listOfStringSelector to a list of string. *) let selectListOfStringBy: listOfStringSelector -> string list -> string = fun f -> fun l -> f l

Slide 29

Slide 29 text

Type system: Structural v.s. Nominal let second: 'a list -> 'a = fun (_::item::_) -> item type listOfStringSelector = string list -> string let selectListOfStringBy: listOfStringSelector -> string list -> string = fun f -> fun l -> f l (* * The structure of * "function that takes a list of and returns a " * is comaticatible with * "function that takes a list of string and returns a string ", * so the code compiles! *) let b = ["a"; "b"; "c"; "d"] |> selectListOfStringBy second

Slide 30

Slide 30 text

Type system: Inferred We can remove all the type annotations. OCaml will infer them correctly. (* * OCaml will know that the type of these functions are "'a list -> 'a", * as the argument is patteren-matched as a list and will return an * item from the list. *) let first = fun (item::_) -> item let second = fun (_::item::_) -> item

Slide 31

Slide 31 text

More about ReasonML ‣ 2ality Ӥጱ "What is ReasonML?" 羬ڜ෈ ‣ Reason ‣ ReasonReact ‣ BuckleScript

Slide 32

Slide 32 text

GraphQL Data query language

Slide 33

Slide 33 text

GraphQL ‣ Graph data query language ‣ Schema first development ‣ Easily parallels frontend & backend develop ‣ Easier communication for developers ‣ No need of extra document

Slide 34

Slide 34 text

Sketch out the schema using Apollo Launchpad

Slide 35

Slide 35 text

Using GraphQL with Reason

Slide 36

Slide 36 text

Demo

Slide 37

Slide 37 text

WIP https://github.com/XConf

Slide 38

Slide 38 text

Thanks & Q&A https://github.com/XConf