why code in node.js often get rejected by soundcloud

62
Why code in Node.js often get rejected by SoundCloud Phil Calçado - SoundCloud @pcalcado http://philcalcado.com Tuesday, October 1, 13

Upload: phil-calcado

Post on 08-Sep-2014

4.033 views

Category:

Technology


1 download

DESCRIPTION

From: http://gotocon.com/aarhus-2013/presentation/Why%20code%20in%20Node.js%20often%20gets%20rejected%20by%20SoundCloud At SoundCloud we ask candidates to send us some code before inviting them in for interviews. Candidates can use whatever language they want, and over the past years we saw a massive rise on the number of submissions using server-side JavaScript. Unfortunately, too many submissions are asynchronous blobs of procedural code. JavaScript is a fairly functional language, and over the past decades Functional Programming developed interesting solutions for many of the problems we face when writing Node.js and regular JavaScript. Let's talk about how to leverage good old Functional Programming techniques to make code less coupled and more readable!

TRANSCRIPT

Page 2: Why code in Node.js  often get rejected by SoundCloud

2011: Phil zieht nach Berlin

Tuesday, October 1, 13

Page 3: Why code in Node.js  often get rejected by SoundCloud

Tuesday, October 1, 13

Page 4: Why code in Node.js  often get rejected by SoundCloud

~ 200 million users / month

> 11 hours of audio uploaded every minute

Tuesday, October 1, 13

Page 5: Why code in Node.js  often get rejected by SoundCloud

Tuesday, October 1, 13

Page 6: Why code in Node.js  often get rejected by SoundCloud

http://bit.ly/15DToNK

hiring @ SoundCloud

Tuesday, October 1, 13

Page 7: Why code in Node.js  often get rejected by SoundCloud

Phone

Code Review

Interviews

Offer

Tuesday, October 1, 13

Page 8: Why code in Node.js  often get rejected by SoundCloud

Phone

Code Review

Interviews

Offer

Tuesday, October 1, 13

Page 9: Why code in Node.js  often get rejected by SoundCloud

challenge until late 2012

Tuesday, October 1, 13

Page 10: Why code in Node.js  often get rejected by SoundCloud

you can choose any language.

0

10

20

30

40

Ruby Java JavaScript (Node.js) C Clojure Scala

% of submissions ~2011-2012

Tuesday, October 1, 13

Page 11: Why code in Node.js  often get rejected by SoundCloud

you can choose any language.

0

10

20

30

40

Ruby Java JavaScript (Node.js) C Clojure Scala

rejected before interview invited for inverview

Tuesday, October 1, 13

Page 12: Why code in Node.js  often get rejected by SoundCloud

new challenge

Tuesday, October 1, 13

Page 13: Why code in Node.js  often get rejected by SoundCloud

you can choose any language.

0

7.5

15

22.5

30

Ruby Java JavaScript (Node.js) Go Clojure Scala

% of submissions on the past ~1 year

Tuesday, October 1, 13

Page 14: Why code in Node.js  often get rejected by SoundCloud

you can choose any language.

0

7.5

15

22.5

30

Ruby Java JavaScript (Node.js) Go Clojure Scala

% of submissions on the past ~1 year

Tuesday, October 1, 13

Page 15: Why code in Node.js  often get rejected by SoundCloud

you can choose any language.

0

7.5

15

22.5

30

Ruby Java JavaScript (Node.js) Go Clojure Scala

rejected before interview invited for inverview

Tuesday, October 1, 13

Page 16: Why code in Node.js  often get rejected by SoundCloud

you can choose any language.

0

7.5

15

22.5

30

Ruby Java JavaScript (Node.js) Go Clojure Scala

rejected before interview invited for inverview

WTF?

Tuesday, October 1, 13

Page 17: Why code in Node.js  often get rejected by SoundCloud

http://bit.ly/J1aLNn

don’t get me wrong

we are all hipsters

Tuesday, October 1, 13

Page 18: Why code in Node.js  often get rejected by SoundCloud

Tuesday, October 1, 13

Page 19: Why code in Node.js  often get rejected by SoundCloud

Not OO, not Functional...Just (bad) Procedural code.

Tuesday, October 1, 13

Page 20: Why code in Node.js  often get rejected by SoundCloud

http://bit.ly/JiECRpTuesday, October 1, 13

Page 21: Why code in Node.js  often get rejected by SoundCloud

we don’t need this complicated stuff.this is not java, you know.

Tuesday, October 1, 13

Page 22: Why code in Node.js  often get rejected by SoundCloud

http://bit.ly/JiFSnq

so how do we structure our app?

Tuesday, October 1, 13

Page 23: Why code in Node.js  often get rejected by SoundCloud

what to use?

(decent)procedures?

Tuesday, October 1, 13

Page 24: Why code in Node.js  often get rejected by SoundCloud

Tuesday, October 1, 13

Page 25: Why code in Node.js  often get rejected by SoundCloud

Tuesday, October 1, 13

Page 26: Why code in Node.js  often get rejected by SoundCloud

what to use?

objects?

Tuesday, October 1, 13

Page 27: Why code in Node.js  often get rejected by SoundCloud

Tuesday, October 1, 13

Page 28: Why code in Node.js  often get rejected by SoundCloud

