00:00:15.599
so good morning everybody I hope you had a a good Rubicon so far uh my name is
00:00:21.240
Matt imunity I'm meris on Twitter and these are websites where you can find me
00:00:27.039
um if you have any questions and I can answer them at the end of this talk please send me a tweet and I'll reply to
00:00:32.520
you as soon as I can before we start um I want to let you know that today is a very special day for many reasons the
00:00:39.600
first one is because it's Theos muos it's the Day of the Dead um so if you're Hispanic or if you like tacos you might
00:00:45.840
want to really enjoy this day and tonight go get some margaritas and Tacos um and if you're Hispanic and if you
00:00:52.640
celebrate well have fun and it's also today my birthday
00:00:58.920
um so um I I live in San Diego California
00:01:03.960
but my mom is back in France and she's always worried that I don't have a lot of friends so I just want to show that I
00:01:10.560
have some friends so I'm going to record it and you guys are going to sing for me please happy
00:01:16.320
birthday so um in English is fine my mom speaks English you can speak in German team if
00:01:22.840
you want all right so one two three happy birthday to
00:01:31.680
happy birthday to you happyday
00:01:39.079
dear Happy Birthday to
00:01:49.240
You Well thank you it's also Brian help Camp birthday so if you want to make him
00:01:54.320
happy go on code climate and give it a try I'm sure we'll be really happy all right let's get started um so before we
00:02:01.439
talk about programming languages I sat down with a linguist and I asked her can
00:02:06.840
we talk about human languages let's talk about it um I speak a couple languages but I want to understand a bit more what
00:02:13.520
it means uh to study languages and we talked about it and she came up with this theory that was um
00:02:22.160
that was discovered quite a while back by two uh linguists called sapan worth
00:02:27.480
and they basically came up with the conclusion that um The Way languages are designed
00:02:35.160
affect the way we see the world the world view we have and the way we behave
00:02:40.239
too so it seems logical um when you think about it but they had to actually prove it so they did a lot of research
00:02:46.800
and an example of that is a tribe that they found in the middle of nowhere I'm not sure where it was but this tribe
00:02:53.599
didn't have a way of talking about the past or the future so they could never say yesterday this happened or tomorrow
00:03:00.319
we will do that they were stuck in the present and the way there would be
00:03:05.560
okay we don't we don't want to hear any more of this all right so for those of you who don't know we just walked in
00:03:11.959
today is Matt's birthday they just sung for me thank you oh you bastard well you may have sung for him
00:03:19.120
but did you get six pack of oh wow thank you guys thank you m thank you thank you
00:03:26.760
happy birthday Matt he service when he talks so so I have to drinking now if we can't sing to you you got at
00:03:33.799
least drink the be all right it's on the east coast yeah so we're good so we're late thank you
00:03:39.599
guys happy birthday thank you all right so I was explaining that
00:03:47.159
languages affect our behaviors and the the worldview and um this tribe really
00:03:53.239
was stuck in the present because the language didn't allow them to talk about the past or the
00:03:58.280
future so based on that I wanted to study more programming languages but I'm not a linguist and I'm not I was not
00:04:05.239
really good at school so I wasn't really sure how to do it but I did what I could and I came up with a few things first I
00:04:12.760
discovered a few things you should not do at least things I didn't work for me the first thing was to study a language
00:04:18.799
by just looking at hello world and say okay I don't like it or I like it hello world is a very bad way of looking at
00:04:25.600
language it's like if you would hear one sentence in one language and you would judge the entire language based on that
00:04:31.160
sentence and that sentence might actually doesn't mean much the other thing I realized is that syntax is a
00:04:37.759
very bad way of looking at a language it is true that it's the first thing you see it's it's true that when you look at
00:04:43.440
a language you look at the syntax and you might have a feeling about it you might react to it but it's actually not
00:04:50.520
the right way of looking at the language because a syntax hides a lot of Concepts behind it so how did I do it how do I
00:04:58.199
think we should do it well I think you first should look at the philosophy of the language you should think about it
00:05:03.919
what did the language what what did the language designer was trying to do with his language or her
00:05:10.080
language also you want to make sure you find the right use of the language you don't want to have uh a Michael Jordan
00:05:17.639
language playing baseball or golf because it just doesn't work and it's not because of the hands actually
00:05:22.960
Michael Jordan used his hands on all these ports but he sucked at two of them um so it's not that simple but what you
00:05:30.199
really want to do is to be curious about it and come up to the language with new
00:05:35.560
eyes try to get rid of the expectations you have the worldview you're coming
00:05:40.720
from and try to look at it like if it was the first language you would learn and try to understand it so I studied a
00:05:47.160
few languages I came up with this greed and it was very boring so I said forget about it um I focused on seven languages
00:05:56.199
and I was going to talk to you about seven languages but my talk was about two hours long and I realized of these
00:06:02.440
seven languages there only four languages I really like um or that are really interesting that are very
00:06:09.039
interesting to study based on our knowledge of Ruby so I decided to focus
00:06:14.800
on three languages closure Scala and go then on the second part of the talk um I
00:06:21.960
tried to think about how these languages affected the way I write rubby
00:06:27.880
code so I do write a bit of these languages I write way more rubic code than I write closure go and and scalac
00:06:34.919
code but by studying these languages and by writing some amount of of these other
00:06:40.520
languages I realized the way I was writing rubby code changed and my view of rubic code Chang and my view of mats
00:06:48.280
as a language designer actually also changed so the format of the talk of the
00:06:53.680
the language study will be very simple I will take a Rubik class so this is the example where I create a a class with
00:07:00.840
two Getters and Setters I have a constrictor I have a start method at the end I create an instance of the object
00:07:07.599
and then I call method on it so that's kind of my halo world but a bit more complex so I can compare languages and
00:07:13.919
give me an idea of what it could look like that's kind of my entry point into the language now it's not a good way of
00:07:19.560
judging the language again it's not a way of judging anything it's just a way to try to to take something we all know
00:07:26.400
and apply it to something else then for each language I will look at a use case what's the main use case I found for the
00:07:32.440
language what's the philosophy what do I dislike what do I I like about it and
00:07:38.039
where to start if you want to learn the language so let's start by go go is a
00:07:43.319
language by Google that was released a few years ago it's a compile language um
00:07:49.080
it's a structural type language so what that means is that instead of having uh
00:07:54.560
functions taking um typed arguments the functions will take will take objects
00:08:01.240
that respond to a certain structure a certain way the object is defined so concretely what that means is that you
00:08:07.080
can define a function that would that could be applied to any object that respects a certain interface and an
00:08:13.919
interface is basically saying these are the criteria for my object that need to be respected so I can call this function
00:08:20.240
on that um go is also an objectoriented language which might be surprising if you really didn't study go uh but it's a
00:08:27.639
fully objectoriented language but it's a lightweight objectoriented language and
00:08:32.719
they really Revisited the way objectoriented um programming works and they they took a Different Twist on it
00:08:39.000
it's also a fully functional language so you have higher order functions um you have Anonymous functions you have all
00:08:45.040
these things um what you saw Jim do this morning in a keynote you can also do that with with go um not sure why you
00:08:52.200
would want to do it but you can do it learning go is actually easy to normal
00:08:58.440
um if you have any background in C is slightly easier because there's a concept of a pointer and you might not know what a pointer is but um because
00:09:05.560
the language is very small you actually you you get in the language really quickly and you can have fun um pretty
00:09:11.959
fast so here's an example of the Ruby class I showed it to you at the beginning ported to Ruby so we Define
00:09:19.320
the package which is the name of the application we're in basically of the library then we import a library which
00:09:25.640
is like requireing Ruby um then we create a new class which is the equivalent of a class it's a type which
00:09:32.240
is a struct that has two um members name and topic and both of them are strings
00:09:37.279
and then we Define this function start that can be applied to a pointer of a presentation class so here it is now we
00:09:44.760
could change that to to have an interface so wow I don't know what's
00:09:49.959
going on there sorry um so we have this start method that will return a string and then we concatenate the string based
00:09:57.200
on the two um Vari or the two members name and topic
00:10:02.240
for the struct then we have the function main that gets called at the beginning when the program starts we create an
00:10:08.000
instance of talk passing two different um arguments so Matt and go for name and
00:10:14.440
topic and then we print the output of the function this it's not too too hard
00:10:19.560
to follow uh seems pretty simple it doesn't have all the semicolons it kind of look a little bit like Ruby but not
00:10:25.720
too much so what's the main use case um for me the best use the best use case
00:10:32.040
for go is concurrency and I will show that to you by um sh an example of a
00:10:37.959
sample code I wrote and the idea was I want to call three websites at the same
00:10:43.800
time and I want to concurrently fetch three resources wait for it without blocking and then get all the responses
00:10:50.880
coming at the end so the code um again we Define a package we import three
00:10:56.839
libraries then we Define an array of strings that has the three different URLs we Define a new type um which
00:11:04.040
contains three elements URL response which is a pointer to http response
00:11:10.440
which comes from net HTTP and then an error so we can um look at the error if
00:11:15.920
we have an error then um this is the entire code for my application and it
00:11:22.120
highlights the use of concurrency in go so uh we have this function that takes a
00:11:29.560
param which is an array of strings and we will send back HTTP responses an
00:11:35.120
array of HTTP responses and we create what we call a channel and a channel is the way go does concurrency you
00:11:42.519
basically have this this concept of a channel that's in the middle and we're going to write to this Channel and read
00:11:48.040
to this channel so we don't share memory by talking between the different threads or however we do concurrency we talk
00:11:54.360
through this broker in the middle um which is a channel so we create a channel that's buffered with a certain
00:12:00.160
length then we create an an an an empty array for the responses and then we look
00:12:05.880
through the URLs that were being passed and we start this go function so this is an anonymous function that's a go
00:12:12.920
function meaning that it's async so it gets started separately can be in different threats or not depending on
00:12:18.680
the system resources and this function will take a URL will print it then it
00:12:24.279
will do an HTTP get of the URL and will respond with a toppo which is the
00:12:29.839
response object and will be the error code um that might happen if the resource is not available then once we
00:12:36.680
have that we create this object the HTTP response object that we um defined before we create an instance of that and
00:12:44.040
we push it into the channel so this is the channel we have here um finally we
00:12:49.320
call this this Anonymous function by passing the URL that was coming from um
00:12:55.320
the looping we did through the URLs then once we do that we do a for Loop so we just look through we just
00:13:02.720
basically Loop and we say if there's anything in the channel get it for me and if we have something we'll print the
00:13:09.920
URL that was that was coming from the channel and then we'll appen the response to the array and if we add all
00:13:16.680
the responses based on the length of the URLs we'll return that otherwise what we will do is just print a little Dot and
00:13:23.399
slip for a little bit so the loop is not too tight so that's it that's the entire code to use it we have a main function
00:13:30.320
and we say call this call um get all the URLs and for each of them we're going to
00:13:36.000
print it and see the result when we compile this code so in go you compile
00:13:41.360
to machine code directly so you just say go build this is the file I have and you print it out as a as a a binary as a
00:13:49.160
machine code file and you can see actually comes back um I say I want to fetch this URL this URL and this URL but
00:13:56.639
the the order they come back is is actually different so we implemented a very nice way without sharing memory of
00:14:04.680
doing concurrency and go is really good at that go is also good at a lot of other things but for me that's the main
00:14:10.480
use case for go um IMX concurrency easy so what's the philosophy of the
00:14:16.839
language well um really go tries to be the new SE it
00:14:23.240
tries to be um a very simple very brief language you
00:14:29.120
don't have to write a lot of code you keep it very isolated it fits in your brain and it's following the Unix
00:14:35.320
philosophy so taking the the Unix and c as a language to the next level which is
00:14:41.839
concurrency and that's really what C is trying to do what I don't like about
00:14:46.880
about um go sorry what I don't like about go is that it's sometimes a bit too low level sometimes I wish it was a
00:14:54.560
bit higher level um so we could do things it would be more accessible for more more people um there's also the
00:15:01.120
fact that go doesn't have a really good garbage collector so if you compare with the jvm um of course the garbage
00:15:07.000
collector is not as good it's decent and you can get really good um performance
00:15:12.360
it has also a limited adoption so that's not really true anymore since One auto got released and um a lot of people
00:15:19.600
started using it Hampton Catlin who wrote haml um used that in his company
00:15:24.880
for a very interesting project you should talk to him about that Google uses it also internally and um they
00:15:31.120
replace a bunch of C++ code by Go including um a project that they have
00:15:36.639
that let you download Chrome so every time you go and you download Chrome the binary um they add a C++ front end that
00:15:42.920
was taking all these requests and using currency to fit that and they replace that by go uh the other thing I don't really
00:15:49.720
like it comes from the standard Library sometimes you had some weird conventions that are bit surprising to me coming to
00:15:54.839
the language I guess I will just get used to it so what do I like about go
00:16:00.399
well the specs of the language are so simple I actually can get them to fit in my head so if you compare with Ruby Ruby
00:16:08.240
is a very complex language and to actually follow the specs is is hard
00:16:13.959
because you have a lot of flexibility you can do a lot more things go is simpler and I actually enjoy that when I
00:16:19.160
write simple code because I know exactly what the language will do and I know what to expect the CER libraries um of
00:16:25.680
go are really really good you have everything almost in the Stander libraries from a a Proto buffer um to
00:16:33.199
all the the net HTTP um um libraries you have
00:16:39.839
um um you have Json you have you have everything I can remember I'm looking for a specific one I can remember it you
00:16:45.360
really find most of what you need you will find it in the standard libraries and they really try hard to do that
00:16:50.720
concurrency we saw that you have this concept of go routines and the channels that are very efficient and a very
00:16:55.800
simple way of thinking about concurrency without having to use use logs and mutexes um a lot of the conventions are
00:17:03.000
actually sensitive even though sensible even though I complain about it the first in the first slide um you'll see
00:17:09.360
that when you start using go they'll tell you this is how you organize your language they even have a tool that tells you how to format your code you
00:17:15.120
can run it and it basically reformats your code so it follows the convention um it makes things easier when you get
00:17:21.240
started and when you don't know the language and it also helps when you have a team of people trying to follow the
00:17:26.839
same conventions comp ation is fast you can compile a very very big Go app
00:17:31.919
faster than you can start a boot up rails application so it's really really quick okay rails is really slow but um
00:17:38.640
it's still really fast what's that no it's not setting a very high bar um it's basically almost as fast as
00:17:45.559
running a scripting language uh in some cases so it's it's it's really fast so you don't really feel like you have to
00:17:50.640
wait five minutes while it compiles um the way you organize the code is flexible you don't have to do it
00:17:56.559
the the COA they have this concept of package and the way things get compiled and the Linker is really smart it's very nice way of of doing it especially when
00:18:04.000
you come from a scripting language um the take on objectoriented is actually very interesting and I didn't have time
00:18:09.559
to really spend a a lot of time on that but I would really challenge you to look
00:18:15.039
at how they thought about objectoriented and how you can have types and mult or
00:18:20.240
inheritance the way they do it which is not the usual way and how you can share functions between different object
00:18:25.960
types you also have all the features of function programming that we love coming from Ruby um the eror handling is
00:18:32.520
actually very interesting in Ruby uh in in go because coming from Ruby or from
00:18:37.960
java we're used to raising exceptions everywhere if you use reals you know if you don't find a resource we just raise an exception and then we'll do some
00:18:44.400
control flow in go if I just go back quickly um you can see here I was
00:18:52.520
returning I do initialp get and if that return scenario this value will be
00:18:59.280
filled with with the error otherwise it will be Neil and I can actually ignore it and the idea is that um if you raise
00:19:06.159
an exception you will need to catch it at a higher level and now you actually Bridge the concern the the separation of
00:19:12.480
concerns because code that's above needs to know about the code that's underneath and needs to know how to handle it if
00:19:18.240
there's a problem and it's not always the right thing to do so uh what they do and go is that you actually have to
00:19:23.760
handle manually the error which seems a bit odd at first but I really like it and talk about it towards the end when I
00:19:30.520
will explain what I changed in the way I write rubby code documentation is really good for go uh and you can go in all the
00:19:37.200
packages you can see how they writes their code Ino and he makes things uh it makes it for a really good way of
00:19:43.240
learning uh the go syntax and how the go um authors write their own libraries so
00:19:50.360
how do you get started uh the website for go is really good the golang.org they have a tour you can follow the
00:19:55.400
different steps you do it in the browser you don't need to install anything um get started you have a bunch of books um
00:20:01.280
the book on the right is a cheap book that was it's a community book that that was written by um somebody in the
00:20:07.480
community the other ones are professional books it's really easy to get started I would suggest you spend a few hours just to see if you like it or
00:20:14.000
not and uh see if it can challenge you all right let's move on to something
00:20:19.240
totally different we're going from SeaWorld to lisp scheme world and we're going to talk about closure so who who
00:20:26.159
actually knows a bit of closure we have few okay so actually a bunch of you already tried closure so let me share
00:20:33.000
with you my own experience and you might disagree with it but that's my experience so closure is a compile
00:20:38.559
language it's dynamically typed but you can also mention um types so you can say
00:20:44.559
this is a function and it will actually return the specific type so the compiler can optimize it but it's really dyn
00:20:51.240
dynamically type language it's a functional language that tries to be as functional as possible everything should
00:20:56.679
be um a list everything is data it's not technically really true all the time but they're really trying hard it's also
00:21:03.559
objectoriented so that's what people don't always know about closure and actually closure people don't really
00:21:09.400
like to say that but I'll show it to you it's also objectoriented because uh closure tries to be a practical
00:21:15.919
implementation of scheme and sometimes objectoriented programming makes a lot of sense the learning curve uh for
00:21:22.080
closure is normal to nightmare and the reason why I put that is because starting is actually not too hard once
00:21:28.799
you get you stop thinking about C programming and you understand how to write code it's actually pretty easy to
00:21:35.440
get started but the problem I had with closure is as I was learning more and more about it you need to know more and
00:21:41.480
more functions and you need to have all this things fit in your head and you need to be able to context switch back
00:21:46.720
and forth and that becomes really hard uh for me at least in the long term so
00:21:53.120
again the example uh some example at the beginning we Define here a protocol so this is not
00:21:59.799
an implementation this is just documentation my protocol is called talk and it has a function called start that
00:22:06.600
uh will return the speaker on the topic then I create this record which is basically like a class called
00:22:12.480
presentation that has uh takes two arguments in the list name and topic
00:22:18.240
then here I Implement I basically say I'm implementing the protocol called Talk and I Define this method called
00:22:24.520
start that doesn't take any arguments we don't care about what's being passed and would return a concatenated string
00:22:31.480
of this is hi this is the name that's being passed here and I will talk about the topic then to create an instance of
00:22:38.760
this record we say Dev talk that's going to be my instance presentation dot notice the dot here as a presentation
00:22:46.000
mat and and closure so this is the list that will basically be um extracted here
00:22:52.080
and get these two variables and then I call start talk so you can see uh scheme
00:22:57.679
read from left to right okay so this is the example in object-oriented programming now most of
00:23:04.039
the time when you write closure you don't really write code like that I just wanted to show it to you uh because that's what I did for all languages so
00:23:11.080
the best use case I found for closure is data processing um data processing is
00:23:16.960
basically the idea of we have data we want to go through the data extract some value of that and U process it and and
00:23:23.919
handle it and do something special with it uh a use case for that is I want to count all the words in a
00:23:30.640
single file name and this is the implementation I won't go through it because if you've never seen closure um
00:23:37.240
or scheme it might be a bit hard to understand how things work just for the record I had to actually Google that
00:23:42.840
this here operator is called a thrush operator and that's it I just had to
00:23:47.960
Google it so I wanted to share it with you to show that I know something and I learned something uh so thr operator great um so
00:23:57.320
in this case you can see the code is not too big and we're processing the data and we're just passing it through
00:24:02.799
different functions so what's the philosophy of closure well the philosophy is lisp and
00:24:10.559
scheme are really good we really like this languages we like functional programming but we want to get something
00:24:16.679
practical because fully functional programming languages are awesome but
00:24:22.080
then it's hard to build concrete things with them to do something really um
00:24:27.240
efficient with you don't have all the libraries it's not that it's not efficient you don't have the libraries you don't have um potentially a good
00:24:33.679
garbage collector you don't have all the the things you get from the jvm so instead of Reinventing the world let's just put oursel on top of the jvm try to
00:24:40.520
get all the Java developers to come over learn some um some scheme but also offer
00:24:46.000
some of the flexibility of calling doing the interrupt calling into Java um and
00:24:51.559
also doing some objectoriented programming if needed so what I don't like like with
00:24:58.120
closure is the fact that I was lied to I felt I thought it would be very simple I
00:25:04.320
thought oh I'm going to be able to get this closure thing done in a few weeks and then I'll be an expert in closure
00:25:10.200
which turns out you know it took me a while and I went I even to classes and I still feel dumb when I write closure
00:25:16.600
like just getting the namespace right I I just never get the syntax right which is another point it's not always
00:25:22.600
consistent even though it tries to be consistent it's actually not always consistent the other problem I have is
00:25:28.559
that you need to know a lot of the functions in the micros you need to know what they do you have a really good command line tool that will give you the
00:25:35.039
documentation for it but I find myself having a very small brain and having a
00:25:40.480
hard time keeping all of that in my head and I have to look up for functions all the time so granted if I was writing
00:25:46.760
closure every day eight hours a day that would probably after a couple month or years I probably should be able to handle that but right now I have a bit
00:25:53.240
of a hard time with that a smaller issue I had um is that I was thinking he I'm going to write web
00:25:59.880
services in closure I'm going to do cool stuff I'm doing with Ruby but I want concurrency so I'm going to write closure code instead and turns out that
00:26:07.320
the closure Community is not really web oriented it's really about data processing so even though you have a few
00:26:13.279
libraries and few Frameworks that are interesting most people don't really care too much about doing normal web
00:26:19.240
Webby stuff they will do web related stuff but more in the data processing um sense of of the
00:26:26.600
word another big problem I had is the mental contact switch if you go from closure to Ruby uh from closure to Scala
00:26:34.120
from closure to anything you always have to take a few minutes and just think wait wait this is
00:26:39.279
closure this is how I write it when you go back to the other language the same thing and finally one thing I really
00:26:45.679
hate and this I really hate and I really wish I would fix it in closure is the error stack absolutely meaningless if
00:26:52.039
you have any problem with closure you have an exception you have something happening there's no way you could guess
00:26:57.279
what it is is and I first I thought I was just stupid so I asked experts and they're like um let me let's look at the
00:27:03.440
SS code and we'll understand what you did wrong and that's not really the point of having error Stacks so that's a
00:27:10.159
problem I really wish they would solve uh quickly so what do I like about closure well I can tell you for data
00:27:16.480
processing this is really awesome you keep your cut very simple very focused
00:27:21.840
um you get it done it's you really isolate things and you get good performance you can also use a Java
00:27:28.360
interrupt so if you need the library uh you need to do crypto you can actually end up using a Java Library so you have
00:27:34.640
libraries for a lot of things and you can deploy this thing really easily on the jvm so it's it's something um the
00:27:42.120
the fact that's easy to use it's an easy scheme that's practical and really good for data processing so how do you how do you get
00:27:49.760
started well you have a BN bunch of books that are really good I personally recommend um you go to this URL and um
00:27:57.000
you take the catas so it's basically bunch of exercises that teach you The Language by going through step by step
00:28:03.840
uh solving small problems learning how to write scheme inclosure basically and
00:28:08.880
that's a really good way of learning and then just take a small project and try to do it in
00:28:15.360
closure all right let's move on to the last language Scala so Scala is probably
00:28:21.320
the closest language we have from Ruby at least from my perspective
00:28:26.440
um before I get too far into that I just want to to stop and and explain a bit
00:28:31.919
more about about Scala Scala is a compiled language it has static infert
00:28:37.159
Dynamic types uh and actually also structural typing so most of the time
00:28:42.480
you would use static and infot typing infot typing means that if the compiler can guess the type of the object you
00:28:49.640
don't need to mention it so um usually what you do is when you write a method
00:28:55.200
you say this method take this arguments and you Define the the argument types and the return you might also want to
00:29:01.679
document it and otherwise it can be guessed most of the time when you actually implement the method inside the
00:29:08.240
block you usually don't type it you don't have to actually set the types so if you come from Java or if you know a
00:29:14.840
bit of java you know how annoying it can be to or even Objective C I have to to set all the types all the time and
00:29:21.200
especially when you come from Ruby um Scala comes basically brings kind of an
00:29:26.440
alternative of in between these two things the dynamic typing is a new feature you can actually turn on Dynamic
00:29:32.279
typing and just have Scala being written like rubby I'm not sure why you would want to do that but you can do
00:29:38.799
it it's a fully objectoriented language like Ruby and a fully functional language like Ruby the learning for
00:29:46.240
Scala is between the learning curve is between normal and hard I think to get started with Scala is really easy
00:29:52.279
because you can write Scala the way you write rubby code um it's or Java code it's actually interesting because you
00:29:57.880
end up writing this code it looks exactly like your Ruby code and you're like oh yeah I can write Scala and then
00:30:03.159
you take this code and you send that to a Scala expert and he looks at I like dude this is the worst code ever don't
00:30:09.080
do that um but it helps you because you feel productive you start writing code
00:30:14.399
um so I I was really pushed to learn Scala by Marcel Molino from from Twitter
00:30:20.120
and he kind of became my mentor where I write Ruby code in Scala which is bad Scala basically and I send that to him
00:30:27.080
and it's like okay this is what you're going to fix you do this this way this way this way and it makes the learning faster however um Scala is a very
00:30:35.440
complex a very rich language and you have a lot of things that sometimes you might look at and like what's this
00:30:41.399
operator what does that mean and it's it's a bit of putting and that's why it's a bit harder to learn it's not as
00:30:46.760
easy as go for instance so how does it look like well we define a class called presentation
00:30:53.559
that takes two arguments U named arguments name and topic there are strings here we say they value and
00:31:00.360
basically what that means is that once they passed they become immutable V values in the class so we can call them
00:31:07.120
from outside the class and they won't be changed now my name and the topic won't change through the presentation so
00:31:12.240
that's fine um we could use variables but Scala is trying to encourage you to use IM multile types if you can then we
00:31:19.080
Define here instead of defining a function we could Define a function but we don't have to we can have a value
00:31:25.039
that um take all these params and that's a Constructor and that creates this start object which is a value then we
00:31:32.159
say I want a new presentation passing mat and Scala and um then I call it
00:31:37.679
talk. start and it will return the string so what's the use case I kind of scratched my head on that one um
00:31:45.600
basically it's good for service oriented architecture and it's whenever you need
00:31:50.639
more entreprise Ruby so Enterprise Ruby sounds really bad for a lot of people um
00:31:57.240
but if you come from java and if you need some of the things you have in Java and if you actually build a big thing
00:32:03.039
that needs more than what rubby can provide Scala is a good alternative I'm
00:32:08.240
not saying you should pick Scala instead of Ruby what I'm saying is in some cases it might make a lot of sense there's
00:32:14.440
also a lot of it that you might enjoy in the language and um the academic approach of the design is actually also
00:32:21.320
interesting so to take an example I'll talk about how Twitter use finagle so
00:32:27.200
fingle is a library that Twitter wrote to handle the service oriented approach and this is how they do it and I don't
00:32:33.679
work at Twitter so uh I might be wrong and they explain it to me hopefully I I I learn properly but you send an HTTP
00:32:40.720
request goes through an HTTP proxy which is written in Scala using finle which is the library and that's being passed into
00:32:47.960
the apit twitter.com endpoint via HTP and here let's say you ask for all my
00:32:53.919
tweets they're going to split the request and they're going to send some of the request to the user service so
00:32:59.200
they can get some information about you and they will send another Thrift request to the timeline service to get
00:33:05.159
other information and then from there they're going to make some other request to other backends and then everything will come back and get grouped together
00:33:13.080
and come back as a as a response for the user so they build a system using
00:33:18.200
Futures and pipelines so what's a future what's a pipeline well the future is basically saying I will return something
00:33:25.799
in the future but not right now so just wait for it it's like a it's same concept of a promise basically you say
00:33:33.159
I'm sending something you'll get it but not right now just wait for it and the pipeline is basically saying you get a
00:33:39.360
bunch of you send a bunch of requests at the same time you get them back and then you you you create one response you send
00:33:45.440
back somewhere so the way they implement it in in Scala to show bit of Scala code is like that say this is my
00:33:52.480
authenticated user it would return a future of a user and to do that we call
00:33:57.679
user. authenticate we pass the email and the password so that looks like normal Rubik code but what will happen is that
00:34:05.480
in this specific case it won't return right away it would return a future object but the value of user is not yet
00:34:12.000
available and then to look up the tweets we'll get a future of a sequence of tweets so you can think of it as as an
00:34:18.280
array of tweets and for that we call authenticated user which is the object we created before we do a flat map which
00:34:25.720
is like Ruby um and then we have a Lambda we have a block so it's basically like a map in
00:34:31.760
Ruby but instead of having um the two pipes to Define user here you say user
00:34:37.720
and then you have the fat arrow and we're passing the the value that will be returned by here inside this call so say
00:34:44.839
whenever you get the authenticated user send it to tweet find by old user passing this user and it will come back
00:34:51.679
a better way or more tic way of writing this code in Scala is to use the four yeld bu operator and here we say um get
00:35:01.119
this whenever you get that get that um user put it into this user object or
00:35:08.240
variable and then call this tweet find by all user and pass the tweets the response of that in this object and then
00:35:14.640
we're going to yield that so that's how you do async code uh with Scala in the
00:35:20.880
Twitter Library so you end up with Asing blocking or not depending on what you want Futures you get the full um the the
00:35:28.880
functional programming aspect and the object objectoriented aspect at the same
00:35:34.640
time um this is just implementation of a server I'm running out of time so I won't go through it but um we basically
00:35:41.000
Define a service we Define an address and then we build a server by passing uh
00:35:46.680
the name the codec we want so it's going to be HTTP instead of thrift then we bind into the address and then we link
00:35:52.240
it or we build it using the service so the request will be sent to the service
00:35:58.000
there uh coming from Ruby you will see that scal has a lot of
00:36:03.599
things we already know you have the concept of enable which is functional programming basically so you have all the maps the
00:36:10.079
inject uh the partition the zip all these things you have Anonymous methods or Anonymous functions you have default
00:36:16.760
params you can do meta programming you can even do method missing which you probably should not do in Scala but you
00:36:22.599
can do it duct typing um you can use mixins they have actually a concept of
00:36:28.040
traits which is slightly different than mixings but it's more less the same and turns out because a lot of Ruby people
00:36:33.880
end up ended up doing Scala and because the Scala Community just liked it I guess they picked up a lot on testing so
00:36:40.839
you do you have good um testing Library like rpec that's being ported to Scala
00:36:46.079
and um you also have a built-in testing framework that's pretty good what you do get that you don't have and sorry I
00:36:52.599
should not have put the first one on the list but you have inner methods so it's kind of funny when you learn scal
00:36:57.680
because you will Define a first method you say def F and inside that you can Define def bar and call it from inside
00:37:05.560
but it's basically scoped inside this method so you end up writing code that lives in the scope of the method that's
00:37:11.800
actually quite elegant when you get used to it you also have lazy eval and streams which is the equivalent of Ruby
00:37:18.560
to Doo um lazy enumerables so you can create infinite Loops or infinite
00:37:23.680
streams or or collections and you just keep on going through them until you
00:37:28.880
find what you need and um the evaluation is done um if you remember what Jim was
00:37:34.480
saying this morning in Ruby um we evaluate the arguments right away in Scala you can
00:37:41.400
choose to evaluate them right away when you pass them or later on and that's how they implemented lazy Eva as the as part
00:37:47.839
of the language you have a great garbage collector uh which is the jvm1 performance Scala is way faster than
00:37:56.319
than Ruby um looking at very small benchmarks on small code I was porting it was between two to 10 50 types
00:38:03.400
depending on the code you write and what you do um so you get a really good performance Improvement and you stay
00:38:09.680
more or less with the same Ruby philosophy um it's also faster at least from what I saw in the benchmarks I saw
00:38:15.960
than closure just so you know if you do functional programming I found Scala faster than closure which surprised me
00:38:21.599
but at the same time one is compil one is typed the other one is not so that's maybe why and finally the thing that was
00:38:28.000
surprising was the fact that I actually really enjoyed using an IDE um I use intell AJ because that's that's what uh
00:38:34.720
Marcel told me to use and I just listened to him and turns out um being able to be inside a function and click
00:38:40.760
on on a variable and get the entire definition of the variable what you can do with it is is nice being able to get
00:38:48.160
the errors being CAU before you run you run them in runtime is also quite nice because that happens in Ruby quite often
00:38:54.800
you call a method that doesn't exist on an object and you catch it pretty quickly with test but having the tools around the
00:39:01.720
language is actually quite nice the philosophy of um Scala is
00:39:08.319
basically Ruby minus scripting plus static typing that's kind of how I see it it's probably not the way a scy
00:39:13.880
person will present it to you but that's the way I see it and it's really for me the academic version of Ruby I find that
00:39:20.160
that Scala um being written by a professor at the University of of loan in Switzerland has been thinking a lot
00:39:26.839
about what he wanted to do he wrote the first one of the f one of the first compiler for Java the one that's still being used and he applied a lot of this
00:39:33.599
knowledge into the language design and you don't get the freedom you get with
00:39:38.720
Ruby but you get a more academic version of it so what I didn't like with the language is that first it has a huge
00:39:45.240
surface learning all the types the collections The Operators all this thing actually takes some time um they're not
00:39:51.680
really hard and if you have Java knowledge it's much fast it's much easier but it's actually huge the
00:39:57.000
learning curve can be a bit impressive at first um you get started you're excited and then you want to do
00:40:02.040
something a bit more complex and you realize wait I don't know what to do here the syntax is often abused or it
00:40:08.359
feels abused you have um the colon colon with Plus at the beginning Plus on the other side will do different things you
00:40:14.520
have all these different things that are a bit hard to to learn the documentation not that great um it's funny but it's
00:40:21.880
just coming from something academic you would expect to have good documentation and I found the do to not be that great
00:40:28.599
um now coming from Ruby we're used to that or we were used to that so it's not a big problem I felt that Scala tried to do
00:40:35.720
everything and nothing at the same time the fact that you mix object-oriented and functional programming I found
00:40:41.480
myself with the same issues I had with Ruby at the beginning which is I have 15 ways of doing this thing which one is
00:40:47.480
the right way and if you do python you know in Python you only have one way of doing one thing but Matt was really nice
00:40:54.240
and said you know what in my language I don't want to for force you to do anything and you're you're free to do it
00:40:59.440
because I don't know exactly how you're going to use it which gave us this powerful language but when you learn it
00:41:05.280
and and that's my case with skella it's always a bit hard to know when do I do this or how what's the right way of
00:41:10.880
doing it and is there a right way I'm not sure about that and um finally the
00:41:16.400
jvm is something that I I like it and it's in my next slide but at the same time I don't like it I wish I had
00:41:22.640
something smaller that was that I could just ship with my application I would be just lighter and not this crazy big
00:41:29.440
thing I don't fully understand so what do I like about Scala well first I feel really close to Ruby or python I feel
00:41:35.920
like when I write Scala I'm not lost it's not a different world it's not like when I write closure where different me
00:41:41.359
mental shift um it does a lot of what closure offers because you can do
00:41:46.440
functional programming the same way you do it in closure you can do it in in scal so I find that for things where I'm
00:41:52.079
not really sure if I want to do fully um functional programming or not I would have a tend to go to Scala because I'm
00:41:57.480
more comfortable with Scala than I with closure because it's more familiar it's easy to get started because again it's
00:42:03.680
close to what we know infot types are great because when you start writing your code you don't feel like the type
00:42:09.640
are just getting in your way or they don't get in your way as much as if you write another language that's stat
00:42:14.680
that's strongly typed or statically typed U the functional approach is flexible you really have a focus on
00:42:22.040
parallelism and concurrency which you might not have in other languages p matching is something I don't have time
00:42:27.559
to talk about but if you come from erlang you know what it is um it's something you have in scy that I find
00:42:32.760
very interesting uh the ecosystem of sky is quite rich I found a lot of libraries
00:42:38.200
probably because you have people like LinkedIn and SK and Twitter and other people using it the community is Rich
00:42:45.480
and you can use the jvm and the CLR which I didn't realize until I studied the language you can actually run Scala
00:42:51.720
on.net which I would not do it but you can which is cool
00:42:56.760
so how do you learn it well um you have the tw Twitter Scala school so Twitter
00:43:02.160
wrote they have this this all curriculum to learn Scala when you join Twitter and they actually publish that and you can
00:43:08.400
actually do that and you can follow that there's a tour of Scala which you can Google and you find it that works you
00:43:13.520
through learning the language and you have the corsera online class uh which is which I just finished and it's really
00:43:20.200
amazing it was seven weeks of classes that were taught by Martin ersi the language designer and implementer of SC
00:43:26.839
and um it was a lot of fun really good exercises you can probably it will probably start again and you get the the online classes available probably online
00:43:35.240
so I'm running a bit of time sorry about that how did all this learning affect the way I write Ruby because at the end
00:43:41.040
of the day I still write Ruby more than I write other languages so somebody asked me this question and I was thinking about it and I was like you
00:43:46.880
know I'm not sure um and I had a discussion with Brian help Camp because he was writing some of the code and he
00:43:52.559
was doing in objectoriented way and I said you know what we should do that in functional we should actually use functional programming in this case and
00:43:58.880
we had this discussion about why and how the first realization I had um and
00:44:05.000
Jim really showed that this morning during his keynote is that Ruby is as functional as it is objectoriented now
00:44:11.440
it's not purely functional so maybe what I just said is wrong um it's it is a
00:44:17.359
it's a it's a functional program a functional programming language you do not have to have immutable types to be a
00:44:24.040
functional programming language and um often when we think about Ruby we only think about the O aspect of it we do use
00:44:31.480
blocks we do use lambdas we use um we use functional programming but we kind of don't want to call it like that we
00:44:37.720
want to do everything objectoriented and I realized well this is too bad because we have these two Paradigm and we should
00:44:44.079
really embrace them because the language designer behind that wanted us to use these two things because there's value
00:44:50.319
in both and they are both complimentary we can find we just need to find the right place to use use the right
00:44:57.839
Paradigm so when do you do that and I don't have a really good answer I can just tell you what I came up with which
00:45:04.359
is based on the feedback I had from the Scala community and um articles I read
00:45:10.760
from different people and basically the concept in Sky list is functional
00:45:15.839
programming should be used when you extend your program with new operations
00:45:20.880
when you extend your program with new data you use objectoriented programming instead so said differently if your data
00:45:28.839
doesn't change you can use functional programming if your data change and evolves then you probably should use
00:45:34.839
objectoriented programming if you want more um information about that what I came up
00:45:40.920
with come and find me at the end send me a tweet we can we can discuss about it um I'm not quite sure I can actually
00:45:47.119
write a blog post to explain with specific use cases um but I find that the Scala Community was a good Community
00:45:53.520
to to discuss these issues and I think that as part of the Ruby Community we should do the same thing because we have
00:45:58.680
the same tools also something we probably all know um it's not because you can do
00:46:05.160
something that you should do it uh it seems logical but when you look at a lot of Rubik card we write we have a
00:46:11.680
tendency to do a lot of crazy things just because we can and um I would like to thank Matt for giving us all this
00:46:18.440
flexibility to do all this crazy thing because it's a lot of fun and we can explore it but at the same time remember
00:46:25.240
there's an implementation you need to run language on top of an implementation and if you care about performance if you
00:46:31.480
care about having other people maintain your code you need to think about the way you organize your code which is not specific to Ruby but think about side
00:46:39.319
effects thinking about meta programming complex code um wanted to do
00:46:45.000
objectoriented everywhere there's a cost to that so you need to think about it because it's not because Matt allows you
00:46:50.960
to do it that you should do it Matt is a very good guy a very nice guy he wants you to do everything you you want
00:46:56.160
doesn't mean you should typing I realized I actually like typing um I I remember a few years ago I
00:47:03.559
was saying I would really like to have optional typing in Ruby I would like to have this option because in some cases
00:47:09.880
if you have a fun a method and this method takes an argument called name it seems logical to you that it might be a
00:47:15.400
string but it might be actually an object that represent a string that's something else and being able to Define
00:47:21.160
an API and be able to have this API contract saying my API takes this arguments and they have this type or
00:47:27.920
they will respond to this methods the same way go does it um and I would
00:47:33.920
actually output this type of information is very useful in specific cases especially when you write libraries if
00:47:40.839
you write web apis it's actually also a very good thing to have now that's different topic but typing is actually
00:47:47.760
not that bad and he evolved a lot and now with infr typing with hint typing or structural typing you get a lot of value
00:47:55.559
um that you don't have when you just have purely Dynamic typing also realize that testing is not
00:48:02.359
documentation so a lot of people talked about that I won't spend too much time on it um but when you don't know a
00:48:07.480
language going in the test and try to understand what's going on is a nightmare um when you go and you look at
00:48:12.920
the source code of a language and you see exactly what the input is expected what the output is actually it helps a
00:48:20.640
lot so you should keep on testing and you should write test but don't forget to also document the way way your
00:48:26.599
software your program behaves and what is being expected I'm not explaining I'm not asking you to document every single
00:48:32.040
line or the inside of the method but explain the outside of it error handling
00:48:38.480
I talked about that when we we looked at go I have a tendency now to return this tble an array of two objects one is the
00:48:46.040
object that comes back from my method and the other one is a potential error that that can be raised that can come
00:48:52.559
from the object so you can actually create an exception object and not raise it you can just send it and let other
00:48:58.680
people above it handle it so usually I have a tendenc to do that in my libraries the way I do it so I will make
00:49:04.680
a request if something goes bad I will return it as an object and I will decide if I want to raise an exception or not
00:49:10.920
or if I want to just pass this information back to the people who will use this library and they can decide what they want to do I'm not fully sure
00:49:18.040
it's a good idea I just feel like using exception for control flow is not the best idea ever all the time it's
00:49:24.720
actually probably a bad idea but there's some cases where it makes sense so let's move on compilers actually I
00:49:31.760
realized compilers are much fun F much more fun than they used to be um they
00:49:36.839
don't get any way as much as they used to or at least maybe I just got better um and I also realized
00:49:43.440
that if my code can be optimized for the compiler so if my compiler can
00:49:49.280
understand the where I write my code and can process that it also means that my brain will also should be able to handle
00:49:55.359
it better so I I started changing a little bit the way I write code and I
00:50:00.640
started keeping my structure simple so if you have an array in Ruby you can put any types in the array you can actually
00:50:06.920
start passing different type of objects um and if you have a compiler usually
00:50:12.480
compilers don't like that or you need to to put a special thing in your object when you send that and I realized well I
00:50:17.880
could actually write Ruby the same way I would write Scala for instance and just
00:50:23.079
choose one type and stick to it in most cases and it would actually keep my code much
00:50:28.839
simpler I don't have to check on the type of the object that's being passed I don't have to do all these things I end
00:50:34.160
up with simpler code that um actually ends up running also faster and this is
00:50:40.799
when I realized that once again Simplicity matters and Ruby gives us a lot of flexibility a lot of options to
00:50:46.280
do really complex code but we also have the functional programming aspect of Ruby which forces you to keep it simple
00:50:52.839
because you cannot build something very complex with while you could but it looks ugly really quickly and everybody
00:50:58.119
will yell at you if you do that in functional programming language but if you have 10 layers of abstraction no op
00:51:04.160
people won't really complain about it if you look at a lot of rubby code we have this very complex code with 10 different
00:51:09.440
abstraction layers and people think hey well that's good look my method is only five lines or three lines of code but
00:51:16.000
actually it's not that simple because when you look at the object graph and how you call this methods it's very
00:51:22.599
complicated so functional programming is one way of helping that and and what I'm trying to do now is when I can I keep my
00:51:30.480
code simpler by sometimes switching to functional programming for a very specific use
00:51:36.000
case so at the end of this journey I I found myself pleased because I came to
00:51:42.799
what I find are some of the limits of Ruby which is good because in everything you have limits and if you understand
00:51:49.240
this limits that means I can pick what's best when is the best time to do that
00:51:55.000
and I came up with three points for what I think the limits of Ruby are performance concurrency and
00:52:02.520
freedom so performance is an issue we know and it's actually a hard problem because it's very much like concurrency
00:52:09.760
is based on the language design you cannot everything is a compromise and you cannot have something very flexible
00:52:17.839
and also very performant or you can but it's really really hard and it will take a long time um so you need to choose now
00:52:25.000
perect perance is a word that means everything and nothing I I realize that um people think well that means Ruby is
00:52:30.440
slow well Ruby is slower than Scala than go and closure but you know what it's
00:52:36.680
most of the time it's fast enough and I write web services and I did that for sunny PlayStation and I do that now for
00:52:42.839
Living Social and we get a response time between 5 to 15 milliseconds writing
00:52:47.880
rubby code this is fast enough I cannot justify even though I would love to just play with these other languages and
00:52:53.799
write some of my services with that I would not get a much much better performance gain by using other languages now concurrency is where it
00:53:01.160
gets a bit more tricky and a lot of people talked about that I won't go too deep into it but there's a bit of a
00:53:07.960
problem with Ruby at this at this level you can get concurrency different ways it doesn't mean you can't I'm just
00:53:13.839
saying that languages that came after Ruby like the three we just studied they
00:53:18.880
have they when they were designed they thought about concurrency I'm sure when Matt started designing Ruby in '93 or
00:53:25.720
when he released it in 1983 he was not thinking well concerence is a big deal and that's going to be the future of
00:53:31.760
programming he had threads and he has we have a lot of cool things in Ruby that allow us to get concurrency we can use
00:53:38.000
multiple interpreters we can do a lot of things but the the language was not designed the same way newer languages
00:53:44.200
are designed and the last one is freedom freedom is what I get when I write Ruby
00:53:51.240
freedom is me is basically ma letting me make any mist I want and not getting in
00:53:56.680
my way it lets me explore what I want to do the way I want but there's a CA to
00:54:01.760
this freedom and I need to be willing to pay it in most cases I'm willing to pay it in some other cases I can't afford
00:54:09.240
this freedom and I will choose to restrict this Freedom by choosing another language that makes compromises
00:54:15.520
that are different so at the end of the day looking at all these things I realize I'm not a ruby developer anymore
00:54:23.599
actually I'm not even a Dev veler I'm a Problem Solver but actually that's what
00:54:29.400
people like to say and I thought about it and it actually sounds bad I can I can imagine this guy you know on this
00:54:34.920
small desk in his wide room with a small window just solving problems and people just bring little problems to him and
00:54:40.599
just like type yeah I fixed this problem and you know if that's my life that's a bit sad because I don't want to be just
00:54:47.440
solving problems all day long what I want is to build products I want to build something um and I'm not talking
00:54:53.839
about the startup concept of I want to have this app and I can make millions of it I just want to build something
00:54:59.960
something that that would change the world around me or just a few people something that will make my life easier
00:55:05.720
or somebody else's life easier so you know what the language you use is just a
00:55:11.440
detail you can use Ruby you can use Scala you can use PHP whatever language you use you can build a great product
00:55:19.319
the only difference is that if you don't Choose Wisely the language the way you will solve this
00:55:24.760
problem will be affected because languages as we saw at the beginning shape the way you
00:55:30.559
solve problems and solving problems is the way you build products so choosing a
00:55:36.119
language can affect the end result of your product so you need to be curious
00:55:41.440
and you need to learn new languages and the reason why you want to do that is because you want to think about how to
00:55:47.680
build products differently you want to solve problems different ways so you can end up with other results and there's
00:55:54.599
nothing wrong with looking at other languages and going back to the one you like and say you know what I still right Ruby there's nothing wrong with Ruby or
00:56:01.680
in this specific case I'm going to take another language because it solves this problem differently and it makes sense
00:56:07.880
what's very valuable is when you learn other things and you go back to write the way you write Ruby and now you write
00:56:13.599
Ruby code in a way that's even more efficient or that seems to fit better your brain it's just a really good
00:56:19.480
feeling so go and build a some stuff with whatever language you want design
00:56:25.079
own language have fun with it understand the concept behind it and just enjoy