Player is loading...

Embed

Copy embed code

Transcriptions

Note: this content has been automatically generated.
00:00:00
alright so um had this afternoon to talk to you about this fact is it's gotta
00:00:05
and just to give you a bit of background on me so that you understand why
00:00:08
i actually can't talk about these things and is it your company called this it though
00:00:13
we recently murdered free completely different scenes one doing node
00:00:17
wondering to um java and wondering scholar and we're trying to
00:00:21
come together with the same processes and technologies it's working out about as bad as you'd expect
00:00:28
but we have finally agreed that's kind that was probably the language we all wanted to use
00:00:33
and this is getting a pretty interesting perspective because i'm getting to see talented developers that
00:00:38
nothing about scallop or function programming struggle with
00:00:41
learning the language and i'm rediscovering all the things
00:00:45
is that really trouble me as i was running the language so i'm saying lots of problems
00:00:50
that keep coming up and i'm writing down these problems and solutions to them and this presentation
00:00:56
is um the best ones the most common once the most interesting ones
00:01:01
or is it completely in knots one but i want to chat was it
00:01:05
so the way it's going get well okay is i'm going to show you some code
00:01:10
you are going to have to work out what i think is wrong with the code
00:01:16
explain it to me if we can refer don't have the time or just give the solution i'm going to tell
00:01:20
you what's wrong with it how to work around it and
00:01:23
uh in the remote next one so um let's get started
00:01:31
it's a very first bit of code that i want to show you is this so how how this work again right so what
00:01:38
why do you guys feel that i don't like this code i'm just comparing to raise is gonna be the hand um
00:01:46
often the to all the slides and is a good idea about what
00:01:50
the answer is going to be so yeah it quite obviously the problem is
00:01:54
with a re compare reason can anyone tell me why this is probably not great
00:02:02
okay
00:02:03
okay uh the main problem that is that it doesn't actually work
00:02:08
the rent is sent only collection invent highest colour
00:02:12
collection library start doesn't have a working equals method
00:02:15
so comparing always like that is going to not work ever and
00:02:21
we know that's when it's kind of approach we have had problem before
00:02:24
so we don't use a razor when we do we don't contend that way
00:02:28
well to begin is to people who come from a java background or javascript background or any other background
00:02:34
this doesn't make any sort of sense this is completely nuts um the reason doesn't work you have to do with the
00:02:39
way to go to the j. v. m. arrayed have reference
00:02:42
equality not value quality it's not something interesting just doesn't work
00:02:47
so instead of using equals fall arrays use same elements and again you have to
00:02:54
know that and it's going to but you sometime if you don't know it so
00:02:58
actually to yeah and if you didn't know about that great adjusted you i was of painting production
00:03:05
right so that was my first problem with every compare
00:03:10
regions and given the fact that this is kind of tennis
00:03:14
and also going to try and for anything one of this problem explained how
00:03:18
seine are fixed or improved or not at all in later version of colour
00:03:24
and so since four races can actually that's thirteen has immutable raise which behave
00:03:30
saintly with because we call them not some stuff so if using it will raise perfectly fine
00:03:35
you too will raise even dotty thought i can tell a completely nuts and and try to stay away from them if you can
00:03:45
right so this bit of code which looks perfectly fine dining many have any clue what i don't like it
00:03:53
okay
00:03:56
right so this is not the first and somebody giving the answer probably should changes like this
00:04:00
is completely correct but not the point to the slide um and again there's often a hint
00:04:07
um the front hey it's start i haven't type annotated my method so you could return anytime
00:04:13
in the components construct infrared and the best time again for the best type you can infer here
00:04:19
what you'd expect it to be option ave especially given the fact that i haven't a my method as option
00:04:25
it's actually going to be some which is not a massive they'll most of
00:04:31
the time if you have a summit to subtype of options so it's alright well
00:04:35
it could be a problem say if this is a library and i were to probably
00:04:38
starts then the type of the method actually changed and you break binary compatibility just like that
00:04:44
so when you have public methods public members
00:04:49
type annotate them because otherwise you will eventually break something and the types are inferred
00:04:55
are not actually the type you think or inferred watches not was not all the time
00:05:00
so just fix it that way put an extra seat type annotation and then everything works out just fine
00:05:07
this is kind of improved is kind of really 'cause implicit members have to have a type annotation
00:05:13
but at the same time into this it's are being deprecated things kind of result does actually change all that much
00:05:18
so this is still pretty much of a problem in to that city names got free as far as i know
00:05:24
and due to type annotation on any of your public members
00:05:33
you get operators
00:05:36
this is problematic cable ten why so first what is good supposed to do um this syntax here
00:05:44
is expected to read created topple who's left member is one and who's right members for divided by to
00:05:51
and this is while what happen if you read that using the ascii operators
00:05:57
and the documentation tells you that you ask operators and there you could equivalents
00:06:01
are exactly the same pair as they are in fact not the same says does not come how well if
00:06:08
you want to use the ascii operator it complies just fine so it was a problem here is very subtle
00:06:14
the problem has to do with operator priority is kinda where the rules the rules are the
00:06:20
way than hardcoded but if you operator starts with an eye for an eye with a minus
00:06:25
so and it's going to have um lower priorities and say divide
00:06:30
but this correctly here does not start with a minus
00:06:34
so is not actually the same operator as you ask hero
00:06:38
contrary to what the condition expressly states so this is very confusing and it
00:06:43
is but uh most of the time to use yes q. operator instead even though
00:06:48
it looks much nicer within a good characters um
00:06:53
there are ways to still have a nice display you can use fonts with
00:06:56
teachers you can use some advanced features such as he might have pretty printing
00:07:01
uh but it's not going to give him a problem much longer anyway because it's deprecated into that thirteen so
00:07:07
if you guys like me had rules to turn all you ask your bridges into you could
00:07:11
you could you like that you're going to have to revert that 'cause it's not going to find
00:07:16
uh_huh
00:07:20
any variations what is wrong with the way this is implemented first does anyone and not know what enumeration is
00:07:29
okay we're going to soothe everybody does does anybody then
00:07:33
it no ah everybody's and know why this is problematic
00:07:43
i couldn't quite has that sorry
00:07:47
that is a very good answer where to start um there's a
00:07:51
lot of problems that uh it mostly the whole thing is problematic
00:07:55
but the one thing i'm going to focus on 'cause i think it's pretty important is that
00:08:00
once you have written your admission like that where you
00:08:03
have declared integration of text acres with members okay not okay
00:08:08
pam this code is going to compile without any sort of warning
00:08:12
you can have a match on the value of type state stages the value and have a non exhaustive
00:08:18
that match is going to compile anything to fit at run time and we don't like it when things
00:08:23
for one side especially since the sky uh we tend to assume that
00:08:27
pattern match is smart and is going to want you whenever it's not exhaustive
00:08:32
this compound without a single wanting it crashes at run time it's everything that's wrong which was
00:08:38
a lot of years that we have is gonna so don't do that don't use enumeration um
00:08:44
used use cell trait hired is that uh uh well uh the way this works yeah it is
00:08:51
i have the greatest feel trait sealed means set set cannot be any subtype
00:08:56
of steak is declared outside of the file in which stages with like that
00:09:02
so the compiler knows that having a cat okay as a type of teachers not okay as the type of status
00:09:08
and those are the only sub types of data is in
00:09:11
this file that cannot possibly be any other subtype of status
00:09:16
so the component of now that this is not legal
00:09:21
then is going to warn you that you shouldn't be doing that anything interview
00:09:26
that is going to fail on that ideas we can give you quite a
00:09:30
good error message just because you stopped using enumeration so don't use animations ever
00:09:35
yeah just one thing this is actually a warning not a continuation failure
00:09:40
um up something that's pretty important if you want to write corrects gonna turn on fiddle warnings ah have
00:09:47
had a lot of but found that when i've never had a
00:09:50
false positive discusses very small that way warnings fixed and it's so important
00:09:58
um it's kind of free might eventually duplicate enumeration in favour of the in um q. it
00:10:04
uh have seen discussions on that matter last time i checked u. was
00:10:07
not the property gets that was not the proper poll request on that
00:10:11
uh but given the have check this weekend lots of things have been happening this week it might
00:10:15
actually be going on now i don't know but this is something that might actually disappeared from the language
00:10:22
uh_huh still trade so right i just told you so traits were nice and now
00:10:28
this is very similar to what i should do before but i
00:10:31
believe something is wrong with that code does anybody have and anyway
00:10:40
yes you in the back
00:10:44
i picked leather well thank you so i'm
00:10:50
at bar is not final and soprano yeah it's
00:10:55
when you see a seal traits and adjusted his definition sailed means you can't have a
00:11:00
subtype you can have a direct subtype outside of the filing with the type of the good
00:11:05
but direct is very important here most people don't really realise that but
00:11:11
but are is the director type of fruit and you can only have bar as
00:11:17
it directs the type of fruit anywhere in the rest of the code by itself so
00:11:21
yes the final so you can go to other file inductor a sector it you indicated some type of bile and
00:11:28
full by here is not a direct the type of food because as a level of indirection this bar in the middle
00:11:33
so this is correct this is perfect embedded this is exactly how feel that is supposed to behave
00:11:38
it's also for people who have just learned about sales not all that expect any kinda very surprising
00:11:45
so it's not should still and sometime it's what you might want to do but you have to
00:11:49
know that it behaves that way and unless you have a good reason for sub types of still trait
00:11:54
to be final to make them final or save themself a 'cause it's it's good default it's
00:11:59
not much which will what's a good default unless you have reasons to not follow that rule
00:12:06
uh right so solution is to prefer final still descendants and s. five
00:12:10
and can tell nothing's changing deserted that's it you know all dirty about that
00:12:16
um right
00:12:20
how to break that attack so i showed is that
00:12:22
just before uh it's basically the same code and now i'm
00:12:30
something's wrong with that something's where it was that yes you in the back
00:12:42
right so this is a very good answer but to the wrong slide i'm gonna very soon so can the answer and and and then and
00:12:50
say i think it's to slide down the road uh i'm not contributed because i don't want everybody to know the answers to the next trick
00:12:57
ah but no the problem here is start um this kinda compiler can sometime in for some
00:13:03
pretty wanted types so yeah if you create a list of digits okay instead just not okay
00:13:09
you'd expect the type to be list of status and instead you get this abomination
00:13:15
which doesn't we change all that much but again this is from the perspective of somebody learning the
00:13:21
language somebody who's new to the language in trying to work out how how how the body thing but
00:13:26
and when i see that the call help but think this is magic magic
00:13:30
objects and it's not what you'd expect and you don't understand what you have that
00:13:33
and the reason for that is perfectly correct coherent it's even possible for some people
00:13:38
to explain it i'm going to attempt at the actual wedding to get that but um
00:13:42
the reason this happens is that because here it's car is going to try and finds
00:13:48
the closest possible subtype uh is coco super type that is common to both okay not okay
00:13:54
one of these types the states because okay or not okay extend status but that's
00:13:59
not all 'cause by virtue of being cans objects okay not okay also extend implicitly
00:14:06
say reasonable and product which you don't need to know it's absolutely not interesting it was implementation detail
00:14:12
well it means that is the least this stuff about so the closest to the type that is
00:14:18
common to both of them is product with a reasonable we stages it's an implementation details that looks out
00:14:24
to the user doesn't wanna hear about that and who gets re compute
00:14:29
and when you have to explain that's what i just said to people who are learning schuyler
00:14:34
you lose about fifty percent of the yeah okay skies a bit magic at that time on that maybe we could make a backchannel script
00:14:40
so that doesn't really work and the way to trick the compiler into doing what you expect
00:14:46
is to have your entity extent product was veritable because of that and magically
00:14:53
okay do extend status and product it's a reasonable not okay as well but
00:14:58
both of the uh but stages is also a product that is readable and so
00:15:04
the list of abound is going to be status so this works this we had expected
00:15:10
sky freely enough improve on that um
00:15:14
i'm trying to hide it so i'm saying i'm keywords
00:15:19
whereby defaults not returned the type that you expect a return to super tight but it still
00:15:25
can happen if you use that if you use for constructors directly but i didn't have a lot
00:15:30
more interesting if you want to read about that uh this is clickable once i link to
00:15:35
slide at the end of the talk you can go and have a look at how this works
00:15:38
but um so dotty makes is that uh but it's not fixed is just kind of hidden under the rug
00:15:46
um there was that that was the answer so what's the problem is that case last
00:15:53
and uh as the answer was discussed as is non final and if it's
00:15:58
not final then get really weird behaviours that was in a sense you answer right
00:16:03
so an example of that behaviour is through being on final i'm not extended
00:16:10
here after class ball with two members i. n. s. which are in some
00:16:15
strings and i maps to choose i that's our problem and then we have
00:16:20
the additional string member and this means that this cold here is going to compile
00:16:25
and it's going to return true which is not what anybody said would expect
00:16:31
and i've actually taken the most obviously that's easiest example to
00:16:37
understand 'cause what happens if you put these two whoops sorry
00:16:42
and back there if you put these two in a hash map is that one of them is going to ride the
00:16:49
other and you're never going to figure out what and when that happens in production and you don't know why using elements um
00:16:57
it's happened to me i hope it doesn't happen to you it's a problem that now um
00:17:01
so the reason for that because i i promise that yeah that explain why this happens um
00:17:07
if some of you guys have some data experience what happens here is that through
00:17:13
uh being a case last gets a lot of synthetic code lots of methods generated for it such as
00:17:19
it falls to string hash code all these kind of things and so few
00:17:24
having equals method is that these implemented in a way that makes sense through basically wraps and and so if we
00:17:30
have to choose to have two things to have the same value them both of them are equal and that makes sense
00:17:34
but when you extend when you subtype ah through them bar inherits from the saint equals method
00:17:43
and so when you call that the method is going to be called is the method sars is a bit fiddly
00:17:51
the myth is equal method defining who which doesn't even know what s.
00:17:55
m. s. filled uh is it the string so this is absolutely normal
00:17:59
this is exactly what's expected when you know what's going on it's also
00:18:02
super confusing and and really does make the language for like magic so um
00:18:08
prefer making final case classes um uh the reason why this is not the default
00:18:14
the pen is is one person in the whole entire words that does because they're not for the case classes and has a use case from it
00:18:21
up that person inherently martin or the ski so when that happens you don't get to change it
00:18:26
uh i wish i wish to to change but unfortunately
00:18:30
that's nothing standing in these are two thirteen or dotty so
00:18:34
when you take a case last make it final please that's going to save all operating and
00:18:40
um custom instructors right does everybody know what a custom instructors
00:18:47
i'll take that as a yes um so what's going on here yeah is
00:18:53
and declaring an object extract some within and apply method for any psalm
00:18:59
is going to return and the value of type option of a and this allows me to use extract some of the pattern match and
00:19:06
this is really very long and does anybody know why when i found out
00:19:11
i i got kind of angry about that and i know what's wrong with that
00:19:18
nope okay have fun working it out so what happened say
00:19:23
when it is that this code here is going to compile
00:19:28
no problem even though it's quite clear that given the fact that my and apply method only texas some
00:19:36
it's not defined for non uh it's quite clear that hey if my though isn't on which can be
00:19:44
jesus i this is going to crash at run time because of how much does
00:19:50
not exhaustive but the compiler doesn't know that somehow and this will for run time
00:19:57
it's perfectly valid code by the compiler cannot work out that they have a problem so
00:20:04
so the reason for that was explained to me um it basically boils down to to really work that thing
00:20:11
uh i'm not construct explain it's a pattern matching exhaustively
00:20:14
checking is quite one key themes got to look twelve
00:20:18
uh and in order to avoid this kind of problem that solution would be
00:20:22
to never define custom x. factors if you can do that but if you can't
00:20:26
try to make the republic structures return some as an option because
00:20:31
that actually fixes the issue and you do get expected wanting here
00:20:36
it's kind of friendly make this whole thing overall patterns have been
00:20:40
a lot of research done on exhaustively t. checking for pattern matches
00:20:44
and uh so the point is completely gone in dirty and you don't need to worry about it as soon as you move just gonna free
00:20:50
but until then be careful was catholic structures they're weird
00:20:55
um structural types
00:20:59
do i need to give a quick quick information about what the structural type is does would anybody like that
00:21:05
think up of nods okay um structural typing is for those of you
00:21:10
who have used it languages this is doc typing popping a statically typed language
00:21:15
this allows me to say that my at one method here with accept any type
00:21:21
provided that type defines a i'm deaf uh get methods that resentment
00:21:27
and then i can just call that method 'cause you everything i know about that x. value is that
00:21:31
it's got a cat method so i get that in every time and at one that's what every time
00:21:36
um and then quite conveniently i can defend defined this case last notice how it's final important
00:21:43
um that rotten and and if i get my thought on that and i'm completely allowed
00:21:47
to pass wrapper to my i've been method even though i have not define any hard
00:21:53
some typing relationship so structural typing either way to do some typing without having to declare it beforehand
00:22:00
yeah it's quite convenient it's it's a great tool buttons colour he
00:22:03
suffers from a few falls does anybody know what the slows or
00:22:09
yes right okay so um the frenchman said reflection which basically covers my two point
00:22:17
um this is implemented in santa as reflections so the compiler knows this works
00:22:24
because it knows everything that isn't rubber it knows that rubber had a cat so it knows is called fail but at run time
00:22:31
is going to have to use reflection to dig into the values they
00:22:35
received extracts and make um a method object call that manually and this is
00:22:41
much more expensive than not doing anything so it has run time cost it's not nice even time cost and that should not
00:22:47
um discourage you from using structural typing we make sense but
00:22:52
the other problem is that i think some of the v. m.
00:22:56
this might not actually run at all 'cause it's possible and a during the day the m. to disable run time inflection
00:23:02
other configuration option for security managers so the composing to compare that there's no problem that code but
00:23:08
i wanted to find out that caught actually do that i have no way of knowing that in advance
00:23:15
uh was so the preferred approach is type classes and
00:23:22
i'm not having a bit over enthusiastic yeah so i
00:23:26
i don't think i have the time to control the slide if i go through this whole
00:23:28
thing um if anybody wants to know more about the type classes i'm going to find that
00:23:33
after the talk but i want to cover a few more of these before before we stopped
00:23:37
so i'm going to skip this nation if you know the type classes use that insubstantial type
00:23:43
uh and it's kind of freely them as overall z. and higher
00:23:48
federal type um it yeah i uh uh well i don't think it
00:23:53
changes of course the issue because the default implementations still relies
00:23:56
on reflection reflection and i don't see any ways that it
00:23:59
could be anything but reflection from the cases i don't think it's going to be fixed it's improved but not fix it all
00:24:08
exceptions
00:24:09
can you tell me what's wrong with these two bits of code
00:24:17
come again
00:24:20
right uh so pa since might throw number from an exception because most strings are not actually married into goes
00:24:26
and a lemon tarts might fro in the rain later that
00:24:29
exception or some such thing 'cause i might be outside of
00:24:34
he reached down and the problem with exceptions um well not very many
00:24:40
problems with exceptions but the one i've chosen to focus on here are
00:24:44
first thing is okay so this one is now and tiny
00:24:48
harnessed but it works wonders when trying to explain to other people
00:24:51
what happens very often is i'm working with a programmer redoing the code
00:24:54
that the buttons calla and when they getting by the input of one exception
00:24:58
and that point had that maybe you don't want from an exception maybe exceptions should not be used and they look at
00:25:03
me like i'm crazy i've been doing exceptions my whole life in java why should not do that what's wrong with them
00:25:09
and then what i do is ask them okay with the user go to segment in your code
00:25:14
course not nobody uses good to statements are famous papers written just about the fact that you should not be using go to statement
00:25:21
and then you ask that one what's the difference between good to stick with an exception can explain
00:25:25
to me what the critical difference between the two all in most of the time it happens they get
00:25:31
a blank for thirty seconds then so okay and they get rid of exceptionally carry on
00:25:37
so this is not an honest on my part because there's a very
00:25:40
many differences between exceptions and get two statements well there are few critical um
00:25:46
see now it is the first one is the problem with a good to statement is when
00:25:51
your at the label of a good to statement you have no idea where you coming from
00:25:55
you could come from anywhere it was good so you don't know your state and this is something that happens
00:26:00
exception as well you don't know was exceptions from you have like yeah you might have a double status that is
00:26:05
not gonna say could expect so you call no and this is very similar between good to statements exceptions
00:26:12
uh it's kind of in words for exceptions because when you write to go to statement to compare is going to
00:26:19
fail if there's no associated label so you know when you have to go to statement is going to go somewhere
00:26:25
with an exception is basically i'm going to pan out now so many
00:26:28
catch me otherwise crashed don't know don't care your problem and uh well
00:26:33
it unless you don't know that anybody's going to handle it you can't you can't take that so that's the
00:26:39
first reason why i don't like exceptions it's it's essentially good to statement for all the wrong things that now
00:26:45
um it's an checked it's gonna so this is basically just got a few other languages but in
00:26:51
some languages such as java exceptions are part of the type signature of the method that because i'm
00:26:57
so the compiler can tell you well you haven't caught the exception you haven't have that our case applies to
00:27:03
that and and of by the neck and compound but was colour the compiler complaining all exception you have no way
00:27:10
when you call method of for the exception you have no way to know whether you have
00:27:15
actually dealt with all possible error cases in that question one time and you have no way of taking that
00:27:20
and lastly east preferentially pack which is a very barbaric term which i'm going to explain now
00:27:29
so um referential transparent referential transparency um is
00:27:34
the property of code that we really like 'cause
00:27:36
it how obsessed reason reason about code at the local level evenings that uh when you have
00:27:43
an expression uh you can replace it by whatever it evaluates to without
00:27:49
changing the meaning of the code so you can ignore whatever else goes on
00:27:54
around the whole thing and focus on that expression that you all that matters so
00:27:57
expression is said to be refrain should be transparent if you can replay it put
00:28:03
what it's doing avoidable then use the mobile everywhere else in for an exception
00:28:08
if it was refreshing transparent would means that these two implementation would be the same as in in that one
00:28:14
i have a test that doesn't make much sense it's never going to be evaluated
00:28:18
well if falls it's true send and into for an exception of the budget and to
00:28:24
and the other implementation does the referential transparent testing where
00:28:29
it's going to put the result of that expression into horrible and then easy to use them the rest of the code
00:28:34
and obviously is that doesn't actually work out the first one with evaluating terminate
00:28:39
the second one fails so these two expressions are not equivalent and so
00:28:43
throwing exceptions is not refreshing transparent thank you don't want to do
00:28:47
that in your code 'cause it leads to all sorts of headaches
00:28:53
um you should it as much as possible prefer encoding your or types
00:28:58
in science of the return type of of the method to completely um
00:29:04
when frying a element but find exception if you want to convince the absence of you return an option
00:29:10
if you want to have some sort of fancy their code and all things like
00:29:14
that put it in an user so the right side of the users of successful part
00:29:18
the left side of these are these with the c. r. code the error message whatever
00:29:23
um and if you have if you absolutely have to
00:29:27
agree exceptions like you doing some general drop for example
00:29:30
try is going to help you use basically neither that contains an exception on
00:29:35
the left so if you have to be exceptions to try runs an uneasy
00:29:40
uh unfortunately nothing changed in dirty about that
00:29:46
now i'm starting to put together things that we have said before
00:29:50
uh uh this is one almost completely valid way of encoding or
00:29:57
so this is a very simplified entity which we talked about the fall um which
00:30:03
is meant to encode all possible error cases when you try to connect to database
00:30:07
and you know the for the whole thing to fit in one slide of just to get to possible implementation
00:30:12
one which is the sequel you try to run it not voted in the
00:30:15
other one is i try to connect but lost the connection please try again
00:30:20
and something is not ideal that implementation but it you know it doesn't have all the thing i've said so far
00:30:26
it is still trade extend product is a reasonable case objects everywhere it's it's it follows all the rules of
00:30:32
given so far but it's still not quite right or does anyone know why or how you could improve on that
00:30:41
okay out from that is that a lot of it yeah
00:30:45
it has to a library rely exceptions to cut the errors mostly
00:30:49
try and future and you have lots of libraries that we'll use future will use try
00:30:54
and you call stick your d. v. d. or enter into that if you said if you throw try
00:31:00
so when you know that work around that what you have to turn
00:31:03
out to do is use exceptions well not from them just typing it type
00:31:09
just typing it type is an exception
00:31:12
and so the the air is no exception was product answer usable
00:31:18
and you can absolutely stick values of type to be there in the
00:31:22
left or in the try sorry or in a future start problem at all
00:31:28
so the trick that but it allows your exception c. d. t.'s to
00:31:32
be a lot more usable when interacting with that discussed in a library
00:31:37
and right has returned to it um okay
00:31:43
uh what's wrong with that aside from everything
00:31:48
get off well down the return key word so there's lots and lots and lots
00:31:53
of reasons to not want to use it and um we has a whole go to
00:31:58
segment thing against basically same a discussion fracture friendship disparity again same discussion but mostly
00:32:04
is just completely insane ah it doesn't not at all do it i think it does
00:32:10
going to
00:32:13
well we're going to go for that right so this code yeah
00:32:19
ah looks kind of saying this is what somebody who's come from desperate for
00:32:24
example might write it makes a lot of sense ah you have a list of
00:32:27
names and you want to map on it and add one to absolutely was invite
00:32:31
you in it so you created an was function which returns and plus one i
00:32:36
unless you know to look for return this makes a lot of sense but the compiler hasn't quite agree
00:32:42
telling me that i have said it was a list of him but really should be an eight yeah
00:32:46
doesn't make much sense to me um mapping in the least should return a list but
00:32:50
compare it is often more smart than i am so i'm gonna just it and play along
00:32:55
so i do what he does when he suggests and now this
00:32:58
another list of in cement you complain should sorry should be stuff nothing
00:33:04
when nothing occur as in the type that you have inferred something's really wrong
00:33:10
um and i have no idea what's happening here but i'm just going to follow the error messages
00:33:15
back to it well you find a list of nothing but i really wanted him into what the hell
00:33:20
so i don't know what's going on i don't want to know what's going on i don't want to understand what's going on
00:33:25
i don't use return it makes no sense um you construct understand at some point you want you will fail you will
00:33:32
you will remember that slide and you will think i should not have flight understand it don't touch to it isn't that right
00:33:39
um so don't use return ever just from it um and set are
00:33:45
possible improvement in sky free in that non local written statement might be
00:33:50
forbidden i don't know what that means so maybe the thing i don't know
00:33:55
uh um it's implicit conversions right so this here methods defined as implicit
00:34:04
means that it's implicit conversions so whenever the compilers going to find a string
00:34:10
that he would like to be an aunt is going to call this method and turned my string in tonight
00:34:18
just looks pretty nice it's pretty it's pretty fun to you know what's wrong with that
00:34:26
right so if you muttering it i'm not going to hit a for that you came up with the answer
00:34:34
oh absolutely woeful an exception uh 'cause it lets you write beautiful go like
00:34:38
that full bar divided by two and a competitor is going to be very happy
00:34:42
to compare that and and carry on as if nothing happened intends is basically you lying to the compiler
00:34:48
the tank right i have as you do the string section and and
00:34:52
this is most of the time not choose there are infinitely many strings and infinitely many more strings that are not in
00:34:59
synching the or change so this is going to break eventually sooner rather than later and you never want to do that
00:35:06
the main problem being that this implicit conversion is not total
00:35:11
so if this was total so say transform in seem to float
00:35:16
it's actually but it's okay 'cause it called veteran tends to wear that you're getting the types like to
00:35:21
each other but it will not fit at run time but this is this is horribly don't wanna do that
00:35:26
uh instead well you could is is really nothing sorry you
00:35:35
could do this really nasty thing can be explicit about y'all
00:35:38
um conversions or you could just try not to divide for now is
00:35:42
to 'cause doesn't make much sense it's also possibility um so this is
00:35:49
at least it's got to that's a reason to happen to conversions is this is how will every that exposed to classes
00:35:57
will allow you to add syntax is is how you can have the map method when you have a factor instance for example is very nice
00:36:03
an implicit conversions to enrich existed types existing types are okay
00:36:08
the also completely and needed things kind of free because you have extension methods so
00:36:14
as soon as kind of free happens stop using data conversions the compiled into fighting over it anyway 'cause is going to ask you
00:36:20
to enable the computation flag and then to be very explicit about it uh it's
00:36:24
kind of free implicit conversions are kind of frowned upon and this is a good thing
00:36:32
implicit resolution so
00:36:37
i'm going to go for that one actually 'cause it's it's all um what happens here is
00:36:41
have to find the type config which contain the port for some sort of network configuration
00:36:47
and that if i get bored methods that for any config value in scope you can treat on the port so that way you could
00:36:55
implement a default configuration here so by default my configuration is going
00:36:59
to have port eighty eighty and if i called get port like that
00:37:04
then is going to work out that the default implementation here in your default pulled into the
00:37:09
eighty eighty it's quite common in the chasm but in skylight suffers from a pretty big problem
00:37:16
which has to do with uh impress each other wing so yeah in
00:37:20
another object i define a new implicit value of a completely different type
00:37:26
before coming here is that that config default config yeah of type int the only thing they have in common is their
00:37:35
name and that should not have any impact than the the name of the time when you result types but it does
00:37:43
we import both a one a two you get the dreaded cannot find good value for
00:37:47
parameter blah blah blah and this is very confusing because this is not what to expect
00:37:53
it's actually quite clear what happens when you remove simply sickness of
00:37:57
this if you were to import with a one a two and
00:38:00
ask the compiler to use the vocal fake easy so you what's ambiguous have
00:38:04
it both from a one and a two which one do you want to use
00:38:07
this is very clear this error message so when i don't have any
00:38:11
place it's thing stocking male anderson happens but what actually happens is you get
00:38:19
could not find peace that before parameter and this is black magic to most people who stop reading the language
00:38:26
this is extremely confusing and the bad news there is no real work abound
00:38:32
provided so that you don't have a perfectly unique name is going to happen eventually
00:38:37
and you can't guarantee that didn't have a computer you think anybody can be using the same as you and it was worse
00:38:44
thing is here when you do that you might not know that any to declare as an implicit value of the
00:38:49
wrong name so you might have no idea that you causing the problem you don't know what importing because importing everything
00:38:55
this is very confusing to beginners and what happens it's in that match explain it
00:39:00
so when you do it when you have to campus values given city names renal names
00:39:06
with with your name in its that nicholas is fancy full bar instant for type int
00:39:11
up it looks in it but the whole point it's an increase in value that is going to
00:39:14
see the name he's not supposed to maybe play the names of disembodied so so it's not a problem
00:39:19
but still not perfect somebody might also because nicholas and have the same in colleges i do so that my to be a problem
00:39:26
luckily in sky free first you have import implied which
00:39:30
means you knows that you imply importing implicit instinct is values
00:39:35
so it's less likely to happen because you call to do it by mistake but more importantly
00:39:39
um implicit danger in doesn't exist so the problem just completely gone it's gonna freeze it's major improvement
00:39:47
um ah string get nation
00:39:50
okay and anybody tell me what's wrong with that
00:39:58
good night
00:40:00
okay well um yeah string concatenation and using plus to distinguish generation this is this is a mistake because plus
00:40:09
this kind of insane it doesn't behave very coherently so yeah i have a
00:40:13
list of string and i plus bar it's or i dunno string to it
00:40:17
and deciding to return a string which has a value not super interesting was going to do that on the other hand if i have a set of strings
00:40:26
and i at but it's going to get to the collection and doesn't have the same type at all so this is with uh
00:40:34
when you know what happens and in if you understand it and you go ah
00:40:38
of course what that thinking but when try to expand that to somebody who's learning
00:40:41
the language you of course to behave that way coconut look at what the person's
00:40:45
going to look at lecture notes and he's going to go away never to sky anymore
00:40:49
uh and i'm not even talking about this absolute nightmare where you had to to list of
00:40:55
ins and the completion or is what i expected a string why why would expect a string
00:41:02
again it makes sense when you knows that any to string uh the the thing if you do know that these two two string ad
00:41:09
it does exist and what it does i'm sorry for your pain when fruit as well um up
00:41:14
i think it's the predicted um it is deprecated into that setting has been
00:41:20
removed from to that fourteen magically back in sky free i'm not sure why
00:41:25
uh i think it's going to i think is it just that's kind of free hasn't
00:41:28
been revenge on to that to that uh in standard library i hope i hope um but
00:41:35
so instead don't use a shouldn't get nation um use string interpretation instead
00:41:41
uh this is first i find a lot more readable then it doesn't have the same problem because it's using plus
00:41:48
and also yes they don't you know i was making the point that string customisation is much slower
00:41:53
than stricken depletion so that's that's well if you if you care about 'em efficiency use string information
00:42:01
uh in conclusion um
00:42:05
how do we enforce extract is is having lectures at all the stuff
00:42:10
that i have shown you and there's a lot more with it came from
00:42:13
i've i've just pick the best how do we make sure that this thing doesn't crop up in your code well
00:42:20
first could reduce i knows that a lot of people don't actually like could we use but there's some very solid research
00:42:27
that proves that code reviews actually does drastically reduce the amount of the facts in software
00:42:32
so when you get the slide you can click that he's going to link you to the publications that effect do code
00:42:38
reviews it's great and you have to avoid these things and you have to teach them to people who don't know them
00:42:44
use tools sets the to make the finding of these problems so that's a bunch of that's
00:42:51
i think so i think that at the moment that's all that exist but
00:42:55
let's get keep changing and we're happy valley beyond tuning at the moment so
00:42:58
i wouldn't be surprised that by next week we have another one but at
00:43:01
the moment gets can't go to what remove the scandal into its kind of style
00:43:06
it's gonna say especially if you go through rob notices pose a subject which uh makes kinda
00:43:12
kind of thing again and sky fix all these tools are going to make your code much much more reliable
00:43:18
also switched to scale officers can 'cause that you could see it fixed all of the problems that that that hard
00:43:24
um this well my favourite that um that well
00:43:31
either bad or best participating honestly look at it
00:43:34
um there's a lot more than them and i'm pretty sure i don't know all of them
00:43:38
so if you guys have things that you think i should have talked about and i haven't i'd
00:43:43
love to hear about that i'd i'd love to learn a bit more and i'd love to
00:43:46
include them into my next version of this tall going to the website upgraded to go with that
00:43:53
i i wanted to thank sees cannot contributors and dotty you
00:43:58
the channels they should earmarked i don't know whether he's here
00:44:00
uh but he's basically written all of c. e. a future improvements actions he's easy to be leaving database
00:44:07
we never asked something that but how does that work oh that's problem here publication here to get him
00:44:12
a depressed five second senior year of the hot i don't know he does that he's really quite impressive
00:44:17
well if you're wondering about sky that witnessing the language for how this one is
00:44:21
going to be fixing the future this to be the channels are really really great
00:44:26
a more informations so the slides are already
00:44:29
available here and um if you want to have
00:44:36
proper articles on all these rules and mall as as a companion site at this u. r. l.
00:44:42
well uh i to the time to to write these things down properly not just the slides
00:44:47
uh i can fully into the uh work they say though blah blah blah this is all done
00:44:51
with remote way remote yes and top hat on this problem is still here i sit in the fall
00:44:57
a tight is an amazing tool that will make sure that all the code you so in the slides is correct and evaluates to
00:45:03
what you've seen because it's actually executed when the slides i compiled
00:45:07
so it's not possible to gives like to compile and so the truth
00:45:11
and do we have any questions
00:45:15
oh
00:45:24
oh yes
00:45:30
yes thank you are thinking fast and i have a question rises colours needs and then uh
00:45:36
is it possible to and such cases what you described to me out
00:45:40
someone's been apart right so that's the point is it's made a tool so
00:45:45
was the first part of the question where is kinda fix 'cause right now what is where is what is what the question what is good
00:45:52
okay okay right uh and so these tools will automatically and
00:45:57
i the code and fragile built if they find on the distance
00:46:01
uh as a pretty opinionated what remover in particular is really hardcore with my
00:46:05
reports uh you can turn off some some things that you might not agree with
00:46:10
for example is that what remover is going to follow any code that defines default value for methods
00:46:15
but sometimes quite important to us and so i contacted with that ward so but
00:46:20
but all these tools will fan you build if they find some sort of pattern
00:46:25
and you can pick and choose an at whatever it wants and i mean i think that all the things i showed here are reported like one of these tools
00:46:34
i turned my back
00:46:47
oh i have a question about a using a try
00:46:51
ryan in other players learn except it may happen um
00:46:57
i have those experiences out there is such puerile um way
00:47:03
um my oh sure in all some slight orgy
00:47:07
oh oh so you'll write a cult and on
00:47:12
you learn to scold or in every place you should somehow handle
00:47:18
uh uh try um then should think about um
00:47:24
all the holes and you express dot membrane uh it will be some thresholds
00:47:30
not a okay in those cases i should eat user tried
00:47:34
but there are some cases slow or a a small it certainly is
00:47:40
completely okay right absolutely no this is this is a very
00:47:42
good question so exceptions are absolutely okay provided that actually are exceptional
00:47:49
so if you run into in areas such as a c. p. u. dot
00:47:52
files it's okay to crash you probably going to be able to recover from that
00:47:56
well uh the example i gave a word for example trying to do and and
00:48:00
number for that exception most strings are not things it's not exceptional case it's a
00:48:05
common case that this is a failure so this is not an exceptional exception it's
00:48:09
unexpected exception and you should not use exception for that the should use reason type
00:48:14
but for anything that you're not likely to supply from um or that just
00:48:19
doesn't make any sense uh just let that go absolutely let let's fatal errors
00:48:24
um be from that's on the problem at all i don't have much of a choice anyway i mean perhaps if you just if i'm not gonna do anyway
00:48:33
and for the question
00:48:36
don't matter whatever we don't have any posts are right okay so i don't have time properly
00:48:40
questions i will be here if you have other questions don't hesitate to come over and ask them