what to use?

...functions?

Tuesday, October 1, 13

Page 29: Why code in Node.js  often get rejected by SoundCloud

http://bit.ly/JFbZt8Tuesday, October 1, 13

Page 30: Why code in Node.js  often get rejected by SoundCloud

http://bit.ly/JFbZt8

“SICP and some of the Sussman & Steele "Lambda the ..." papers made a big impression on me years before, although I did not understand their full meaning then.Remember, I was recruited to "do Scheme" [...] My interest in languages such as Self informed a subversive agenda [...]. Likewise with first-class functions, which were inspired by Scheme [...]”

Tuesday, October 1, 13

Page 31: Why code in Node.js  often get rejected by SoundCloud

http://bit.ly/JiEQYMTuesday, October 1, 13

Page 32: Why code in Node.js  often get rejected by SoundCloud

Tuesday, October 1, 13

Page 33: Why code in Node.js  often get rejected by SoundCloud

Tuesday, October 1, 13

Page 34: Why code in Node.js  often get rejected by SoundCloud

Tuesday, October 1, 13

Page 35: Why code in Node.js  often get rejected by SoundCloud

Tuesday, October 1, 13

Page 36: Why code in Node.js  often get rejected by SoundCloud

Tuesday, October 1, 13

Page 37: Why code in Node.js  often get rejected by SoundCloud

http://bit.ly/JiF7ef

going old school

Tuesday, October 1, 13

Page 38: Why code in Node.js  often get rejected by SoundCloud

e.g. passing functions around

Tuesday, October 1, 13

Page 39: Why code in Node.js  often get rejected by SoundCloud

we see a lot of this

Tuesday, October 1, 13

Page 40: Why code in Node.js  often get rejected by SoundCloud

1st, we extract what is common

Tuesday, October 1, 13

Page 41: Why code in Node.js  often get rejected by SoundCloud

then we refactor our functions

Tuesday, October 1, 13

Page 42: Why code in Node.js  often get rejected by SoundCloud

and we send them as arguments

Tuesday, October 1, 13

Page 43: Why code in Node.js  often get rejected by SoundCloud

e.g. closures not only for objects

Tuesday, October 1, 13

Page 44: Why code in Node.js  often get rejected by SoundCloud

we see a lot of this

Tuesday, October 1, 13

Page 45: Why code in Node.js  often get rejected by SoundCloud

we can keep writeComment as it is

Tuesday, October 1, 13

Page 46: Why code in Node.js  often get rejected by SoundCloud

and we add a function with two closures

Tuesday, October 1, 13

Page 47: Why code in Node.js  often get rejected by SoundCloud

and we add a function with two closures

immutable

Tuesday, October 1, 13

Page 48: Why code in Node.js  often get rejected by SoundCloud

and we add a function with two closures

immutablemutable

Tuesday, October 1, 13

Page 49: Why code in Node.js  often get rejected by SoundCloud

now we don’t need to pass in the kitchen sink

Tuesday, October 1, 13

Page 50: Why code in Node.js  often get rejected by SoundCloud

e.g. functions all the way down

Tuesday, October 1, 13

Page 51: Why code in Node.js  often get rejected by SoundCloud

we see a lot of this

Tuesday, October 1, 13

Page 52: Why code in Node.js  often get rejected by SoundCloud

first we extract common protocol

Tuesday, October 1, 13

Page 53: Why code in Node.js  often get rejected by SoundCloud

then we clean up our functions

Tuesday, October 1, 13

Page 54: Why code in Node.js  often get rejected by SoundCloud

then we use them.

Tuesday, October 1, 13

Page 55: Why code in Node.js  often get rejected by SoundCloud

then we use them. redundant?

Tuesday, October 1, 13

Page 56: Why code in Node.js  often get rejected by SoundCloud

http://bit.ly/JiETndTuesday, October 1, 13

Page 57: Why code in Node.js  often get rejected by SoundCloud

our “framework”:1 - Extract protocol in

“combinators”2 - Keep mutable state in

closures

Tuesday, October 1, 13

Page 58: Why code in Node.js  often get rejected by SoundCloud

no scary monads required

Tuesday, October 1, 13

Page 59: Why code in Node.js  often get rejected by SoundCloud

there is plenty to learn fromTuesday, October 1, 13

Page 60: Why code in Node.js  often get rejected by SoundCloud

in the javascript community tooTuesday, October 1, 13

Page 61: Why code in Node.js  often get rejected by SoundCloud

phil calçado

http://philcalcado.com@pcalcado

www.soundcloud.com

Tuesday, October 1, 13

Page 62: Why code in Node.js  often get rejected by SoundCloud

How to Design Programs - http://bit.ly/K0BfrLStructure and Interpretation of Computer

Programs - http://bit.ly/K0BjYm

The Art of the Metaobject Protocol http://amzn.to/K0BqU1

Purely Functional Data Structures http://amzn.to/JFn4KG

Let Over Lambda - http://amzn.to/IMMkNO

An Introduction to Lambda Calculi for Computer Scientists - http://amzn.to/IX8d1B

All drawings are available as t-shirts from the awesome Diesel Sweeties - http://dieselsweeties.com/

Tuesday, October 1, 13