Top Banner
Coding Dojo: Erlang [email protected] Vladimir Tarasow [email protected]
27

Coding Dojo: Erlang

Dec 14, 2014

Download

Documents

Arkadi Shishlov

http://meetu.ps/hxHVz
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Coding Dojo: Erlang

Coding Dojo: Erlang

[email protected] Tarasow [email protected]

Page 2: Coding Dojo: Erlang

● Erlang/OTP● EUnit● Rebar● IntelliJ IDEA 11 CE + Erlang plugin● ERL shell● MochiWeb's reloader.erl

https://github.com/mochi/mochiweb/blob/master/src/reloader.erl

● erldocs.com

Today's tools

Page 3: Coding Dojo: Erlang

● Agner● Sublime Text 2 + SublimErl● Eclipse + ErlIDE● Emacs● Elixir

Some other day tools

Page 4: Coding Dojo: Erlang

● Functional language● Unusual syntax● Forces into concurrent

programming paradigm● Robust VM● Patterns for scalable services● OTP

Erlang in nutshell

Page 5: Coding Dojo: Erlang

How's your Erlang homework?

Page 6: Coding Dojo: Erlang

1. Local file-system directory and its subdirectories contains large number of text files

2. Extract unobfuscated e-mail addresses; together with people names, if possible

3. Write the list of unique e-mails into specified output file

Kata: Grep

Page 7: Coding Dojo: Erlang

Coding Dojo

Page 8: Coding Dojo: Erlang

Coding Dojo is a meeting where a bunch of coders get together to work on a programming challenge.

They are there to have fun and to engage in Deliberate Practice in order to improve their skills.

What is the Coding Dojo?

Page 9: Coding Dojo: Erlang

● Sensei● Moderator● Pair:

○ Pilot○ Navigator

● Audience

Roles

Page 10: Coding Dojo: Erlang

Responsible for:● No long discussions without the code.● Working code by the end of the iteration.● Tests are written during the iteration.● Green tests by the end of the iteration,

otherwise the next iteration begins by making tests green.

● Progress on fulfilling the Kata.

Sensei

Page 11: Coding Dojo: Erlang

Responsible for:● facilitating attendees to obey the

working agreements● conducting the retrospective

Moderator

Page 12: Coding Dojo: Erlang

Pair of two developers working and talking at the PC in order to complete the Kata.

Pair consists of the pilot and the navigator.

The pilot codes and the navigator helps the pilot to understand what has been done in the previous iterations and what the pair should do now.

Pair

Page 13: Coding Dojo: Erlang

Working on KataAt the Dojo one can't discuss a form without code, and one can't show code without tests.

Principles

Page 14: Coding Dojo: Erlang

TimeboxingPair works during a fixed period of time.

SwitchingThe person who enters into the coding timebox begins to act as a pilot. The person who was the pilot during the previous iteration switches to the position of the navigator.

Principles

Page 15: Coding Dojo: Erlang

● Ringtones of mobile phones are off. A person can answer a call, but he or she must leave the room to do it.

● Only the pair at the PC can talk loud.● Sensei can interfere and talk loud by his or

her own decision.

Respect

Page 16: Coding Dojo: Erlang

● All discussions away from the PC must be made in the way not to spoil the pair’s deep diving into the Kata.

● If a person wants to ask or suggest smth to the pair, he or she should raise the hand and wait for the moderator for permit.

● Only one person from the observers can talk at a time.

Respect

Page 17: Coding Dojo: Erlang

Working Agreement

Page 18: Coding Dojo: Erlang

? Randori, Parisian, Pairs ?

● Applicability of unit and functional tests

● Randori round time● Switching: round-robin, by request

Working agreement

Page 19: Coding Dojo: Erlang

1. Join Erlang cluster2. Send grep module to peers and

start grep worker there3. Send messages with files content4. Receive list of e-mail5. Aggregate results

Kata: Grep - Erlang cluster

Page 20: Coding Dojo: Erlang

1. Ping LAN bootstrap nodes- bootstrap@extensa- bootstrap@hal9011

2. Workes are:+ nodes()- worker if name starts with "worker"

*except coordinator local VM [node()] to simplify programming and prevent aggregator bottlenecks

Join Erlang cluster

Page 21: Coding Dojo: Erlang

1. The functionality is implemented by module 'grep'

2. 'grep' is also an (Erlang) application3. use code:get_object/1 to read the module

beam4. use rpc:(multi)call/4, code:load_binary/1,

erlang:spawn/4 to load beam and start application remotely

Send code to peers

Page 22: Coding Dojo: Erlang

1. API signature:grep:grep(Dir) ->

[ email1@domain, email2@domain2 ]2. Obtain list of workers by calling nodes/03. Scan directory recursively and create a

tuple:Work = { self(), Content }

4. Send message to next peer:{ grep_worker, Node } ! { self(), Work }

Send work

Page 23: Coding Dojo: Erlang

1. After all work units are sent - receive all replies or timeout occur:

recv(N) -> c:flush(), recv([], N).recv(A, 0) -> A.recv(A, N) ->

receive{emails, Mails} -> recv([Mails | A], N-1)

after 1000 -> Aend.

2. Flatten, sort, uniq results

Receive result

Page 24: Coding Dojo: Erlang

1. Use OTP gen_server and supervisor behaviour-s with simple_one_for_one strategy

2. application:start/1 calls grep:init/13. grep:init/1 spawns a number of workers

that is equal to core count as returned by erlang:system_info(schedulers)

4. grep:init/1 registers all workers with global:register_name/2

Worker workflow with OTP

Page 25: Coding Dojo: Erlang

Venue

Book give-away

Credits

Page 26: Coding Dojo: Erlang

Latvian Developers Networkhttp://www.ldn.lv http://fb.me/LatvianDevelopersNetwork @LVDevNet

Arkadi [email protected]://bitbucket.org/arkadi

Vladimir Tarasowhttp://about.me/NetRat

Page 27: Coding Dojo: Erlang

This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License. To view a copy of this

license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/