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

Coding Dojo: Erlang

Embed Size (px)

DESCRIPTION

http://meetu.ps/hxHVz

Citation preview

Coding Dojo: Erlang

[email protected] Tarasow [email protected]

● 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

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

Some other day tools

● Functional language● Unusual syntax● Forces into concurrent

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

Erlang in nutshell

How's your Erlang homework?

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

Coding Dojo

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?

● Sensei● Moderator● Pair:

○ Pilot○ Navigator

● Audience

Roles

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

Responsible for:● facilitating attendees to obey the

working agreements● conducting the retrospective

Moderator

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

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

Principles

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

● 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

● 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

Working Agreement

? Randori, Parisian, Pairs ?

● Applicability of unit and functional tests

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

Working agreement

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

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

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

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

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

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

Venue

Book give-away

Credits

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

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

Vladimir Tarasowhttp://about.me/NetRat

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/