Devreal

My Favorite Feature in the Whole Wide (world of) Scala 2.10

Event: Silicon Valley Scala Symposium

funconf 2013, Adriaan Moors: My Favorite Feature in the Whole Wide (world of) Scala 2.10

Recording: funconf 2013, Adriaan Moors: My Favorite Feature in the Whole Wide (world of) Scala 2.10

so welcome um i'm going to be jumping around for the next hour to kind of keep you away power through that food coma sorry i'm sorry am i what sorry i am recording thank you um yes so we'll just have to cut out those first couple of minutes you can like maybe start now so you don't have to see my introduction again anyway so um i'll talk to you a little bit about scholar 210 in general a bit of scholar 211 but i'm going to be focusing on uh what supposedly is my uh favorite feature in sca210 um so i'm this tech leader type safe in a former life i was a postdoc at epfl working on the on the theory of scala and now i'm firmly on the the dark side um so first of all uh thank you to all contributors i've got a lot of those and getting more every day so you know who you are i'm not going to go through the numbers but we're very happy to to you know be in touch and get a lot of bug reports it's always fun so um as i said i was going to keep you away awake sorry through your food coma so i'm going to start with some um control to stir some controversy controversy and i'm going to say that scala is simple and i'm kind of not really going to prove that i'm just going to illustrate it i guess um ritiki did a really nice talk about how simple and easy aren't the same thing so no one said it was going to be easy certainly not me so i am serious about this and be warned that doesn't mean it's going to be easy and one way that i claim scala is simple is because it's a unifier so by unifying more concepts you have fewer things to learn you just kind of have to learn the core set and then how they relate to each other or how they how they simplify to each other as a classic example you have functions and objects that are unified as you all know by now um and there's a couple more that i'll i'll point out during the talk so it doesn't just unify um language features it also unifies how you use it through the rebel that paul poured a lot of manpower in and get it to the point um where it is now um where all my experimentation and a lot of bug fixing in the scala compiler happens in the in the rebel and you know you can do large-scale development and i don't think that needs requires proof at this point um so like i said there's a simple core and it's essentially objects and methods because that's what we have on the on the on the on the java on the vm uh and most of these things of these other features that when you first see them it might seem like a bunch of complexity and uh lots of stuff you may not want or need um and that may very well be true but most of them can be understood in terms of the simple core and they all for they all follow um the same kind of strategy of how they are de-sugared into into something that can be expressed in this this core and so in this talk i'll talk a bit about how that works for string interpolation and for pattern matching um for comprehension is another example where really there's just a bunch of map flat map and with filter calls with the lights of a little bit of nice syntax on top pattern matching you can actually put the pattern meter in virtualized mode so to speak where um it's a lot like four comprehension actually um string interpolation i'll explain in detail context bounds they're just synthetic sugar for implicit arguments oh yeah um some one thing i forgot to say in my introduction is please interrupt i don't really know what you know what you don't know or what you would like to know so at any point in time just you know call me out on something if uh if there's something you disagree with or you would like to know more about i'll try my best to make it as interactive as possible you disagree well let me make an example out of you what do you disagree with fraytel everything everything oh well you're just okay so he disagrees so don't ask him any questions or ask for him for comments um i'm sorry oh no that's just kind of my meta notation for saying when you write this in scala really what it means is you make a new i mean i had to fit it on one line because i didn't want to spend more than that on it but so whenever you see a function literal you know there is no such thing uh even though java 8 might pretend there is uh there is no such thing on the bare metal there is just uh classes which are instantiating an anonymous version of here i mean it's actually new function one but that um and so then there's your apply method so function literals are just objects that have an apply method that take the same number of arguments as your thing and my twiddle there is just to kind of say it we kind of oh no so sorry your question was more advanced than that well i'm sure you could somehow but i wouldn't recommend it sure yeah it's on my github so that's github.com yeah um i can't guarantee you you'll be able to write my read my handwriting any better than so github and then you gotta count your a's adrian m and then i ran out of space there just continue you know i'll just oh uh it's talks and then i believe you're gonna have to write something like tree master scala 210 or you could just click your way to it i'm sure once you get to adrian m talks you'll find it um i think i pushed before starting my talk so uh if you want to run key down you can follow on your laptop but luckily the projector is working so um yeah so okay i guess that covers that slide uh anything else great um so we're gonna be doing some experimenting which um you might wanna do on your own laptop but i'm just gonna do it here i really hope everybody can read it because i don't know much about css and i don't know how to change the font size on this anymore i wrote this talk a couple months ago but so i hacked together a little thingy that um well you know i'll take a word or a phrase or i disagree or something and i'll print it just to prove you i mean like i promise i didn't make paul say that so i could just like rig the show but yeah paul disagrees um is there oh um here there no one saw that one coming so that's not scripted um so right so we're going to have a rapple at our disposal in these slides those are also on my github people have forked it since i think jason has a nicer version and um andrew i forgot his last name for scala puzzlers this year scala days also use it for a nice talk um so whenever you see one of those boxes appear feel free to shout out code you'd like to see in that box to try something out not in this one though because i'm just going to quickly show you how it works so we just open we just have a websocket running thingy i just googled something that's actually i believe deprecated api by now but it's just listening for messages and it's sending it off to the interpreter whatever my javascript thingy here sends from the web browser and then the interpreter will split that string and got um this is extremely robust code so don't please don't run this in production um but it'll call it'll call into the to the standard scala interpreter and send that string off and send the result back and you'll see it appear i have some crazy patterns going on here that i'll talk about in a minute um because well you know i was i was writing a talk about string interpolation so i went nuts with string interpolation everywhere so here are the links uh by the way this is the the wrapper for the rebel to kind of get a websocket running on top of it and this is where um well actually it should be called talk because right now there's only one there but um there will be more um so i'll talk a bit more about that first uh i guess since i promised to talk a bit about scala 210 i'll give you some of the highlights um so the last thing i did on the not dark side was rewrite the pattern matcher um that was kind of it was going to be my summer fun project and then it became my last year fun project and i am pretty pleased with the results i'll talk a bit about string interpolation today i won't talk about valley classes because i wouldn't recommend using them for any but anything but basic stuff do you agree do you agree or disagree paul using value classes for anything but basic stuff to agree with something yeah so specialization value class especially those combined i wouldn't recommend it yeah yeah so i mean yeah there are some cool things you can do with them but i would be careful implicit classes i think are pretty great they just um they just kind of encapsulate a pattern that's very common with implicit um enrichment i believe is the official party line on that now we also introduced few feature imports to let you take away stuff from your developers if you're not comfortable with them using stuff i can definitely see a use for that with some developers not looking at you paul um i'm not better uh so futures and promises i think was a great addition to 2210 with a corporation from from twitter and the acca team and epfl uh guys we added oh i added uh dependent method types or at least cleaned up their implementation so now you can create cakes from your methods if you're so inclined and we got a great new asm based back end which brought us one seven one six by good support and it's also a bit faster we're kind of continuing in that team that's miguel at garcia dpfile who's doing a lot of good work there the next gen optimizer that's going to be experimental in 211 for now um so then i guess we have the unholy trifecta at the end here trade dynamic i guess is the least unholy of all it's pretty fun to i'll show you an example of how to use it um so who's written or used a macro in the room i'm just curious let's start with written i'm glad to see that all right who's used although he probably wouldn't know because it just looked like methods but okay so good all right i'm sorry yeah yeah yeah so then yeah a lot of you have used macros um but i think it's good that not too many people are writing micros for now because we're still working hard to figure out the api there and it's bound to change and it's going to keep changing in 211 until we get it right we're not gonna set anything in stone uh until we're semi-confident it's better than what we have now and um so 211 is going to have most of the features you have in scala to 10 for macros i mean for macro authors that is but it's it's uh it's going to be experimental it's going to be changing because we're still thinking about how to give a nice api into a compiler that really wasn't designed to expose its guts like that so a quick word about the pattern matcher if you've ever had an exponential space bytecode explosion we'll be glad to hear that's fixed in 210 overall fixed close to 100 bugs we kind of just rewrote the whole damn thing and chucked out the old one in 211 and i'm glad very glad to say that we're getting external people helping out with its implementation like getting a better uh cnf encoding um and um yeah we're working on improving it further into 11. i'll talk about that in a minute as well but you can do some cool stuff like overwrite what it means to match so you can make pattern matching backtracking or probabilistic or whatever you want that's experimental but um it's it's kind of fun to experiment with if you like that kind of stuff um so just i mean i'm sure everybody's used pattern matching here before but since i have this rebel i was gonna just you know show you so if i just naively write something like a function that checks some option and um so yeah i'm sorry if this is this readable okay i'm glad and i hope you're just being polite because i said i can't change it anyway but um so we're looking for uh you know an available result that is magic so obviously there's a couple ways in which this can crash and the scala compiler will tell you now and it will give you examples it'll say well if you pass us a none you'll get a match error or if you pass a sum that is that doesn't have a magic string in it it'll crash as well so i won't go into too much detail i mean everybody knows how to fix that well you just do this right done um but anyway so it'll it'll tell you about a lot about which cases you're missing as long as you're dealing with sealed hierarchies of traits you can get a lot of nice error messages for there and that will save you some match error agony at run time any questions about that i guess that's all pretty obvious um so as i said before uh scala is unifier and extractors and pattern matching are another example of that we didn't just bolt pattern matching on top of an old language because it's fundamentally disruptive in a language where you care a lot about encapsulation you don't want people just looking at your state you want to be able to customize you want to be able to evolve how you represent your state and that's what extractors do they give you a handle on how pattern matching actually goes to that state so that you can change it if you want to so you start out with case classes you get you know the pattern match will go straight to your fields to extract those sub patterns later you decide actually i don't want a case class i want to do some extra magic behind the scenes while you just write an apply method and the companion object for that class and your matches will will behave in the same way except that they can do whatever logic you want behind the scenes i'll give you an example of how that works in a second but that kind of goes back to my my statement earlier is that really what it's all about is understanding how pattern matching and extractors how they de-sugar into method calls and i'll show you how that actually works uh and then my claim is the complexity of pattern matching is reduced because really what you need to do is understand the core methods and objects and i'm pretty sure you understand that already how do i understand pattern matching in terms of that well that's something you need to learn but i'm sure all of you have so right now that requires option boxing abstraction always comes at a cost right um but um paul is as we speak i mean i'm disappointed you're looking at the screen instead of your screen but we have a couple of ideas of how to avoid the option boxing overhead and applies and so on and so that'll that'll land into 11 pretty soon so as i said i was going to show you how extractors work exactly and this is this goes back to if if you were really reading really fast um some an extractor i was using in one of the earlier slides um so let's say um we want to match a string and get an integer out so this is going to be uh this is going to have an extractor that does the conversion from string to int if possible so just using the the try that we got that we that we got from twitter is util tool test and write and unapply like that so really what this line is is just saying well put your constructor in reverse and tell me if there's something you could have constructed essentially so this match really what it does is it calls i to unapply because i was the pattern here and it will line up all the sub patterns it saw under this pattern here with the results from the unapply so in this case we only return excuse me we only return one result but you can return an option with a tuple in it so you can return up to 22 results there are no plans to increase that number however with paul's uh changes in principle there wouldn't be there wouldn't be a limit like that huh right right so but for now unfortunately as long as you're dealing with tuples you're you can't have more than twenty two sub pattern so is this kind of just abundantly clear or am i going too fast i it's hard to say with a mix of faces like that so i'll just be optimistic i know it's just after lunch i know this um well yeah okay that's so yeah fair point um yeah um i we're kind of peeling off the onion like with like layer by layer and so this you can sugar further and i kind of assumed that this would be a standard a pattern but yeah we can we can take it much further so really what this does is not the greatest editor in the world so we call this the scrutiny and it says now you see why i didn't type this i don't really want anybody to know uh there so um well actually that's like sub pattern one and then you say if sub pattern one and i mean there's this whole chaining of ifs obviously saying like if this uh check passes then did that check and so on we were smarter about caching those things and i mean like we don't do the same check twice most of the time so well it's it's an instance off check right so it'll it'll be yeah one way or another right um yeah i mean it has to check for it actually has to do more it has to check that 10 as a string and so on and so i'm kind of giving you like you can really if you want to see i can tell you the secret uh uh boss code for scholasti that will show you the sugaring of of of matches um it's not a b aav but there's some way of of of showing you what's happening behind the scenes but essentially it's just a nesting of ifs i don't have this feature in the rebel here unfortunately i could go off the screen and then i'm sure i'm going to go over time so i don't want to do that but and what it really comes down to is saying something that is like that it's kind of like that roughly so a pattern match kind of does a depth first reversal of your of your tree of the data structure that you're decomposing and every layer it peels off it does either equality checks or instance off checks or it invokes an unapply and then it just goes in according to the rules of what how you match a pattern like if it's constant you do different things from when it's when it's a type check and i mean for example the the argument type that i give here tells the pattern matcher that actually to check that what you're unapplying is actually a string and you can also communicate whether your extractor uh is always expected to succeed by returning a sum instead of an option so the pattern matcher will we'll see that as something that can never fail if you return some from your and apply it'll do various things with unapplied seeks that i'll get to later taking the length and so on but the core thing is just it's a bunch of chained if-then elses where the else is throwing match arrow in the end so um no idea how far in i am but we're finally getting to the meat of my talk 20 minutes all right doing good so um here's a couple of ways that you can now at least try to write generating a string with an embedded number so the way to write the way to read this is it's a string literal that's interpreted under the s string interpolator and it has one hole here that's called and that's going to splice in the n variable into that hole so the n here is defined as an argument i'll explain in much in much more detail exactly what those uh letters mean and so on so here's an f like the printf uh interpolator that will uh splice in the same and but it will do so under the percent d formatter and it will actually check that the n corresponds to the expected format um here so if i run this i'm going to get an error because there is this broken bottles thingy here where i sneakily tried to pass in a double where int was expected by the format specifier now the compiler doesn't know anything about any of this that's actually macro so in a sense the compiler does because it chips with the compiler but it's not part of the string interpolation spec it's just you know the string interpolation de-sugaring kind of gives you this kind of checkability when you compose it with macros and i'll i won't go into much detail about macros because i don't want to get anybody too excited about them but i will tell i'm happy to answer questions about them later so really what string interpolation does is you drop all the holes that are demarcated by a dollar and you can actually put accolade like curlies around if you want a more complicated expression in there so you can put arbitrary expressions in there and then pack all those parts in a string context so make an instance of string context call the interpolator which is that name that is before the string and it can be anything s is the one that's standard that comes with the standard library and then pass the actual values of those holes as you specified them after the dollars and possibly within those curlies as arguments to that method so for example the first one actually de-sugars into create a string context i've dropped the dollars and since it was the empty prefix before the whole i'm just going to pass in the empty string here so essentially every comma in your list of arguments corresponds to where i'm going to splice in something later and then bottles of beer is the remainder of the string with the dollar dropped and then i'm going to call the s interpolator which is just a method on string context and i'm going to pass in the n which comes from the dollar from the first hole and the only one that was missing in that in that string so i'm guessing that's that idea is clear so somewhere in the standard library we have that s method that is defined directly on string context there is nothing magical about it we just do this dumb translation and it just happens to work out because that's how those methods look and the s1 s interpolator will take any number of arguments and it will just do the format magic for you as you would expect and you know an efficient way of constructing strings in in java any questions about this yes exactly so the the the prefix you put before the string literal that's the name we'll use for for the method that we constrain context so that's how you get to insert your own it doesn't it's not mandated what they are we just say well the standard library has these by default and that's just how it happens to work out when you write those but you can write your own yes absolutely and people have for example our quasi quote library which is uh a way to construct and and deconstruct uh scala asts um uses the string interpolation mechanism as is with a bunch of clever macros to add the q uh prefix to string so that you can write q and then some scala code with holes in it and you can actually match uh on them to kind of get for example the arguments out of a call that you're analyzing or you can create some valid scala asd and the sky's limit you can do json or whatever you can do you can embed java source code in those strings if you wanted to because you can do triple quotes and have multi-line and so on there are a lot i mean and i guess this is kind of this is touching on why it's my favorite feature it's actually really simple to implement this in the compiler it's pretty simple to explain how it works but there are a lot of things that people have done and that you would be able to do with it later so um the sugaring of the safe bottles version but as you recall uses the the format specifier here that's what it de-sugars into and that's because the f method here is actually a macro i'm not going to go into how it works but you can imagine what it does it gets a constant for that string and it looks at all the percent signs and figures out what the types need to be based on you know d needs to be an end and so on so that macro is a standard also standard macro shipped with scala 210 if you're very curious i can test my internet connection and see if yeah there you go um so probably so this is in the sky tools reflect package and um it does a bunch of you know analysis on how many parts there are uh does some parsing of the flags it checks the types and then it just looks at the format modifiers and here this is how we generate the trees this is why macros are experimental this is not the nicest api you can imagine but these are scala ast types or case classes that will generate the actual format call that you that you just saw so that's that's how that works so this is just a this is the macro and you can you know look at it for inspiration if you want to do something similar but the point is that the actual string interpolation functionality in the compiler doesn't have to know anything about this so um since i said yes suppose i wanted to do something myself what i need to do do i have to write a micro or do i have no well it depends on what you want to do so if you want to do compile time checking and say well hey you wanted to splice in this and the type of that thing doesn't correspond to what i was expecting based on analyzing the string constant that you supplied me then that's something you would have to do at compile time if it's just you know parsing json or something like that at runtime then all you need is to enrich the string context class with a with a method that corresponds to the prefix you want to use any other questions so this kind of and so this is kind of i'm going all the way with the story and so now now i've showed you how to construct data with string interpolation i'll show you how to deconstruct data which is what pattern matching is for and the point is that once you understand how one of these directions of the equation works you can understand the other one it uses the same thing so string as i've not explicitly said but string interpolation is a first class concept it's just a method call it's just a value you can pass around and we'll apply this now to actually make this work so i want to be able to use an interpolated string i'm going to call it r for regex as a pattern instead of using it to actually create a value so what this should do is say okay that's all it's doing and i'm pretty sure it will run um because the standard r it should be in scope if it isn't it will i'll come back to this no so it isn't standard but we're going to implement it step by step and we'll come back to this slide and i promise it'll work so can this work because the spy kind of spoiled the question there yes it'll work so let's kind of work our way towards um how to figure how would you figure this out on your own right let's say someone gave this to you as a scala puzzler and you bet 100 bucks for it or whatever how would how would you approach this so the first thing i would do is get that weird looking pattern out of the way and put it in a value and um kind of reason from there what you know about pattern matching and how it works so i don't i don't have to do this it's just kind of a way to destructure the problem and reduce it to something simpler i have to be completely honest with you i kind of put them in gray here so you can see but i had to add parentheses that i'll explain later that's a little slight glitch nothing is perfect so the idea is though that if we can make this work if we can figure out the requirements based on doing the sugaring in full we kind of work our way back and see what we need to do to make this work so the extractor that we're going to use is going to be a special kind of unapply which is going to apply seek which is one that can give you a variable length or a variable number of sub patterns by returning a seek instead of just elements for your table so this is the first step and how you would de-sugar this according to the the extractor pattern matching rules so this step clear okay so we've reduced the problem now to how do we actually you know give pattern and apply seek method that will make this thing work so the next thing here is i've de-sugar as we already know how that works i've sugared the string context which is just dropped the holes there aren't any so i just get one argument from my string context constructor and r was the name i chose as my interpolator that i want to use so that's going to be the method that we call but there weren't any arguments there weren't any sub patterns you'll see that that is possible too in a minute um but that's what it is so really what we've what we've simplified it to is we need to add an r method to string context that when applied to this string we'll give something that has an unapplied c that won't apply to that or return a sum that's what we want to achieve so fortunately that's pretty easy um and we'll use implicit classes which are a new feature in 210 they're just a nicer way of writing implicit conversions from this case string context to our context so they give you a class definition that looks exactly like that with implicit dropped and the corresponding implicit def that will take any string context and create an arc context for you and the real reason we're doing this of course is that we want string context to look like it has this r method that's what implicit classes are for they give you extension methods so whatever appears in the single argument that we allow for a constructor of an implicit class it will now look like something of this uh when it has to when the compiler is looking for an r on a string context it won't find it as i showed you it won't compile the slide as is but as soon as we do this it will any questions about that so this is a new thing in 210 but it's not that new it just kind of lets you drop the implicit depth that you'd always write in companion with the class that you would write as a wrapper to add something to an existing class okay so if we run this the the interpreter that is running in the background will know about this now and we can take this step and i'm betting it'll work so it has an excessivity warning but the result is that it's okay the existivity warning is well you're only considering some here it might not match right the the extractor that we wrote might actually say it doesn't so this is a valid warning that we get like with a lot of you know we've written all this machinery from scratch or cells but you still get executivity warnings you could turn it off by just returning some from the extractor that we don't want to do that because in principle these things may not always match so this is another point where the same kind of behavior you expect with built-in case classes in scala you get with your custom extractors and that is part of my thesis that these things are simple you don't get like some kind of newfangled string interpolation that just is often its little own universe and you need to relearn everything that pertains to it no you just understand it how it how it is how it works under the hood which is pretty simple and then everything else you already knew about scala applies still so of course the de-sugaring when i take it all the way where we start it um will work as well so now we can kind of play around with this if you feel like it um do you have any suggestion of what we might do to this to break it or you know to see if it really works all the way i'm sorry yeah let's do that so i already put the cursor in the right spot should i just type it or do you want to like have a stab take a stab at it dollar something okay and we'll just return something uh-oh why did that happen oh yeah i didn't capture it it doesn't it's not creating groups sorry so um it'll only work when it detects groups in the in the regex this is something if you wrote a macro you could warn for this case where you have to try to capture something that hasn't actually been captured by the regex it's not something i can do when you're only doing this at runtime so let's get rid of this hideous stack trace and extract our temp right um i forget whether i ran i've i've set this up this talk up pretty carefully so i was actually planning on using this as well so you can take this all the way and you can actually also inline convert the string to an int so since these are sub patterns you can write whatever sub pattern you would write in your pattern matches these are not these are since you're you put your uh your interpolated string in a pattern context these aren't just variables you can write arbitrary subpatterns so what i've done there now is i've used the extractor that we defined earlier that will take a string and turn it into an end and so now before i haven't run this one yet i guess but this one is gonna is gonna extract the 10 as in it right um and so that's that's where i'm yes okay okay yes true yeah i agree it's a bad example about as far as readability is concerned um i didn't really have uh the the time to write a json example for example where i think it would make more sense to have holes and match on it no i yeah i i don't disagree but this is the simplest example i could think of to show you how you can write your own string interpolators and how how it works uh across the board yes there are a lot of things you can do in scallop you shouldn't do all of them that's kind of general advice about life but yes thank you absolutely i mean so the type of something is kind of determined by the macro so here there are no macros at play here so how does how is that type checking for there's no declaration or something like that so the i is a is an unextractor oh here i kind of glossed over it when i went back just now but let me show it to you again so i made this eye thing uh that has an unapply method which makes it into something that will take a string look at it by doing it to int and if that succeeds it'll tell you oh wait that was the end that was in there in that string that was that's the end version of the string and so that's what i was doing here so since i can read this where this isn't a pattern thing sorry in a pattern position would be slightly more accurate technical term i can write this embedded in my interpolated strings as well does that make sense now okay so this is essentially the implementation vehicle for quasi quotes um which are have been merged into 11 the last milestone where you write a bunch of clever extractors and macros to to look at the asts inside those those uh quoted strings um yes compiler executes code to figure out the type uh no it just looks at the at the types so it's it's it's sneakily hidden away and i again um i probably should stop trying to fit everything on one line and just uh you know as an example um of of bad scala code your public method should have signatures don't let the compiler infer your types um do as i say no it isn't so yes i mean i would in general never write public methods without a return type especially not if they're implicit don't ever write implicits without our explicit return type it's gonna it's gonna suck for technical reasons so um yeah so does that answer your question so there's no like compile time magic it's just the the standard uh pattern matching type checking rules at play the only change we had to do to the pattern matcher to accommodate string context was allow enrichment or as we used to call it pimping of methods inside of a pattern context because before we didn't allow implicit conversion while type checking a pattern now we do because otherwise you could never get the dot r on the string context in a in a pattern context but otherwise the pattern matcher is none the wiser about about string interpolation okay any other questions any other disagreement okay where was i yeah so um i just quickly wanted to mention that since we're talking about implicits it's another kind of unification where uh type inference and value inference meet so an implicit val is really just a value that's inferred rather than a type there are a lot of cool stuff you can do with that i would recommend not going too crazy with it i i once did but i've seen the light since um why is that come up again oh yeah so i wanted to show you the one-liner that we just did where actually patterns can also appear in variable declarations um not just in pattern matching constructs so this actually does the same thing it'll get the 10. it'll define a variable n and get that out so this kind of brings me back to the beginning of the talk where we're saying like you know sip 18 where we take away some of the features from you this is great stuff when you want to do really advanced things i would not recommend doing this as um i'm sorry i don't know your name point it out um but you can if you want to so as i said already quasi quotes are a cool application and the camera team also is doing some cool stuff related to quasi quoting so the desire for new toys is very high and and it has been high in the in the last couple slides um but we're a pragmatic bunch i mean we're not i'm not going to tell our clients hey start writing a bunch of crazy string inflators i just wanted to show you guys how you can do it if you want to do something like that uh we're really you know we spent a lot of time thinking about java interrupt uh how to deal with legacy but you want to balance that out with actually making it fun and without losing your sanity so as an example of combos um you know immutable yeah yeah let's you know stay on that bullet but when you need it it's there for you and there's other features i kind of anticipated your your disagreement i mean there's other features you shouldn't be combining here you write a var and then you start doing stuff in futures with that var you can do it there's nothing we can i mean we can technically do stuff to keep you from doing that but we won't we're just counting on your good judgment not to do that um so i mean i'm just kind of glossing over to slide but i'm just saying like shared mutable state and future is not a good idea you can write this in scala i mean you can write this in any language right and it's actually pretty easy to write this you just you don't want to do that um and so that generalizes and i think as a skyla community that's really where we are we're figuring out now that we've kind of figured out all the stuff you can do you need to figure out what you should be doing and that's much harder uh and i'm very grateful for people working on on things like the style guides and and giving talks about experience in companies and in bigger code bases those are the things that you should be paying attention to not me because i'm just going to show you my new toys but there are a couple of cool things we're doing in this area with futures that you know with four comprehensions and so on they're pretty nice to write asynchronous code and just do a bunch of arrest calls and not worry too much about the the network and so on um but it's still a little tedious so we've been working on scala async who's heard of scala async okay the rest of you check it out it's going to be it's a really cool macro based library for doing asynchronous computation it's a lot like what the c sharp guys are doing but nicer of course where instead of writing those that for comprehension and kind of writing your code monadic style you just write a direct style and under the hood the macro will rewrite your direct style code into magnetic code do the transformations into a nf and so on and all you have to do is say this is a bunch of async stuff um here's where i wait on my results it's not blocking it's just showing that you're coming out of the out of the async monad um it's just saying i need this result instead of just composing futures essentially i don't really want to go too deeply into this but i if you're doing async stuff check it out uh we're getting very close to first release there i think it's very exciting and it's another example of macros being used under the hood and again i mean i i i don't have anything against that as long as you're willing to keep up with the api changes and we are because we're doing it um so another thing here is that the await thing is kind of like give telling you the difference between future of t and t and this is a nice thing nice example where types actually help with with i don't know operational knowledge or something like it's important to know when something is a future of t and when it's t for obvious reasons i'm sure i don't need to explain that to you so um as i said we're aware that there are a lot of bad parts and i'm hoping really you know if someone wants to write scala the good parts we're there to help you out and proofread a review i don't really have time for that but i think it would be a great book um in the meantime we've been trying to give you some of the tools with uh sip 18 where you can say i don't want you to be able to define implicit conversions or i don't want you to use post fix or higher kinds i every time i see that that hurts me of course but i implemented that a while ago but hey it's all good if you don't want to use it don't use it um so and these things evolve so this is our first stab at giving you a handle on on the complexity that's there admittedly but it's complexity because there's just a lot of stuff and it's complexity that's there for a good reason when it comes to certain problem domains it's just not always something you would want to use um and so here's a quick overview so for example reflective calls is very useful when you write structural types you might not know that you actually get reflective calls under the hood because that's how we have to implement it on the jvm uh for now anyway you know you might want to not have to deal with existentials or higher kinds or dynamics or macros so these are all things that become explicit in your code base where you're using them except if you just do import language underscore which in which case you'll get everything so one of those things you have to import is dynamic it gives you a little bit of ruby in in scala i would say and any uh class that extends dynamic will accept any method calls that you throw at it basically and we'll reroute them to message not understood if you from or what's yeah message understood if you're from small talk i don't know what it's called i know any of those other real languages but we call it apply dynamic uh because i don't know why actually it's just less scary name so you know i'm not that inspired and i don't think i'm gonna so man i have to import this or what think twice when you see this so okay fine let's import it oh sorry got out of the editor there you go so um obviously the the apply dynamic method got called when i wrote this method here that obviously isn't there in that class it can be really nice when you're implementing dsls or when you're dealing with data that's you know too dynamic to bother when you're experimenting with with a rest api and some json data or whatever i think there are a lot of cool applications for this and you could use macros on top of that your applied dynamic method could be a macro that does actually check whether it's there or not if you're doing some kind of database access or something like that um or you could you know write a type save dictionary um where you know paul hacked something together where you just write in all the reading all the words and you call some method and it'll tell you oh it's in there uh unsafely or safely i'll just give you the link to the gist because i don't think i have time to go into it but this is how um you could say well bippy is not a word well it kind of is now it's gala land but it's not one i'll wrap up in a second thank you it's not at least according to whatever dictionary you use i don't remember which one if you can write real fast write down that number um and check it out or ask me after uh or you know check my github whatever we prefer um so quickly about scala 211 uh we've been hard at work on a lot of just dealing with technical depth uh that we've accumulated over the last decade and kind of like depresses me every time i said decade um but so we've been working on on modularizing the standard library and the thing i'm most excited about is that we've ripped out scala xml the compiler is the same way that string interpolation four comprehensions and so on are just a bunch of you know they just translate four comprehensions or string interpolation into a bunch of method calls it doesn't care what's underneath same thing with scala xml so you can plug in your own jar skull xml is now a jar if you don't load it you can't use xml literals when you're compiling but if you're not using xml libraries you don't need it on your class path if you do want to use xml literals and you have you happen to have some other jar and we won't ask any questions where it came from but it implements the same methods as the scala xml jar you can just use that um we're hoping to find some time to actually spec this but um we're kind of also waiting for you guys we're kind of waiting it out to see if anybody's interested in doing that but we're happy to work with you if you want to um no i mean like there i think there's still too many people who are using it it's more a way of you know acknowledging the the reality that not everybody wants to you have to use this or have to have this on their class path uh especially for resource contra constrained environments uh and we've over the years people have asked us about you know how can i plug in my own xml library so it'll be there we're we're fixing bugs in it but it'll be in its own github repository and it'll be pulled in just like any other module that'll that'll come so just a couple more slides left so another theme in 211 it's faster and uh greg who's into here today is working on incremental compiler because that's really our main hope for giving you guys faster compile times but we also have people for who are working on the more long-haul uh or long-term solution with a better optimizer and better cogen epfl that's miguel and type safe does james irie and of course we're working on stabilizing these things i was i was telling you to stay away from macros and reflection and i think in 211 when it comes to uh using macros i would recommend using so-called black box macros anything else experimental um but we're working on on maturing it we want we really want to give you a nice reflection or macro api but we won't call it official until we're comfortable with that all right thank you very much for your agreement your disagreement and i think we have a couple minutes for questions but feel free to change rooms if you want to attend the next talk in a different room