Play Video

ScalaUA Conference // A field guide to DSL Design, Tomer Gabel, Wix.com

ScalaUA Conference // Event Sourcing, Daniel Coldham, Wix.com, Israel [EN]

Presentation: http://www.slideshare.net/DanielColdham/event-sourcing-quick-introduction
http://www.ScalaUA.com
http://business.facebook.com/ScalaUA
http://www.facebook.com/groups/Scala.UA
http://vk.com/ScalaUA
ScalaUA Conference // Event Sourcing, Daniel Coldham, Wix.com, Israel [EN]

Presentation: http://www.slideshare.net/DanielColdham/event-sourcing-quick-introduction
http://www.ScalaUA.com
http://business.facebook.com/ScalaUA
http://www.facebook.com/groups/Scala.UA
http://vk.com/ScalaUA
https://www.youtube.com/channel/UC_ZJvRHot6thpgqsXvtEvFg/videos?shelf_id=0&sort=dd&view=0

hi my name is Donatello I work for which Israel web boxes in the label clubs in Ukraine and you’re saying we want to give so if you like or something a totally different something that they thought I want to apologize in advance I usually get this rock drum but there’s no beer the conference I’m going to have to go sober none of it makes sense and knock knock so sorry you know it is what it is so let me just get away from the things you can
actually see and I just want to set the stage all but how many of you have you know know what your cells are the traffic yeah pretty much everyone not much of a surprise it tell me if you have implemented or ringing yourselves in the past mom five people that’s five more than I expected cool okay so just a quick overview of what yourselves are and we can get to meet up things so do yourselves a dsl stands for a the ranges of language so as the
name implies it is the language designed to deal with application domain now why is that a good thing is because once you have a very specific application domain you can design the language to match that to me you need for assumptions right you can assume that if you’re writing a dsl that deals with you know building Jason objects that is what your users want to do so you don’t like to worry about anything else so this gives you a lot of kind of
freedom to design a language that is more expressive or concise a lot more you know correct by design or more readable there are various various advantages you can get if you reduce your attachments right so sell is the general purpose language you can do pretty much it but it doesn’t mean that the code that you write it’s readable if you saw abolish as a presentation about macros are there showed how to build a jason serializers with way Jason
it looks like he’ll write because it’s your stuff you don’t want do that want to work with the language fits your domain as precisely as possible because burns managers today so dsl’s generally can be classified in front of categories you have external dsl’s that are not post language right these are actually designer languages built with specific tools you need your your lexical analyzer your parser you need an HP for down right it’s it’s this
whole shebang of external cooling you’re on language and there’s an explicit lifecycle if you work with an external SL then you need to actually create a parser Regan get back some sort of data structure that you work with and then eventually disposal right to the life cycle is very very explicit you as developers work with a tool to force some sort of you know Stern language we did in examples of that include things like sequel right so if you
have if you use my sequel or anything of the sort you know you built your a simple statements you feed them into database engine the database engine reads them in and you know execute whatever execution planet actually parse out of your sequel so that’s an example other examples include markdown which probably everyone’s truce familiar with that’s also kind of music I’m good and sorry about that actually I had a third example that it was a stupid
one so i removed it so thank the other category is internal yourselves and that’s what we’re going to be focusing on today an internal via cell is a domain-specific language that is designed within a host language right so in the context of scala and i will show examples of that if you write your tests what specs to our Scout this you get sort of an extended language right you get you can send X that is designed for testing for making assertions
but it is stuff and it’s built in the top and stuff so the journal yourselves don’t live in a host I would just call in our case it does not have explicit fully everything is you know everything can you introduce all must be valid skeletal by definition you cannot add syntax that that is not stop right anything that your dsl provides must be fully understandable by the provider and the life cycle is implicit because if you’re right code you can
ask allah dsl it gets compiled belong to your program don’t have you know code that says okay here’s where i read in coding this dimensions of platinum right it just gets compatible on Konerko so you do not have control over life cycle on the bright side you don’t have to knock new tools you know everything is a lot more semper you know it’s a very different flavor of language design so examples of that include as i mentioned forced out of this
or specs to say integrity is a good example to yourself this shouldn’t keyword it’s not cute right it’s a mythical and it does not exist and stop that the string class and scala does not have a ship method so that’s an extension doesn’t make specific language of design force out this provides same thing would you know should be for the various various nice beads that you get about this or 60 so another example might include if any of you work
with Schelotto or spray for HTTP request writing you didn’t be right your requests in animations of the climate’s design for that third example they’ll be engaging hd’s right for this is valid scott code but it does pretty look like stuff right this is arrow thing that the big reduces of people does not produce adjacent feel so there’s a whole lot of you know there’s a whole mechanism under the hood that’s designed to give you the illusion that
driving with the main source of language worsens back its valid spell code should be empty and the collection is not empty when evaluating that particular line of code an exception gets thrown just eager me about going right the language that you can describe the test gets evaluated on the fly it does not you know it condition fits right the result of a shallow we invented dsl to effect which in the case of specs there might be turning except if
you use immutable spec you have to find some way to compose the results of these various assertions and that the result would not be infected to be something else that whole covering second i prefer the term imperative dsl’s imperative because you give commands to your compile write an expression and shoveling but at the SL is nap whereas an expression going to deepen bit ly a cell like split for instance is something different that will lead to
defining say examples of that hugging three masks right if have any of you use adds to the best yeah plenty of claim right because i used to be standard built or for java file a day so your antics ml gets free gets written by the Gant runner and little bits of it get executed on the squad doesn’t read your whole description and photos figure out an execution plan know it just read zip line by line and execute a shell script might also be
considered to be a shallow being fitted itself if you implemented within a different language sir chimes you know just the search require everything that we know from scala or also sort of a shuttle mean but it yourself because things get evaluated as they have an exceptions get thrown as they have adversely people in that yourself are pure lazy these are languages that are designed not to produce the fence but to produce kind of execution plans
that you later feed into some sort of execution engine right so firstly for instance which i think might be one of the examples will firstly you would say something like you know here is my users day hole and i take Matt one of the fields oh right that does not actually do anything it generates a description that you can later feed into slick for query evaluation for updates or four different but there is no effect to actually saying table dot
matt underscore top field instead so the results an execution plan that you that is a prescription you prescribe a bit of behavior to subsequent logic right so the expressions in themselves are fewer or leads to be evaluated this is a very fundamental difference now why would you choose one or the other well obviously the plans on the context but also there is a question of complexity so deep a minute these cells are more powerful you can do more
things with them if what you get is an execution plan and nothing fit you can take these plans compose them together do things like optimization or or you know for instance with the Java screams Java screams aah screams is one example but you give a DSL hypothetically you can take all the operations on a stream everything that happens before your collect right same thing with using stop and you can fuse them to something that is more efficient if
you have a filter and a map you could use flat now instead and do it in one step instead of two and so there are various advantages pleasing and deeply embedded yourself but there are more complex but you need some sort of result model if if the result of an expression is an execution plan you need some domain model needs and classes to represent that execution plan and then you need to write logical actually execute that execution but gets it’s
a lot more complicated setup so it really depends on the level of complexity that you need and the complexity of your domain what it is you’re actually trying to achieve for simplicity’s sake as you know we have roughly 50 minutes we’re gonna use an example that is shuttling a little because it’s just that much easier showcase so any questions so far before we actually dive into how to go enemies and stuff okay are you worried 40 if you’re not
worrying you will be if you’re not bored I’m sorry like I said I’m silver okay so when you’re designing the main source of language in style read in any case the first thing that you need to know is milder to me but you need to figure out what it is you’re trying to achieve and you know the first thing you need to figure out is water too what are the various kind of actors athlete like you’re describing your building a language you’re describing
something what are the things that are involved right what are the actors what actions do they think right if you’re running the matrix of language that queries database right you’re think amending sequel basically your actors might be I as a user I’m not gonna trying to execute the statement a table might be an actor they’re very you know very moving pieces thank you need that need to figure out what they are so you have your actors you have
your actions so the things that the actors and come to do you have objects that the actions operate over and you have some desirable consequences of that operation so once again for the sequel example the consequence would be a query running on the database and data coming back results of coming back to you or it could be an update right so it’s very contextual so let’s let’s use what will track this entire presentation will track one example
which is bigga assertion or data validation they’re very simple to yourself or validate data objects so in this example you know you really have one actor and that is the user right I’m a programmer I’m writing my cell phone they have to see a case glass or a bit of Vega that I want about it right so really there is only one afternoon one action I’m the actor and the action is spelled a disability and the objects if you have a place are you know
basically an assertion right if I’m trying to validate that list is not empty then the list is an object and the assumption that the list is not increase also object and the consequence that I want for this example is I want an assertion exception to be thrown if that assumption is not cool so this is an actor the colors and actor data an assumption or objects so we need to provide a language which it’s easy to define these assumptions an
assertion is the action that I’m trying to actually or facts straight the accident I can form an exception may or may not be thrilled that is the consequence of the sash we also need to know your users right if you’re building a domain-specific language you’re designing a language people are going to want to use that language hopefully if you want people to use your language you need to know who they are need to know what they’re trying to
achieve right so you have your users you’re either represents some actor in your releases of language they have a desirable consequence what you’re doing is you’re designing a language that makes it easy for your users to express their desire to express whatever it is we’re trying to achieve in a way that is optimal for your domain so far assertions there’s only one after there’s only one constant last right I’m asserting on that a piece of data
matches the assumption that i have a shape the consequences of exception gets thrown so it’s a very easy you skate to do to showcase but the question the real question is if I’m providing surgery the item I users what is the best way for my users to express what it is that they want right I have a listen I want to make sure that the list is not empty what is the best syntax for my user to actually perform them to actually express that in a
language welven level stop well the easiest ways to start with the users perspective right I’m a programmer i’m using this validation library I have a piece of data I have you know I want to make this assertion on the shape of the data so really I need things I need to provide away from a user to define assumption right and you can provide language to say something like not empty that is a language feature and I need to have a very concise index
or making assertions so let’s see what that Oh before we see what that might look there’s also the question of cabinet but every night when it is built of words or tokens these words have semantics that mean so we have our knowledge that describe objects we have adjectives that qualify objects we have verbs and adverbs and all that stuff right it’s easy to think of a programming language that the main specific language is being something
completely separate from English or Ukrainian or Russian or any-any really spoken language but in effect it deals with the same things it deals with the transfer of information in a very precise and concise way that is to express things as precisely as possible with as little as little information as long words little letters as possible while still making sense so for example insertion is a sentence they have the sentence lifted should be empty
this is English right ideally I want for myself codes to look like all English what Atlanta threat but they spoken in law understood human language that is the ideal so we have this sentence with Jimmy and me listen the object that I’m trying to assert on that sanam should be is the faction right this should be something that is the verb and empty is the qualify description of what it is of trying to go cheap and that is an adjective so how do we
start implementing this stuff and stuff first we need to figure out where the accurate this I’ve mentioned before you need to identify your actors in your actors perform actions and there is no factor in the sentence because the actor isn’t block right for this particular the main data assertions the videos is only one after program so you don’t believe that as part of your language we might have a whole bunch of the right this is the vocabulary
for our data validation language we have certain assumptions that need to make something like you know empty emptiness for a collection or list or a map we have no ability you have true false for billions left right for either define completed for future is whatever there is a whole stack of descriptive words that I can use that that match the objects in my domain language and also it might have grabbed dress dysfunction so if I want to say a
string starts with another strain or ends with or matches regular expression these are parametrized assumptions so these are the words that make up my domain language and once I’ve written off is done I have a good idea of who my actors are what actions they want what consequences they want a basic notion of what the sentence structure is for my language I can start seriously think about how to implement it on top of the host language and this is
what we actually get to describe how these things work and stop so the second step is no your language and by your language of this case and we know you’re gross language know the features that the host language provides that allow you to actually implement yourselves and Scala is quite unusual in that it’s a statically typed language but it’s also very rich features you know it has a lot of features that enable you to extend the syntax of the
language with the amazing Civic considerations so tools of the trade right the toolbox that scholar get it starts off with infants and envision in terms of notation is also often called doc freedom fishing stuff and you’ve probably run into this right it’s your ability to take this method call this one parameter method call flow is called meriting one any method calls where we have an object it hasn’t you invoke that method with a simple
parameter you can install off right with no dots and o brady’s right this is infection attention these two symptoms as if you will install are completely equivalent as far as the compiler speech and this is the first step towards allowing natural syntax natural yourself because if you do not have this your hip cells look kind of like cloned yourselves a new job and lend a salsa Johnny don’t really look like natural language it just looks like a
nonce way of building stuff right and we want an actual language this is the first thing that stuff gives us that really makes it possible to design yourself but as we’ve everything dark cap yachts right it’s not perfect there are things you need to know about how to operate so that you don’t paint yourself into a corner training right infant sanitation is very confusing to stop the Bofors just starting their there and for a sub because the
message should be empty will not actually do what you think it does you have your object which is listening to have your method which is should and you would expect the empty to be the proud but in practice style is very very very little so we expect be happy to be the forever but actually the compiler forces to go and the prouder is in fact beep right it just it is very literal it looks up the next open and that is a private it does not try to
reason about you know language instructions and whether or not this is emeka fault no it just takes the third dug in and treats it as the kragle so you have to be little bit careful what is you know what is the type of beat I don’t know you probably didn’t even define about Heidi’s probably a method in your dsl right it might have a function but whatever the type is it is not what you meant right what you meant is for me to be the parameter but
fellas you know just goes on you know says okay just the filth in right the treats busier cracker that is not what you intended so you need to be a little bit careful how do you you know what can you do about it have you important on it so the first thing you can do is you can contract that if you work with I think I think stop this actually have this for should be one word one minute you know this is a method name right and that is why as simple
as that you know should be just becomes a dessert that is one word for Arnold it you can match a second workaround is to burn fat I think that it expects to does you know different choices once you have this be because there’s your emphasis here B is treated as a method call by the compiler and then it takes the value of this method coffee treat status of traffic so that is also a valid way to work around this issue there is no right answer right
a lot of times you might ask you know which is better there is no better right the ideal solution would be to not have to worry about it and have a compiler to figure out that mate english young must get rather but it can do it Tyler’s are you know they’re not stupid but they’re very very straightforward right so it does not reason about your language so really pick one there is no right answer it so it’s an aesthetic choice it’s a judging at all
which one do you like better you like the season you like weird words that are actually toward to encounter base come on also a second problem with with the infix notation also run change so you have the same symptoms list should be empty you have your object you have your method and then you have your parameter and then this gets evaluated into a result right this is the resulting object from this from this a fixed location method now you have
an object and you haven’t heard yeah guess what you do not have you do not have a grammar right so that is often surprising people just coming into scallop for the first time where they see something like you know weird error messages that don’t seem to have anything to do with what you actually intended and that is why once again it’s a very very literal-minded very straightforward compilation process the compiler does not know what you’re next
it only knows what you wrote so if you do not have a parameter obviously you’re going to get the compilation error right so what this actually means in practice is for chaining to make sense for a fix of the patient a week since you have an odd number of marks to your sentence you can have three words 5 7 11 however but it needs to be odna you can’t have an even number of parts policy is something called post fix an addiction which is deprecated
from Stella and I think and you should write it it causes a whole bunch of our communities there is a reason why the compiler will warn you unless you explicitly say that I want to use post exotics just don’t leave it but use an odd number of words in a sentence any questions on this moving on the next the next piece of the puzzle and its feature that style gives you two are complicit classes so listen flex is really a union entry point if you’re
useful so in our example we have you know safe respects that we had strange not be empty sure is not a member of string you need to add it just rating after the fact that is an extension method lessee sure its value to this through illicit plastic the extended time is it make specific plans in your language so for data validation because we want our language to be able to basically violate any data type we would use a generic question right we
don’t know what it is we’re extending we want to add a shift method to anything right to ATM so let’s check the empty list it’s known ahead of time right this is the only thing really that that we know how to find on our users are kind of a big deal should be at the extension of it so need to have a class that adds this also one more new space for illicit classes which will cover that when betta later is lift about unity don’t worry about it i’m
going to show that very very explicitly a few slides right the printing your whistle class is your entry point because the only way to actually start a sentence and your jamaican language is what I dedicated it is known that does not have this should be or shouldn’t the verb so let’s start putting it together and this is where we actually start ethylene code on screen I hope everything will all make sense great we established an assertion if
symptoms in the symptoms of the shape some piece of data should be some credit right a strange trip start with a list should be and that is our sentence structure the first thing to do is we need to have some sort of definition of what a predicate is right we make it into the trays I don’t know I hope this is readable from the back I’m sorry this is a red coat for a slightly more contrasting addiction so just read it off we have a trade called
pregnant it has two methods one method is called test takes in a bit of data and turns opinion right it’s generic conclusion that a predicate can operate over some certain type deep and it can test that that the prediction holes right so if i say let’s simply team this case would be a list of some string integers it’s entertaining and i have failure message because you know the compiler can guess what the frigate does so the person implementing
the predicate must provide a figure that’s really an entry points which are you saw so the only thing that we actually know ahead of time is data so need to extend that that the type of that piece of data to actually support our dsl well that was a class called context it operates its generic it operates over any arbitrary type T and as this should be method that takes a predicate of team but that’s when a patient is not the point right the first
thing we need to have is we actually need to have that every point of yourself together listen class and then because as I said before it’s a lot simpler to implement shallowly embedded yourself what is the consequence of a failed data validation for this example an exception for simplicity sake let’s or say that if any piece of data fails to validate you thrown except site mr. assertion failure has cost consequence that consequence is an
exception e throwing them around ation is actually pretty obvious right whatever the busa plasma cover should be method we require this is a scallop standard library if you haven’t run into this am I surprised but it’s missing the insertion method that also to suffer enough right so it requires that the predicate can successfully test the data and if not then it just outputs a string throws an exception with a string value leah is some sort of
failure message derived from the practice so this is a pretty imprinted implementation that just throws an exception so we can start implementing predators right you have our extension like that we have this concept that the predicate can actually implement the cranium so let’s say our sentence we want to implement an emptiness predicate for this Sunday’s should be in an invalid ation would be you know fairly fairly obvious not in target your
military on this we have here an empty method that takes a parameter t t must be some iterable like a new sequence or register now it needs to be a collection at least literal and the predicate the test is really simple I take my piece of data that I know to be a literal I just asked is empty and the messages based on this is a very trivial one patient so far so far it’s pretty basic so are there any questions before we get to the nasty bits okay
up until now this is pretty incredible if you run into if you run into endless classes or you’ve implemented extension methods of C sharp or any other language sports it this is where you know you given like half not sure about that given half an hour of work you want to do in a variety at this point and everything with my niece this work things get nasty because Scott is not accurate of language and there are all sorts of things that you need to
take into consideration and all sorts of corner pieces that you need to handle in your yourself this is why the ax cells are actually not that easy to implement in any language and install if you look at the source that respects you or Southwest or anything that provides it yourself it’s not I’m you know scared sometimes so now things get here let’s let’s consider various corner cases that we might not eat you but ends one have three times four
is bigger than them that’s a boolean value should be true the problem is that book ends the values for remains true and false are reserved keywords and stuff right there not values for actual keywords you cannot you cannot provide a diff right you cannot provide a method with the same name you cannot provide an optical signal really you cannot define anything that has named true or false in stock because you will get a composite one you can do
that with back tix like you can he can rap trimbak Tex but then you also have to use tactics whenever you actually use your he s else that is not reducible you know rhetorical question can we support the sin tax you know despite the fact that with the these keywords are reserved can we actually find a way to implement or DSL that will support this particular syntax obviously the answer is yes only a single time one solution to that is to lift
boolean values to our domain model what I need like that we have our listen class boolean predicate that fixing a boolean value actually provides a predicate over that right that is that is the way you go like you have your should be method and signature we’re asking for a predicate and what we’re basically providing here is an implicit conversion from bullion to accredited with pudding and implementation is pretty pretty simple we have our best
method and it just checks that the value we got is equal to the value that is expected then we have a regular message that is an easy workaround right it’s not trivial in that you need to think about it and you can be careful in your design that we deal with these corner faces but the solution so that is the first thing we need to do not a big deal but then we have knowledge right we have some string and we want to say that some piece of data
should be or should not be enough right the problem with now is that null is itself but the reserve keyword and a value so you also cannot use this and mountains up there more importantly though you think of the solution of implicitly lifting knowledge or the main level of work except not so much and the reason is that this this is the signature for should be that we started off should be it sets predicate over some type t know in Scala the
bottom touch so any reference any any reference type by definition is a super type of not right so if you say should be now now is actually a valid value for this birth predicate cravath so there actually is not going to be an implicit search and it was search will not take place because comprehending for true and false are not of type a-negative deep so the compiler tries to find an aggressive conversion is natural but now is a credibility it’s
an ultra 50 so notice it sir same place so we need to once again and find a horrible horrible workaround to support it unfortunately the only workaround that I’m aware of is providing an open book basically you provide a second version should be that deals specifically would not and here there is a bit of a hitch I data validation in operating over a thing that can operate over engineers or lists over the main objects now the definition only
applies to Earth in size so you want to if someone says why should be not want to get a competitor because probably the submission to not knowledge integer but it’s a valium life so what we do is a little bit of factory what we’re saying is we have our should be overloaded the takes and end of titanal but only technology not only fun but if only ever has one value and that value is called now right and we’re asking the environment to provide
evidence to us that our type T is a subsidiary right right if you’ve never run into this pattern for my team very very confusing but the way to read this is this method can only call if the compiler can prove to this method that whatever type t is is a reference type because because it is a subtype of Sigma take the syntax is a bit wonky it can be explained it’s not that hard but that is not a long as you need to have this otherwise your dsl is
not sound and then we require the data is now otherwise because this is shouldn’t now and we provide the error message any questions on this yes you just might make it should be extent a and for this our candidates like empty like around men and everything but hopefully here extent by plane train or baby and like there should be message we just too much reach your chest for self image and it is a pretty big thing we just do it or need to do with
the predicate it is not not already game it is perfectly in the foreign inside view we don’t have anything to do this not so I’m trying to understand are you asking can we can we eat a check up on time or can we provide some syntactic contract that resolves two different methods for these different use cases is it a predicate is about you by yourself no estas Paco so you know yes so you’re asking about my money dispatch questions can be used
counter matching and deal with those dancers yes but there have been problems first fun matching happens a part time and we want to have as much from palatine safety as possible the whole idea in designing that the nexus of language is to add 15 and sometimes performance redeveloping you know various very strong knees doing tests a frontline first of all it’s not a good solution because you don’t get to compile time safety that would with this
word solution and second it’s perfect hit right because you know what if you forgot base you get a matter that is not soft right and also like does not perform as well because your solution happens at runtime so fkin problems that you could it’s not an ideal solution any other questions so far okay moving on so this is this is a bit wonky but you know it works what about parametrize credits right we have three times for should be equal to 12
right this is our sentence structure this is what we give you was like well there’s two problems here first off the quality predicate you know just the second stage is pretty simple diagram i right we have our equal to method taking a fat gramma turkey on the right hand side that’s on our chest ask for right hand side of type T and we just in front of the predicate for the test notice that that’s for quality generates a pro-business easy enough
but we have an even number of parts in our sentence once again we drop the odd rule be out in under large hole right so what can we do about it oh not much the only the only solution that I’m aware out of service right click on for should be equal to 12 now there might be some other way to solve this not one that I’m running every single library that ever gives you a DSL has this issue in fact I think Salafist has a specific section is
documentation title what’s up with all these parentheses this is what’s up right there is no way around that you just need to add parentheses in your you know if you don’t like the way that looks oh that’s too bad you need to that there is one more consideration we have just a bunch of examples he writes tell you a you shouldn’t start with stop so they should make this 13 should continue to five should be greater than two there is a subtle
difference between the few of these options so thanks rod it’s not really that pretty great let me clue you in well here should and should be right that is because we’re trying to mimic English and we’re trying to have our services make sense so actually we have to predict families and I’m sorry for the technical language description you know that’s what wikipedia says we have simple mobile form to list 1 2 3 should contain two and then you have
something called compound subjunctive form I don’t know what the hell that means that that is what wikipedia says is the right name for this type of like three times for should be equal to 12 right so we have to do families for Fred we have fun when we have crickets that require me and kritika stuff do not so how do we know the swallows you know semana we have another perp so we take our validation context class we refactor that the actual test
an exception throwing fits oh you told me method that is private but then we have two methods should be and that both they can break it then we’re big ego and it’s like this us and the reason that the sucks is because a lot of good things like this one two three should be contained two which is not English now I want two choices you can build a laser out and say well you know if I use your boss right thinker finish that time or you can go deep
anal retentive crowd which is always a further out as far as I’m concerned and find a way to deal with let’s find a way to not to diss allow this type of sentence well one way of doing this is you know to find a way to differentiate between these two predicate families so we take our Bass Strait try to get a deep we extend it with local predicate or compound predicate and you’ll notice we’re not adding new features or anything we’re just
classifying credibility to use you up two separate families next we need to modify verbs accordingly so you share the things in the world reddiquette should be takes it at the proper etiquette pretty simple but one for specific we don’t want anyone to be here to generate interest of a predicate we no longer have an action the sugar or should be that deals with credits we just have those two types little or compound so we make the predicate of the
bass strait seal we move it to separate separate population unit no one can extend it and no one can actually use your instantiate credibility nice honest finally we need to go through all four different predicates and you know plus 50 simple enough now we have a sensible sentence structure good honest last thing we have negation the not a / right which so far ignored but the game it’s not just about symptoms you expect to get a different message
but if a list 1 2 3 should not contain three then you expect to get a different message for a blip one should contain five right these are different earrings so a predicate that the base trade right technically should support negation and need to extend it to provide us also a negative failure message we need to extend them all so the first game unfortunately we need to do is decide what is the ground right what is it what is this going to look
like from a user language perspective we have two categories and you have number options right we could go with the Moodle type of works with ability programmers should not start the job or we could go with rumors should not wrapping start with Java right we have these two options means big for compound we can have with level three you should not be empty or this one two three should be not empty this one’s a free should not be in it all these
are valid options there is no right choice right some of them might give a little bit weird but it’s an aesthetic choice you know all these are reasonably valid sentences and kind of English all right so you can use either want an unique you pick once again no right choice it’s an aesthetic variance so for simplicity sake i went with programmers should not what God awesome not is effectively a function that he gates credit and then we have should
be not them right Mike little bit weird but it’s a lot easier to implement so that’s one again shows right what do we need to do we have our predicate teeth that we need to extend right it’s no longer just to fit it provides a failure and it provides a negative visions now if you tried working with variance annotations and so on this might look a little bit familiar a happy way because what I need to do is for each I want to be able to define a
general negation method but the result of that negation would not be a predicate teeth because we still have our two families forever compound predicate SAR modal surface and we need to maintain that pack information right so you need to be a bit of types of some hackery to figure out how to do that so we each type of credit defines a self type that is a bit of theme and then the gate function that returns the salsa and this is just a pipe Elias
it’s cut listen I know and sometimes it’s a little bit hard to understand but fortunately only have to do it once for bass critics so how the implementation look right you know you have your negative message you have your generic gregation function implementing it just as an example for the mobile predicate would be you know to self buy is once again a mobile predicate you know if we’re taking a little reddiquette and we’re getting it we still
expect to get that little credit and the vision is pretty easy we just generate any one we invert the best right we’re starting off with a with some predicate and call itself we run the test and we just put in the case that the value of it and then we switch the messages around so the failure for de- predicate is the negative message whereas the negative message for dedicated predicate becomes original right we just improve it and that way we now
have a generic thing that can basically negate any predicate that gives us a negative fingerless and once again if you take a look at how Scala test or respects to deal with negation this is exactly how it stuck he’ll love you interpretation details finally we need to add our and this is my final slide we need to add the NOx modifier advert to have function not operating over sometime around your teeth takes an accredited team returns this called
the pin the myth of types you can actually do that installer if you haven’t John pretty the fries around like the jumping is chairman joining up because he realized this feature it returns the self type of the predicate so if it’s a local in terms of local with its compounded returns compound and it just calls the gate and this is part of our via soma and once we have those parts in place voila this one two three should be not empty urban race
should not start with job alternately i was wondering if i should do basically your java but i figured it might be Ruby programmers and basically he’s pecans Joe thanks so this this works and this is you know pretty much it the next step in your dsl design is to sit back have a cigar or grin severe and very profits which you’re probably not going to because it smells like an open source operating here you’re not getting paid for it they’re not
right so this has been a lot of stuff we unfortunately do not believe I think have time for questions yeah I need to stop like a minute if you have any questions feel free to gluten from after the the top and ask there is laron obviously going to going to publish this slide deck on SlideShare there are code examples that you can have a love to have all the things we discussed implemented and it’s on github if you have any questions feel free to
contact me and that’s all we have thank you very much you