Devreal

So, You Want To Be Functional and Reacti...

Event: Scala by the Bay

scala.bythebay.io: Vladimir Bacvanski, So You Want To Be Functional and Reactive? Here is how...

Recording: scala.bythebay.io: Vladimir Bacvanski, So You Want To Be Functional and Reactive? Here is how...

I you alright so quick show of hands how many of you are skull enthusiasts all right how many of you would like to expand the use of scholar in your company almost everybody alright so a couple of words about who am i what am i doing I'm running a company that is doing custom development but we also do a lot of training and we create a custom training in Scala and other topics so we went through the whole range of various color topics and introducing them to organizations now usually when you have a scholar in the company there are a couple of champions who are really pushing it that they are very capable but then the question is how do you bring the rest of the organization to the same level and we typically see that we have a quite diverse student background so mostly they are Java developers but increasingly we see data developers who are coming with strongest sequel relational data by the background and they have fall in love with spark and they would like to apply that and suddenly they find themselves in a completely different world so one of the things when we are doing our training in companies is to make developers productive the first day after the training and this requires slightly different approach to training than you normally find in various tutorials so for the typical audience that we are dealing with we see that they are not the early adopters they are not people who would implement haskell compilers over the weekend and they are not fluent in closure and ochem oh and they don't have PhD in category theory well the people who are bringing in scowling companies often have at least some of these traits so when you're going into scaling scholar in the company you're more likely to find background java developers quite a long time ten years or so some exposure to other languages a little bit of functional programming and often in companies you would find them working as a medium or large projects on on the teams they have some curiosity about the new technology but they are not living for the technology so they have their regular lives and so when we are introducing Scala in organization we have a set of topics that we need to deal with one is introducing Scala is the new language and this part is easy you are introducing the syntax the language constructs the headaches start when you start introducing functional programming and you want this to be a very positive experience you want people to experience this as something beneficial and you know we have been in a similar situation a long time ago in the late 80s whether we had the object oriented development where we had the C++ come again we have been talking to developers they are telling us you know it is impossible to things in terms of objects you're not having data and functions together this is just completely unnatural a human cannot think that way and that now we are facing a similar situation people who have been raised with object orientation and now they're getting in the functional way of thinking and they have difficulties one of the big reasons why companies go to Scala is because they are hoping to get good scalability and concurrency and a synchronous programming are very important motivation motivators for that one of the problems is that people often have difficulties thinking in the terms of concurrency and we need to make this task easier acha another topic quite related we'll talk more about this and now these days we see that companies are embarking on micro services and for that we see great use of spray and increasing use of acha HTTP and completely separating that was kind of unexpected to us we see a large number of student audiences it is almost about a half is actually coming from the data background they're motivated with a spark we had a couple of teams that were using scouting and what is interesting these were people without real programming background there are people who tend to use a sequel and do the data analytics and they have realized that the code that they would write in Scala for etl would be just superior to using various other tools now one of the things that I feel is really important when you are doing this training you need to also cover frameworks or applications that are existing in a company you want people to be aware of their architecture design coding styles so when people go to their projects they can be productive in this environment so how should you do the training there are two major approaches a one approaches get an instructor and this is actually the approach that you recommend in the beginning when you are rolling out training two masses one thing that you always want to monitor your coming out with the new technology you need to monitor the student attitude you want to look for the potential problems you want to make sure that everybody gets it has a great experience with experiencing scholar you may find the developers who will come up with some amount of resistance and skepticism and you need to deal with those you need to prevent a bed feel spreading through the group one of the common problems that we see over and over again we have the scholar champions that are bringing in scholar in the organization's they are very fast we're very motivated when they get involved in planning the course they tend to crime too much stuff into the course and that often overwhelms the student and the important thing for a course like this is not to impress the students but to make them more productive and that means that you have to allow enough time for exercises and you want to create some groups where people can work together review each other work and here are some typical duration that we have found optimal for further training and then after that you follow up with resources for self learning now if you have a smaller team or a theme that is very enthusiastic about the new technology a self-paced training online works very well but you need to make sure that the things are at the right level so sometimes we have seen in some online courses that the problems are not so much about programming but about solving mathematical challenges in scholar syntax and may be fine for with typically backfires when you are rolling out two masses so we have seen lots of motivation students dropping out of the classes and you end up with negative sentiment in the company taking Scala is too complicated we cannot do that important thing particular if you go with self-paced training is that you have some support for group group learning and exchange in the organization ideally through some meetups groups or something like slack channel that you need to moderate and and make sure it is active so how are you going to start in bringing in people to scala so there are a couple of approaches one approach is a rather traditional approach when you start with small steps go through the basic syntax and then you cover objects and then eventually functional programming that approach may be a little bit boring and you will find people who are expecting great things from scala and then they end up in the class where they are learning very basic things so the better approach we found is when we dive in show various cool features first keep people impressed show them unique features of the language features that make them more productive and then go back and are on the details so one of the things that we have seen in in our approach is choosing examples for Scala is shorter where you get done more in less code is something that resonates very well case classes are usually the first thing that we show to people you know Java developers immediately fall in love when we show them the difference in the number of lines of code and after that we like to show collections various operations and that works really well for people corrugating into spark who are coming from the data background so then after we have impressed the people and show them some immediate benefits then turn around and go back to fundamentals so one thing that we often like to show is something like this so this is from the top tile comparison a couple of lines of Scala and in Java so focusing on productivity tends to work really well the other quick wins are concurrency particularly if you have Java developers that are working with concurrent programming show them Scala futures they would love it that works really well and big data the ability to have your code that you can show people operating with plain less than you do mapping and folding and then you switch to spark and connect to some data source and then you basically do the same but across the cluster so I'm very attractive thing as you are doing your training you need to create the impression that this is easy as much as possible it is not always possible to do it but there are a couple of anti-patterns so one is let's go to the scholar doc document ation and to review the type signatures of functions and then you show people something like this you know and then then they are in shock and they are saying people cannot really comprehend this language instead our rule number one when we are talking to developers about the libraries never show the signatures instead always go through examples and then I have students mimic the examples so we often skip a number of exotic language features and and leave them for later provide them online references the other thing that you should never do is you should never show five hierarchies you know this is for the list and first we impress people with the list you don't want to show them this and normally beginners have in their mind that the conceptual model there is something like any then there is a collection and there is a list as a subtype and that's it in fact it is it is a very rich model so don't show them this this will confuse them in the beginning now later when they want to approach the level of mastery of developing Scala you can tell them well this is actually right so Martin Radetzky is saying that is how it should be work hard to make things simple for your users so if you want to roll out to your own collection then you would actually benefit from something like this but don't show this to beginners now functional programming here are the typical topics that we are covering in the part of the course which deals with a functional programming so we start with recursion go from their tail recursion introduce some functional data structures go to folding and then we do some additional things now here is something quite interesting if you take a seasoned java developer and you ask them so when was the last time you use the recursion they will usually tell you oh it was ten years ago in the college and then now when we show them recursion they have difficulties thinking in this way which is very natural people without mathematical background people who were spending too much time to incorporate the development and the experience is very frustrating because they all think of themselves as a great experience developers who are productive you give them a very simple problem and they are suffering they just cannot do it with recursive way you need to manage that very carefully you need to allow for them to practice and in our training we have developed a whole range of exercises that go from very simple to more and more complex and we ask them to practice this and then whenever we are going with the functional solution we like to compare several ways of doing things so we show them first recursive solution tail recursive then we do folding and then eventually we do the for comprehension so the same problem always done in four ways recommendation is do not go to Mass heavy there are experienced developers when they deal with recursion they feel they need to show it off on some complex problems don't do that it may be too difficult for your audiences and then one thing that we really like to do and it resonates well is we always run a set of benchmarks so we are running the benchmarks for all of these four different solutions and we see what are the numbers and we make people aware that these abstractions are very powerful very productive but they come at price the question is does it matter for you for your application and as one optimization we have them to implement the solution in simple java like four loops if you need to squeeze out the performance you have that option and this is actually good because it can combat the effect that some people are saying well this is elegant in short but it is slow in execution you can always descend to the low level high-speed code if needed the other thing when we are doing recursion and visualizations sorry recursion and folding always visual things so rewriting we found to be very useful particularly in the beginning and that the other thing is always visualize the relationships especially things like folding operations of various data structures and our recommendation is don't do it as a pre can't diagram but to do it live in the class with your students so build such visualizations interactively going beyond functional programming so after people cover the basics of Scala they typically approach development of more complex systems and we have seen in our development in C++ and Java world that there are many developers who have difficulties reasoning about concurrency and in some organizations we have seen Scala RX + RX Java being used and many developers have difficulties on the other hand one thing that is very attractive what about actors we found that it is much easier to teach people to think in terms of actors and there is something that I like to call a on turf electric anthropocentric design or approach think about actors f as if they are people and if necessary you can do a little roleplay in the class where you have people playing the roles of different actors particularly the concept of supervision are explained well that in that approach when we are looking into actors in teaching acha we have found that visualizations are very useful you know and it is somewhat disappointed that most references and in books on these topics don't have extensive visualizations so what we like to do is create the diagrams in the class live with students where we are working together and we are representing and the interaction between the actors and messages and this is actually example from the class a diagram that we have drawn live with the students so that helps quite a bit then you collect those and share with the class its color for big data big big trend this was much more than we expected in smaller companies we often see these are developers they don't have much problem but in larger companies you see that the data department is moving from enterprise data warehouse to something like spark and you face developers with the relational database focus so you will find the additional problems beyond Scala it is not only the language but it is entirely different culture and you often need to introduce modern development practices like doing unit testing a continuous integration and so on so for sparks start with splain scholar list and then show various operations and then switch to spark connect to the data source and repeat the same thing and that works very well shift of cultures as I mentioned going from sequel to programming that is something that you will not be able to handle on your own you need to have a support for management and it is it is often a challenge in organizations so for big data the path that you want to follow start from the plane Scala collections demonstrate various business processing for example has have a collection of sales or accounts and then you do various business queries on this stream processing you really need to have a programmer for that the code tends to be too complicated the management of state is something that sequel developers will have a great difficulties now attitudes and preconceptions you need to actively manage that and we are not talking here about enthusiasts we are talking about the skeptics you need to work for them so you have those who are just uninformed you have the herd no one told us to use it the cynic this will probably not work then you will find that the burned I tried it and it did not work at the time crunch we don't have new time we don't have time for a new language and then the boss I don't care about these technologies just show me the bottom line and then you have the irrational it usually hidden as one of the other ones and there are there are a couple of good references in the book driving technical change so you may want to consult that so you fight that with first expertise you need to be passionate but you don't need to be crazy about it show don't tell synergy show some benefits in the larger context create the system organization really needs so make a change in the organization a play nicely with the rest of community so exposed to Java API and make your efforts known in the company so avoid the friction is my message ignore the hostile you cannot just win with them a target the willing this is where most of your efforts should go convert them into developers work with them apply the skills on the new project choose the project wisely don't something that don't use something that you will doom to fail microservices tend to work well because you can replace an existing implementation with a new one and then show the bottom line you know higher productivity less code seven habits of successful transitions so first class if are your students don't bring everybody into the same class so differentiate between enthusiasts regular adopters and skeptics prepare the training path for each of these groups monitor for attitude this is going to be one of your most important roles avoided the carry things focus on practical and productive techniques share the experiences and enthusiasm with the learners and the organization and then after the course don't let people language without using scholar but immediately start some project and have a mentor on the on the team before they get stuck you need to act and then you need to prepare the support after the training so various meetups online resources you want to curate them to man what is relevant to your systems and questions what misconceptions people in the course tend to walk out one of the common misconceptions that people face is that Scylla is too complex it is too difficult there are many people who come with this attitude and it depends on the training they may live with this attitude this is why I stressed it is really important to give people enough time and to create a progression where you will bring in this from the skeptic to the believer and there was one bullet of a showing the course should not be intended to impress the people but really I walk them slowly I think we're out here but I appreciate your talk and very informative you know you come up and ask questions on here to the side and I gotta get on way you're blind I'll be around so thank you very much [Applause] you