Share this talk: 


Conference Program

Welcome!
June 11, 2019 · 5:03 p.m.
1575 views
A Tour of Scala 3
Martin Odersky, Professor EPFL, Co-founder Lightbend
June 11, 2019 · 5:15 p.m.
8340 views
A story of unification: from Apache Spark to MLflow
Reynold Xin, Databricks
June 12, 2019 · 9:15 a.m.
1271 views
In Types We Trust
Bill Venners, Artima, Inc
June 12, 2019 · 10:15 a.m.
1569 views
Creating Native iOS and Android Apps in Scala without tears
Zahari Dichev, Bullet.io
June 12, 2019 · 10:16 a.m.
2233 views
Techniques for Teaching Scala
Noel Welsh, Inner Product and Underscore
June 12, 2019 · 10:17 a.m.
1296 views
Future-proofing Scala: the TASTY intermediate representation
Guillaume Martres, student at EPFL
June 12, 2019 · 10:18 a.m.
1159 views
Metals: rich code editing for Scala in VS Code, Vim, Emacs and beyond
Ólafur Páll Geirsson, Scala Center
June 12, 2019 · 11:15 a.m.
4697 views
Akka Streams to the Extreme
Heiko Seeberger, independent consultant
June 12, 2019 · 11:16 a.m.
1552 views
Scala First: Lessons from 3 student generations
Bjorn Regnell, Lund Univ., Sweden.
June 12, 2019 · 11:17 a.m.
577 views
Cellular Automata: How to become an artist with a few lines
Maciej Gorywoda, Wire, Berlin
June 12, 2019 · 11:18 a.m.
386 views
Why Netflix ❤'s Scala for Machine Learning
Jeremy Smith & Aish, Netflix
June 12, 2019 · 12:15 p.m.
5030 views
Massively Parallel Distributed Scala Compilation... And You!
Stu Hood, Twitter
June 12, 2019 · 12:16 p.m.
958 views
Polymorphism in Scala
Petra Bierleutgeb
June 12, 2019 · 12:17 p.m.
1113 views
sbt core concepts
Eugene Yokota, Scala Team at Lightbend
June 12, 2019 · 12:18 p.m.
1656 views
Double your performance: Scala's missing optimizing compiler
Li Haoyi, author Ammonite, Mill, FastParse, uPickle, and many more.
June 12, 2019 · 2:30 p.m.
839 views
Making Our Future Better
Viktor Klang, Lightbend
June 12, 2019 · 2:31 p.m.
1682 views
Testing in the postapocalyptic future
Daniel Westheide, INNOQ
June 12, 2019 · 2:32 p.m.
498 views
Context Buddy: the tool that knows your code better than you
Krzysztof Romanowski, sphere.it conference
June 12, 2019 · 2:33 p.m.
394 views
The Shape(less) of Type Class Derivation in Scala 3
Miles Sabin, Underscore Consulting
June 12, 2019 · 3:30 p.m.
2321 views
Refactor all the things!
Daniela Sfregola, organizer of the London Scala User Group meetup
June 12, 2019 · 3:31 p.m.
514 views
Integrating Developer Experiences - Build Server Protocol
Justin Kaeser, IntelliJ Scala
June 12, 2019 · 3:32 p.m.
551 views
Managing an Akka Cluster on Kubernetes
Markus Jura, MOIA
June 12, 2019 · 3:33 p.m.
736 views
Serverless Scala - Functions as SuperDuperMicroServices
Josh Suereth, Donna Malayeri & James Ward, Author of Scala In Depth; Google ; Google
June 12, 2019 · 4:45 p.m.
936 views
How are we going to migrate to Scala 3.0, aka Dotty?
Lukas Rytz, Lightbend
June 12, 2019 · 4:46 p.m.
710 views
Concurrent programming in 2019: Akka, Monix or ZIO?
Adam Warski, co-founders of SoftwareMill
June 12, 2019 · 4:47 p.m.
1975 views
ScalaJS and Typescript: an unlikely romance
Jeremy Hughes, Lightbend
June 12, 2019 · 4:48 p.m.
1377 views
Pure Functional Database Programming‚ without JDBC
Rob Norris
June 12, 2019 · 5:45 p.m.
6389 views
Why you need to be reviewing open source code
Gris Cuevas Zambrano & Holden Karau, Google Cloud;
June 12, 2019 · 5:46 p.m.
484 views
Develop seamless web services with Mu
Oli Makhasoeva, 47 Degrees
June 12, 2019 · 5:47 p.m.
785 views
Implementing the Scala 2.13 collections
Stefan Zeiger, Lightbend
June 12, 2019 · 5:48 p.m.
811 views
Introduction to day 2
June 13, 2019 · 9:10 a.m.
250 views
Sustaining open source digital infrastructure
Bogdan Vasilescu, Assistant Professor at Carnegie Mellon University's School of Computer Science, USA
June 13, 2019 · 9:16 a.m.
376 views
Building a Better Scala Community
Kelley Robinson, Developer Evangelist at Twilio
June 13, 2019 · 10:15 a.m.
245 views
Run Scala Faster with GraalVM on any Platform
Vojin Jovanovic, Oracle
June 13, 2019 · 10:16 a.m.
1342 views
ScalaClean - full program static analysis at scale
Rory Graves
June 13, 2019 · 10:17 a.m.
463 views
Flare & Lantern: Accelerators for Spark and Deep Learning
Tiark Rompf, Assistant Professor at Purdue University
June 13, 2019 · 10:18 a.m.
380 views
Metaprogramming in Dotty
Nicolas Stucki, Ph.D. student at LAMP
June 13, 2019 · 11:15 a.m.
1250 views
Fast, Simple Concurrency with Scala Native
Richard Whaling, data engineer based in Chicago
June 13, 2019 · 11:16 a.m.
624 views
Pick your number type with Spire
Denis Rosset, postdoctoral researcher at Perimeter Institute
June 13, 2019 · 11:17 a.m.
245 views
Scala.js and WebAssembly, a tale of the dangers of the sea
Sébastien Doeraene, Executive director of the Scala Center
June 13, 2019 · 11:18 a.m.
662 views
Performance tuning Twitter services with Graal and ML
Chris Thalinger, Twitter
June 13, 2019 · 12:15 p.m.
2003 views
Supporting the Scala Ecosystem: Stories from the Line
Justin Pihony, Lightbend
June 13, 2019 · 12:16 p.m.
163 views
Compiling to preserve our privacy
Manohar Jonnalagedda and Jakob Odersky, Inpher
June 13, 2019 · 12:17 p.m.
302 views
Building Scala with Bazel
Natan Silnitsky, wix.com
June 13, 2019 · 12:18 p.m.
565 views
245 views
Asynchronous streams in direct style with and without macros
Philipp Haller, KTH Royal Institute of Technology in Stockholm
June 13, 2019 · 3:45 p.m.
304 views
Interactive Computing with Jupyter and Almond
Sören Brunk, USU Software AG
June 13, 2019 · 3:46 p.m.
682 views
Scala best practices I wish someone'd told me about
Nicolas Rinaudo, CTO of Besedo
June 13, 2019 · 3:47 p.m.
2713 views
High performance Privacy By Design using Matryoshka & Spark
Wiem Zine El Abidine and Olivier Girardot, Scala Backend Developer at MOIA / co-founder of Lateral Thoughts
June 13, 2019 · 3:48 p.m.
754 views
Immutable Sequential Maps – Keeping order while hashed
Odd Möller
June 13, 2019 · 4:45 p.m.
278 views
All the fancy things flexible dependency management can do
Alexandre Archambault, engineer at the Scala Center
June 13, 2019 · 4:46 p.m.
390 views
ScalaWebTest - integration testing made easy
Dani Rey, Unic AG
June 13, 2019 · 4:47 p.m.
468 views
Mellite: An Integrated Development Environment for Sound
Hanns Holger Rutz, Institute of Electronic Music and Acoustics (IEM), Graz
June 13, 2019 · 4:48 p.m.
213 views
Closing panel
Panel
June 13, 2019 · 5:54 p.m.
400 views