Venkat Subramaniam - The Art of Simplicity @ DevConf 2017

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
all right well thanks for being here it's a pleasure great pressure to talk to developers my name is Venkat Subramanyam I'm here to talk about one of the things we deal with every single day of our work which is this conflict between our desire to make things simple and how the world and house around us continuously seemed to get complex I was on a flight I travel a lot but on one of the flights I was next to a guy and he said what I do for a living I said I'm a programmer and immediately he said with the bright smile II said that's the easiest job on earth I said that's great to know somebody thinks like that but can you tell me why and he said well all you have to know is zeros and ones and I said now that's pretty cool and I said but do you know why they pay as the big price they paid I said why I said because only we know in what order to put them together and that's where the complexity really relies in how do we really work with the problems the domains and software's being used today in almost any form of human activity just it's absolutely phenomenal how much it touches our lives so how do we deal with all these things we do well in this room I would say there's probably one of the most complex things ever that is our human brain but if you look at the human brain it's pretty fascinating we would associate terms like creativity absolutely phenomenal ingenuity when it comes to human brain but the human brain also gets pretty tangled up with emotions we get confused we cannot see clearly solutions and then we kind of wake up and say duh why was this so hard this is kind of obvious we say hindsight is 20/20 there are times we struggle with problems for hours if not days and then when the solution comes up we are kind of surprised why it took us so much effort to really figure this out and all these complexities we got tangled into and the confusions that arise from it well I often talked with my children about shouting girl and shouting girls cat it really karaoke it keeps kids excited we talk about these stuff a lot of times the conversation would be one of my kids text me saying that's like a Schrodinger scat well Schrodinger once I've had a thought experiment he said if you put a cat into a into a box and you can't see through it again here and if there's a vial in the particular box at any given time he said a cat may be both alive or dead you know how do you really conceptualize some of these ideas things become really weird at some point but one of the things we have to constantly confront with is complexity in our daily lives of programming but Confucius said life is really simple but we insist on making it complicated that is so true though and and we deal with this every single day we want to take things and how do we really deal with complexity and how do you make things really simple but why are we really interested on insisting on making things really complex and so I like the Y question a lot I don't want to know why we do this and I'll tell you why we actually do this we do this because it really feels good when you make things complex isn't it because when you make things complex you feel like what you have done is important you feel there's credibility to what you do and if you do something that's really really simple you're worried that maybe people won't value it you go to a colleague and say look here's a design I created what do you think about it and your colleague looks at it and says yeah that's simple I understand you feel a little let down you say I'll come back tomorrow and you make it more complex probably or there's another benefit of making things really complex it gives us job security because when it comes time to lay off the company says what do you do don't touch Joe because nobody understands what he is doing so we tend to really have that cloud of these job security as well around us and and so there are a lot of you know reasons why we kind of get tempted to make things really complex but the problem really is you know Einstein really nailed it he said any intelligent fool can make things bigger more complex and more violent but it takes a touch of genius and courage to go in the opposite direction I want to outline the word that he said courage and and this is one of the things that I find more and more important is to have that real courage because when you're sitting in your meetings when you're sitting among your colleagues when you say something that's really simple we often get ready killed about it and to have that courage to say no I really want to think about this further because we don't need to deal with all that clutter and complexity and that really takes perseverance and courage to be able to stand up and say we want to really create something simple and that's one of the reasons why he really uses really brightly the word courage that's very important but the question is if simplicity was sitting next to you on a train would you even really recognize it would be even look around and say oh you are mr. simplicity aren't you would be able to be able to even recognize it and that is one of the challenges is when you work with people it's not very clear what simple really is I had an experience actually working here in Poland with the team and I was endlessly complaining that a piece of code was really complex and after several minutes of quietly putting up with me one of the developers finally said I don't get it you keep saying this code is complex but we all think it's simple and I said wow wait a minute you all think the code is simple but I'm thinking it's complex but tell me explain to me why you think it is simple and the gentleman said well all we have is a very simple for loop in this a very simple if statement in this code why are you so upset about it and that's what I realized that we don't understand what really simple means because that if statement was duplicated about 60 times in this function and every few days they would have to come and add more if conditions to this code and this was duplicated in several places increasing the complexity of the code so a lot of times we use the word simple but it is very difficult to define what it is here is an experiment you can really try in a nice way you can go to work and ask your colleagues hey what is simple I bet you you'll get as many answers as the number of people that you actually ask but nobody can really put it into really good words because simple is something we all kind of feel but we can't quiet gravitate towards and define it very easily so how do I go about defining what simple really is well I like I said it's really hard to define what simpleness so I'll take opposite attempt I'll try to explain what simple is not and maybe if we can understand what simple is not maybe we can avoid those and maybe with a good hope end up with what simple so I'll talk about what is not really simple how about that so I want to start with a few things that I believe are really not simple and we can avoid them the first and foremost simple is not clever now how many times how many of you have ever written clever code come on be honest yeah everybody here has done it some of us have the courage to raise the hand others are like too embarrassed to raise the hand right so we all write clever code why because we have pride in what we do we want to write something and stand up and say man wasn't that cool the way I wrote it well I remember experience not too far a lot far back in time client asked me to fix something and I looked at the problem and I said oh I could fix this in 10 minutes but oh no I don't want to fix this problem I want to fix the mother of all problems I want to fix problems like this the patterns a problem that could happen like this and so I spent an hour writing a very clever solution and in all honesty I felt so proud about it so proud that my body literally detached from me and came and hugged me because there was nobody in the room to celebrate this it felt that good and I went up and said this is awesome this is how problems should be solved you don't waste your time solving problems you solve meta problems well I check in the car I move on and then I get this email after a couple of weeks from the client something terrible has happened in production and I looked at what happened I said to them immediately oh don't worry about it I'll fix it right away and they said oh of course we know you will fix it because you have that good I said no no no I'm gonna fix it not because I'm good I'm gonna fix it because I'm the one who car and the problem has blown up in ways I had never ever thought about it was a lesson really a humbling experience to learn this and what did I do I reverted back all the change I put in and quietly did the 10 minutes of work that will work in the first place and I never heard anything back from them up with this problem and so these days when I look at a piece of code the minute I realize it is clever I delete it and I start over again because I want a solution that is clear to people what are the things to keep in mind is it is not how much time and effort I put in to write the code I always have to ask the question how much time and effort other people are gonna put in to maintain this code after I leave this code and a lot of times it could be myself six or seven months from now and if I'm not able to maintain the code I'm writing today I have created a lot more liability to the company then I would be worth it so we really want to reduce that quite a bit but when it comes to this here is an example of in Java if you look at job as enum literally this is what you're gonna look at it says public abstract class enum e extends enum e well that little noise you heard is your brain throwing an exception because you're like whoa what does that really mean and there are very few people in the world who actually understand this code and even them they need a quiet room you put them in a cone of silence they think very deeply and they figure this out do some work with it and they forget it so it is extremely complex and sure there were good reasons to do this but that's a representation of complexity right there you are seeing that can be really hard now when I go to companies a lot of times you know employers come to me and say you know how do I really office get the code my team is creating and I often tell them why do you need an efficient tool your employees are creating what I call a self office carrot code they themselves don't understand it after they write it so we don't really have to worry about it it becomes self office catered very quickly now you know programmers are very excitable because I know it I'm pretty excitable but sometimes we go a little overboard this is when I firmly believe every court anybody writes somebody else has to read it if we don't want it can become a disaster over time like this one dude who got really excited about it and has done this coding and I came across this and it says float in square root float X the first problem I have is I don't have a clue what X is but I got some good news for you whatever X is I have now half of it and then of course if you notice this is beautiful operations don't didn't you don't understand it you should be smart enough to know this right and then what happens if you say you don't understand it they put a little comment what is the comments say shifting and then of course it performs this beautiful operation and then and then there's something wonderful happens you received X on your returning X back again as an output now when you look at this code you're scratching your head and is saying what is happening here and and wine why me why I may have to look at this code and remember how people tell you object-oriented programming represents the real world you know what never trust people who say that because it never represent the real world it represents our abstraction of the real world but one dude ticket too seriously he was creating flight simulator and said this is great the code should represent my line of business and created that this is really crazy stuff isn't it now who is going to maintain this code over time not me definitely right so we could get excited certainly but this becomes a liability for us to leave when we start doing things like this so we got to be very careful how we create things so I said simple is not very clever another thing I want to emphasize very important because we get into this conversation a lot is that simple is not necessarily familiar we could confuse between the word familiar and the word simple now what is familiar familiar is something you have seen a lot of times and you don't care to see it again familiar is something that is something you are used to something you're calm but it is quite possible that something that's very familiar to us is actually pretty darn complex but because we are so used to it over time we have kind of gotten used to the pain and because we've gotten used to the pain we don't feel the pain anymore and then we tend to associate it incorrectly that what is familiar actually is simple and we have to be very careful about it when we define this actually so let's think about the word familiar familiar something you have seen a lot and you may not care to see it again what comes to my mind is usually my in-laws right yeah usually in Las or like that so you're kind of like oh very familiar but doesn't mean they're simple and so the point really is that you want to really ask whether it is really really simple let's talk about this anybody knows what this one is well we could look at this and say my gosh that's a complex set of symbols but people who speak the language don't think so in fact I kind of found out this actually means simple in fact it means uncomplicated casual and common how did I know it I use Google Translate for it of course but the point really is that it becomes really complex for people who don't understand it you know here's a beautiful country I've been to this country several times but I wouldn't say that I am familiar with a lot of things but it would be really foolish of me to make the claim that things are very complex because I am not familiar that only will reflect my ignorance if I say that exactly the point when you know that something is very familiar you get to evaluate whether it's factually simple or complex but when something is unfamiliar we have no right to evaluate its simplicity vs. complexity because it's unfamiliar ignorant about it and we first have to get familiar with it before we can even evaluate its simplicity vs. complexity let's talk about a fairly simple problem here and see how things could really get complex very quickly you could do this little thing in c-sharp or Java or just about any language but I'm going to use JavaScript here because it's the most beautiful language right so let's talk about JavaScript for a minute give it a bunch of names print names and upper case comma separated well JavaScript has some really nice features javascript is one of those languages even before language like C sharp that has been supporting both imperative style of programming and a functional style of programming together so what do I want to do here I want to say far and let's say name of names hey this is great I got names out of this collection one name at a time and what I can do here is can say process Dart standard out dot let's say right and I can write a name dot to uppercase let's say over here and when I write this little code you can see the names come up in uppercase but of course I want them to be comma separated so what do I do I'm going to say a little put a little plus or we could use a fancy nice features in JavaScript and write the code really nicely and we can simply say here you go and then of course I can go ahead and print at this point a little comma around it so that was not a hard core that all wasn't it but when you write this you suddenly notice there is a stupid comma in the very end has anyone seen the problem before how did you feel the first time you ran into it you said this cannot be true because it should be a such a simple thing to do why do I have a stupid comma in the very end and then you're sitting there without doing your work trying to figure out a way to get rid of that stupid comma and they're coming with some very interesting options maybe I'll store this into a string and I'll remove it oh darn it string is immutable okay I'll store it into a string and then use the index off to remove it and then you're thinking none of this really seems to be right and then you because you don't want to really store it into a string after all that's not your problem and then you realize why did I not think of it there is a simple solution to do it remember the word simple we use in here instead of using the word familiar so what are you gonna do you say over here let I equal to zero how does that go and then I less than names Dart and now you wonder is it length or is it sighs is it count well depends on the language depends on the collection somebody calls it length somebody calls it size somebody calls the count because we can never be consistent about these two kind of stuff and then you say a length and then you pass for a second you ask the question you said less than or less than or equal to because there's no other important business in life than figuring that out isn't it and then what do you do once you find that you say this is going to be names a square bracket I to get the value out of it and that lingering sum is a comma is still around so you quietly remove that and then what do you do then you say over here well if I is not equal to names dot length then of course I want to go ahead and process dart stand it out over here and then write and then I'm gonna put the little comma and the minute you do this you say that's not too bad you realize the comma is still lingering around you like damn it how do we get rid of this bang bang bang and then you realize is it minus one and we're kind of nervously trying that like yo get how it works right now and this works it holds true barely by us very thin thread because then your colleague comes to you and says oh the rules are changed only print the names if there are four letters wrong long this code is gonna fall flat and you're gonna say my goodness now got to put more variables to keep track of which of the last one is and then you're like I need a coffee break so this is accidental complexity right there very familiar code no doubt about it but enormous ly complex if you really hate somebody and you don't want to hire them give these things in the interview and say this is all your code airs and see them run away from the building right nobody wants to be writing code like this but on the other hand we don't have to struggle this hard you could try this in any language like I said but I can say name start map and give it a name I want to get the name dart to uppercase and then I would simply say given this collection just join them if you will plays with a little you know comma in the very end and you can ask you to do the work without having to struggle through it well most of the languages have been providing an imperative style of programming for a very long time which really forced programmers to spend more time on imperative style and as a result they're not as familiar with a functional style of programming but turns out impair the style of programming which we are really familiar with actually is more complex it is kind of like taking five kilos weight and putting on our wrist and then asked me to scold all day it becomes pretty tiring and wears us down but that's what we've been doing all these years if you look at the code on the other hand the functional style of code it actually is not familiar to a lot of us but once you get once we get used to it we realize it actually has less complexity in it compared to the imperative style of code so something that's familiar may not actually be complete as simple it could be actually simple but may not be but something that's unfamiliar may actually be really saving us quite a big deal if we get really comfortable with it and so that is one of the reasons why we should really get comfortable with writing some of these code and and getting used to this style of programming so given this what we just saw here is that the task may be really familiar but we should not confuse familiar with simple we should really ask the question is the familiarity that's really messing with our mind right now or is it the simplicity that really shines from this code and we have to be able to discern from them so let us not let us lots of things are familiar like for example the imperative style but declaration style and functional style is actually a lot simpler because we tell what to do rather than spending overtime in a fair telling how to actually do it which is really a good thing and simple one of the key things about simplicity is simple has fewer moving parts in it we saw this in the code example even though it's a very simple code example this is a very consistent team we see between simplicity vs. complexity is a simple code has fewer moving parts in it fewer mutable burials pure garbage variables fewer things we have to keep the state in our mind and work to it becomes a lot easier to work with those things because we have fewer moving parts in the code well I mentioned that simple is not necessarily familiar I said simple is not really never but another thing is simple is not over-engineered now this is one of desires for us the programmers we want to create beautiful engineered code and when somebody gives you a problem you won't exploit the design options in front of you you want to create an architecture that would scale and a lot of times we don't know what that scale is I had a client who came to come come up to me and said we want you to build this application but we have two requirements they said and I said wow that's great what are your two requirements and they said the products should run on the cloud and it should support concurrency I said that's great and they said no no no we want to make sure you can handle this it has to be on the cloud and we really really need a good support for concurrency I said can you tell me more about the problem you have and they said we don't know in over the problem but these are very important to us so so sometimes we kind of decide on the solution we want and we quite haven't figured the problem itself that we want to work with and and in our engineering becomes really a liability for us because we can't really maintain the system as time goes on rube goldberg spent his time creating water called the Rube Goldberg machines and these were pun intended but he created these things that would be enormous ly complex for solving really simple problems for example here is an example of a backscratcher that is going to work through a series of combination of activities to scratch the dudes back children in schools these days spend time creating Rube Goldberg machines and it's really a lot of fun to watch this but they don't realize that I get to do this for real when they come to work with us because we do Rube Goldberg machines all day at work isn't it well it reminds me of one experience I had with a developer I had this project where we were working on and what does developer had done is there was a data in a database and he had written about 250 lines of c-sharp code to read this data from the database and he converts it into an XML representation so I spent the time reading this code 250 lines later I'm like I understand that he has created this particular format and then I noticed what he is doing he's sending this xml document to this other function in the same application and what does this function do another 300 lines are code to parse this stuff and then he takes this data does a little work with it and sticks it into the database and i'm sitting sitting here scratching my head here's the data it goes into XML and then comes back into data again and then a little work and then gets saved so I was very intrigued by this so I wanted to really understand what was going on so I went to the developer and said and leiden me please what's going on here he said isn't that cool like no it's not cool that's why I'm asking you what are you doing here well I am taking this data converting to XML and then through seeing the XML yeah I get that I see what's happening but why are we doing it he said why Venkat you need to have a vision I said I'm sorry what machine do I do I not have right now explain to me well he said the beauty is that data can come from anywhere and the data can go anywhere now I said okay in our application where does the data come from well here why does it go to here so why are we talking about anywhere he said no no you really don't have vision you should have an architectural vision while he was saying this I took my phone there was dialing and he said I'm sorry give me a second he takes the phone he said hello I said hello he said is that you rank it I said yeah you're right here in front of me why are you calling me I said you have to have a vision I could be anywhere in the world now talking to you I don't have to be in front of you and the point really is we have to really understand the problem we are trying to solve we cannot just throw things together and say god I have a vision because I like shipping products that actually work and and you know Frederick Brooks said go ahead and build a software system and then when you are done with it throw it away and you have a better opportunity to build it for what it really serves so a lot of times we really want to get it out in the hands of the users find out if it solves real problems for them and make the code extensible but not by building mountains of infrastructure around it in fact the very things we put into the code for extensibility is what comes to hurt us the most because when time comes to really change the feature the changes are not quite exactly what we had predicted and all the code and the complexity we built really makes it hard for us to make the change so a minimalistic solution is actually really pretty good to really focus on and I'm gonna say simple is not terse now people confuse conciseness with terseness concise code is short easy to understand and work with terse code is short but waiting to hurt us when we least expect I don't want the terse piece of court I want a concise piece of code well I came across this example in an a client project and when I was working with them this particular product it sells for a very huge amount of money for licensing and the developers working on this product are very advanced engineers and I asked them do you mind if I take a little photo of this and they said ok and I saw I took a photo of it Oh what I really found was not this line but what I found developers I had left right behind it it said God helped me have no idea what this means so when we program code with such terseness we lose abstraction we lose the ability to understand what the code is really supposed to mean that becomes really hard to maintain the code as well well here's one example this idea actually came from n unit and J unit kind of copied that idea and both n unit and J unit what they did initially was you could write a verbose test like this so I could say try and call this max profit after calling set prices and then I'm checking if the the method is actually throwing this exception that I'm expecting it to throw well the one of the tools that did the change first of all is and unit so what nu and it did was well if you recollect C sharp had attributes way before Java had annotations so when attributes were around in c-sharp and unit said hey we could be smart about it and so what they did the code here is in Java but you can relate to this in c-sharp but what they did was they said we're going to specify the exception at the top so you probably recognize the syntax in n unit to do this and that way we don't have to have the clutter of all this and when I looked at this in and unit I really screamed because it made me really mad it's a really bad ready to do it in fact the end unit guys are very smart they did this and they waited long enough for J unit to do it and the minute J unit did it they duplicated this and said this is bad idea and so either J unit has this you know still holding and n unit doesn't do this they duplicated it realizing we shouldn't be writing code like this what's wrong with this it is a very terse code I say because in this case even if the method the first method throws an exception the test will fail for the wrong reasons I never want to test to fail for the wrong reason a better way to write it would be probably to use lambdas and that's what an unit does today oh by the way J unit also does this now but not as part of J unit 4 but as part of J unit 5 this is the way they are moving towards realizing that we don't want the code to be so short that it actually begins to do the wrong things that's what terseness really leads to we want the code to be concise and not curse so don't assume that something that short is actually better it could actually be pretty darn evil quite quite often so don't confuse ters with simple and concise you know code and as Tony Hearst said there are two ways of constructing a software design one way is to make it so simple that there are obviously no deficiencies and there ways to make it so complicated that no obvious deficiencies so we have to really think about simplicity all the way through well okay then ice men shinned a few things that are really not simple but you're not going to be satisfied leaving saying okay I kind of identify a few things that are not simple but it would be really nice to actually think about what really are simple so I'm gonna say a few things about maybe we could identify simplicity really well also well the first thing is simple keeps you focused now what is the most precious thing in today's world the most precious thing in today's world is people keeping people's attention we live in a world of instant gratification we know we live in a world of instant messaging and social media and to be able to sit down and keep the focus and get things done is really not that easy and when you get down to you writing your code you don't want your code to help you to lose your focus you want it to keep your focus similarly the tools around us the technology around us should really not make things easy for us to lose focus and and that's very very precious and I tell this with all sincerity because the most valuable thing I have in myself is the time I can never get it back once I lose it so anytime anything around me is trying to distract me I try to get rid of that so that is one of the most important things when it comes to simplicity we want to keep our focus let's say for a minute you are programming and you're not quite sure what method to use for this particular purpose and you're scratching your head you're not so clear what method may help you to solve this problem so you're saying oh maybe I should just do a search and look for this method maybe I'll do a search that says you know how do I really filter out all these values from this collection so with all honesty what you're gonna do you're gonna do a search so you are about to maybe open a browser so you can actually do a little search so let's go ahead and open a little browser and see what where it takes us and I open the browser and let's see what it says oh wait a minute interesting what a million dollar home can look like in Canada this week that's pretty interesting I'm curious how a million dollar home is gonna look like and iPhone eggs why bother with the iPhone eight hmm you know these numbers they keep switching on us it's pretty confusing actually and then of course Oh taxes you know what the taxes really suck I gotta tell you notice what just happened I went to search for something and I completely got hijacked and this is absolutely not relevant to anything I wanted to do all I wanted to do was do a simple search that's all but all these total noise around me that doesn't help me in getting my work done at all let's try this again maybe I can go and search in Bing well that's great a way to a beautiful picture where did that picture come from you know what I'm not sure I'm feeling I should search for it worried that another picture may show up and it may be in a recursion searching for that picture again let me try this one more time and I'm gonna search and Oh what do I want to search now think about this for a minute now do you think the developer who designed this had a easy job can you just close your eyes and think of the day the meeting room that morning the developer is there to do a demo and he says I've got the search page ready and he brings this up and they look at this and say what's this well it's a text box yeah I get it in fact I put even I know you're gonna ask for this so I even put one button call I'm VI are you feeling lucky well you should feel lucky to have this job and this is courage isn't it how many of you in your job will have the courage to say that's it I am NOT gonna put any clutter on it make no mistake the minute you hit that button enormous complexity is behind that button huge number of servers and clusters and algorithms and processes are right behind it but they said but we're not going to take all that power to waste your time because the most important person in this room is you your time is the most valuable and if I distract you from what you need to do that would be a disservice to you and this is something I care a lot about when what I do I want to get people moving I want them to be focused on what they want to do I want to make them productive I don't want to give them anything that they shouldn't care about but what if I really really want to know how a million dollar house looks in Canada I'm gonna search for that and I don't want to be distracted with that information and this is one of the reasons why I'm a huge fan of pair programming I'm truly am one of the terms that I'm really a big fan of is this term called Shaving the Yaak we all shave the Yaak well shaving the egg is fun totally I I want to have my own time to shave my axe at least while a couple of times a week because it makes me feel really happy but at the same time when I'm at work I also have to keep in mind that I've got production to release so if I'm alone what's going to happen I'm sitting on my machine I'm doing something and somebody says hey what are you doing well I'm trying to figure this out I don't know what the call is and I'm having a little trouble can you help me and and Bernie says yeah I'll help you with this if you can go help on my machine and I go look at the problem I can't figure it out so I call Sarah and say Sarah what's going on here and Sarah says I know how to fix this why don't you go take a look at my problem and then a few minutes later the boss walks into this class and looks at me and says venket yeah what are you doing in the class said shaving this yak and I'm like boss I don't know how I got here I remember having that problem on my machine I ask for help and one thing after the other led me to having to shave this yak not quite sure where this yak plays a role in my solution today but I'm here shaving the act we do this all the time we are solving these meta problems but imagine you are sitting on your computer and you are pairing up and you don't know how to make this call and what do you do you open up your browser and your browser says would you like to install an update and your colleague next to you not just even says not now dude we got problem to solve and you're like no not right now and keep your focus on it I have to tell you I've never seen a pair of programmer sitting in the closet and shaving a single yak so that's actually a good thing in general so we want to really keep focus and focus is extremely important so anything we can do to keep it so people simple keeps you really focused and that's one of the beautiful things and here's a code that I really like a lot and this code says perfection is achieved not when there is nothing more to add but when there is nothing left to take away and this is the thing that I constantly remind myself when I do design it's not what I can add that matters it is what I can remove that really matters I used this not only when I do software design I do this when I write books when I write articles the words are golden you want to really minimize the words you use and deliver the car and really concisely so people can actually understand it without a lot of fluff and words that would describe them and waste their time so taking things away is a very important skill we have to create four key things keeping things really simple so a simple eliminates accidental complexity and hides the inherent complexity now the inherent complexity is based on the problem domain that we are working with the application carries complexity with it but when we use a wrong solution the solution brings on more complexity and that becomes a vicious cycle because we bring more solutions to solve those complexity and we get dragged into it so I want to minimize as much as possible accidental complexity so I can more prudently deal with the inherent complexity of applications the next thing I want to emphasize about simplicity is simple keeps your focus but simple also fails less now when programs begin to fail how annoying it is for the user I'll give you an example of this I wanted a boy asked me to fill in for a visa and I started filling the application for the visa then I came to this section where it said list all the countries you have visited in the past five years I'm like are you kidding me and that took me hours to enter because I travel almost every week around the world and I have to sit there and enter everything but as I was entering it onto this website that my programmer mind comes in and keeps telling me dude do you understand you're using your application a user mind says enter the data programmer mind says this is going to crash this is going to crash so I started copying and pasting literally every information into a text file as I entered into this visa site and I came to the last page and I clicked on the submit and the whole damn thing just disappears and I'm like thank you very much and how do you feel when applications behave like this and you wipe your sweat and say I'm gonna start over again at least I copied this on the text file now I had to just copy and paste it and of course you say are used to Peter try it again well that's called desperation I still want to travel to that country and about the third time it actually works it's wonderful when things work like that but the point really is it you should really make applications fail less and if they do fail they should you know fail gracefully same thing with API same thing with you know libraries we use we want to fail us but failure is not just the runtime behavior it should make us fail less as well in our attempt to use these libraries - what if the library is so obvious to you how you would actually use it I'll give you an example of this I was working very late one night and by this time I was very very sleepy I was barely awake and maybe you would say Vanka this is not a good time for you to drive but I really had to get home so I was driving and that's when I realized my gas is low on my car so what did I do I pulled up to the gas station and I wanted to fill up gas and I could barely I have no attention span right now and I pull up I put my credit card and I take this you know a pump and the nozzle and I'm trying to insert it into my car and it just would not insert and I'm almost the point where I want to cry I'm like why do this to me I'm really tired I want to go home I want to sleep why would filling a gas in a car be such a hard task and it wouldn't work and that's what I said stop and get think and that's when I realized it's actually diesel nozzle and I can't put the word petrol belongs and I am like thank you for designing it this way right and imagine they had not done this I would have filled diesel on my car and I don't think I want to get a new car that's not the way to get new cars so that's an example of where things actually fail less where it can protect you from making these kinds of mistakes that is something we should really try now look at this example here this is the main hole and of course you see that little round circular lead and I could ask you why is this lead circular in size and most of you probably will strike with an answer very quickly you would say oh of course the reason why this is a circle and in shape is it will not fall into the hole you are not wrong you are correct but imagine for a minute you are gonna send a proposal tell you you could even try this and a proposal and you tell the proposal your proposal says we want you to build a cover for the manhole and when you build a cover the cover should not fall in and I bet you very few a proposal replies you get back will be a circle because that is so simple and we cannot charge you more if I make things very simple right so what would you get back most likely it turns out each of these shape also have that property you cannot put any of these inside also and the chances are if you are dealing with business contractors they're going to send you one of these not the circle because they can charge you more for these things right and it looks cool but circle has one other property then it won't fall in if you are this person coming out your team is waiting there after a very long day's work and when you come out of this hole you turn around and you ask the team hey dude which way do I put this and the answer is I roll the damn thing over let's go home and that is one of the most beautiful things about the solution too it's not that it won't fall in it doesn't matter what direction you put and it is the absolute ease of use that is incredibly powerful here that we should really think about there's no wrong way to do this that's the whole point so when it comes to this easier is simple is easier to understand and simpler is easier to work with as well what if we start designing over libraries in a way the the person using our library doesn't have to feel the pain how many times have you used a library where you look at the method and the method says the parameters are three parameters and they are int P 1 comma int P 2 comma NP 3 and you look at this and say why are you hurting me right because you don't know what these three-inch mean you don't know what order to send them in and they are making us work too hard to figure this out not very simple at all well here's an example I wanted to find if a number is a prime number well to do this what I could do is I could write a code like this I could say is prime which tells me whether a number is prime but here is the primes which is going to return it's going to say if a given number is prime concatenate that with the value and all the primes that follow it otherwise return to me just all the primes that follow it unfortunately this code won't work and the reason this code won't work is it will go into an infinite recursion and throw a stack overflow exception but it turns out we can actually do this you can do this in c-sharp as much as in Java by using infinite streams and in the case of c-sharp you can use an iterator to get an infinite stream and you can say given these values lazily being created I can produce these kinds of results and I can produce it by looking at a slightly different solutions we can start finding good solutions to problems but is this really a complex solution or is it a solution that simply not familiar to us comes in into a question so sometimes when we explore these ideas we have to really work really hard to find a elegant solution and simple is elegant so let's think about elegance for a minute you know why is this one of the most beautiful paintings ever created and I would argue the reason this is the most beautiful painting ever is because of the simplicity in it it is it is word there is nothing here there is this lady and there's not a whole lot around that is pure elegance pure beauty and that's what you're really looking at there is no ornaments to clutter there is no things to clutter there is absolute simplicity and elegance comes out of that elegance simplicity comes out of this elegance and and so we want to be able to create something but I was fascinated by this quite a bit and I call this the architects dilemma so I was visiting Boston and I was walking through the downtown with my family actually and I was a visiting I came across this Trinity Church in downtown Boston and when I looked at the standard Church I actually did not look at the church directly but I was looking at the church and I stood there absolutely mesmerised in fact I fuse to move I just was stuck over there with my camera are trying to take photo until my family eventually came and said you better start walking or I'm gonna call the cops and so why was he so thrilled about it what really helped me there what really helped me there was not the church actually but next to the church there is this John Hancock cover well they wanted to build a tower in downtown Boston and they applied for a city permit to build this high raise next to this church and the city said there's no way we're gonna give you a permit to build a building next to this particular church because when you build this the beauty of the church is going to be destroyed so we will not allow you to build this over here the architect came around and said no we do want to build here and when we are done with this this building that the church will look even more beautiful he said and and they kind of entertained the part and they said okay let's try and so what he had actually done is actually this he created this building next to it in such an angle that the reflection of the church is a lot more beautiful at least to my eyes than the church itself and the camera here is not doing a good justice for you but if you ever get a chance to go to Boston downtown I encourage you to take a look at it it is just unbelievably beautiful and you can just stand there and stare at the church through the reflection on this building at the angle in which it is and the pure elegance the solution that was here to bring the beauty of this place is just unbelievable and and this is something that I admired quite a lot a lot of other things were exciting but I kind of stood there just admiring this architectural work and and that is a really really simple solution for a problem to bring out the elegance as you can see in the in this particular case but I also realized though while we all want elegant solution very few of us can actually create elegant solution in one sitting in fact elegance has to really grow and evolve we have to work towards making things really elegant and and Fineman said if you cannot explain something to a first year student then you haven't really understood it this is one of the things I used to measure whether I know some stuff or not I remember teaching a class way back in time and I went to the class I spent an hour lecturing on this topic and when I finished lecturing I found that everybody was in their face they were I could see the pain in them and because no one in the class got it I didn't even pretend to ask them do you understand because I know they didn't understand it so I said you know what Congress has a failure never mind I'll see you guys tomorrow in class and it went away and I came back the next day and I explained it and within 30 minutes people came to me and said oh my goodness this is so easy to understand and by the way why did you have so much trouble explaining this on Monday what was the reason I said oh there's a very simple reason because when I explained to you on Monday now I figure it out I did not understand it and when I tried so much to explain it and when I went back that night I realized I don't really understand this after all I was trying to teach this stuff and when I sat there for three hours that night and trying to go over it it finally clicked then and I got a deeper understanding that I ever dead so it was much easier for me to explain and that is one of the most beautiful things as when you understand something really really well it becomes easier for helping others to learn it otherwise it becomes really really hard to understand it and this is something that kind color comes back and forth but in my experience Occam's razor says if you have two equally you know due solutions which are equally useful for a problem then choose the simplest of those solutions I have learned an experience when I was writing the book on Java 8 I was working on this book when Java 8 was being developed and what I really wanted to do was show that we can implement tail call optimization I mean there's this inner spirit in each of us to do something kind of little weird and unique I want to do a tail call optimization so here's a factorial as you can see where I'm calling the factorial method recursively but unfortunately this will end into a stack overflow but a tail call will not have this kind of problem well I've read books like structure interpretation interpretation of computer programs and in this book they talk about something really phenomenal they talk about a difference between process and a procedure a procedure is a code you write a process is the runtime of that procedure where what what runs in reality when you write a loop you're writing an iterative procedure it runs as an iterative process when you write a recursion you're writing it as a recursive procedure and it runs as a recursive process no surprise about it but in tail call optimization what you can do use you write it as a recursive procedure but it can run as a iterative process then you will never get a stack overflow exception I've seen how this is being done in languages like Clojure in languages like Scala and groovy and Haskell and Erlang so I know that these languages do this but Java itself does not have tail call optimization so I wanted to really implement it and so I wasted literally wasted two full days of my life not doing anything but trying to create a tail call optimization solution and when I created a solution it looked somewhat like this and I then spent 10 more hours and I wrote something like this and the nail the real essence of this is a while current dot apply is equal to current then executes the current just look at this part alone it'll become really easy to see all the other things are not important so current dot apply is set to current and then current art is complete and I keep you know repeatedly calling this method well this is the solution I had after about two and a half days maybe three days of effort and that really bothered me and the reason it bothered me is when I was writing this book until the previous page in the book I kept telling the programmers avoid mutability avoid mutability avoid mutability and then when I wrote this example what am i doing mutating so I spent countless hours on this and in all honesty I was totally lost then I came up with a brilliant brilliant solution I think it still think it's brilliant because what I decided to do was right under this example I wrote a paragraph and the paragraph said dear reader do you notice I'm using mutability to solve this problem the solution with no mutability is left as an exercise to the reader because that was a brilliant solution wasn't it it would have worked about 30 years ago but today we live in the world of Twitter and Facebook and the minute the book comes out they're gonna say oh yeah so when you post the solution damn you and so that's not going to help so I said okay let me think about this and I spent a little bit more time and I said okay a better solution well don't use mutability except in cases where you cannot avoid it and I felt really silly about it too and I said to myself I can't do a grim realization but sometimes it is good to come to this kind of realization I fully realized my code simply sucks and I said there's no way I'm gonna put this out so never mind and I kind of moved on and a few days two or three days later I was on the treadmill exercising and slowly in the back of my mind a threat is processing this problem and suddenly I'm like whoa wait a minute I totally didn't realize they could do this and I jumped into the treadmill ran two floors of my building while my children screamed are you okay daddy I'm like yeah I found it and in 15 minutes I had a solution and the realization came from something I never expected I realized that in the primes example I showed you we can use a infinite stream meaning I can create an infinite collection well what if the collection was not numbers or other data objects what if the collection was every object in the collection was a function and because it's an infinite series when you evaluate one function you get to decide if there is more functions or not and the minute I realized that you could do this 15 minutes later I had a solution which really avoided mutability and became really elegant I said given a function iterate over a collection of functions and until it's complete but fine first and get me the first one and print the result you know in c-sharp also for example you have this ability for getting the fine first I think it's also called as fine first or default you could also use and those are lazily evaluated so that becomes really easy to implement that kind of solution something I never actually thought about but came to be really useful and and sometimes it takes a very long time to find solutions that are actually simple and so as Einstein says everything should be made simple as possible but not any simpler but always worries me is what I created simple or can it be even more simpler and I always learn by getting feedback from other people because when I show something to somebody and I think it's simple they come back to show me that there could be actually something even more simpler while it's very humbling it's also very important for us to improve and and build something simpler as well so I have this feeling that maybe simplicity is that showing your sketch when you look at simplicity what you have is simple and yet it is complex at the same time until somebody can show you that there is maybe something a lot more simpler than what you thought about so simple makes things easy but it certainly is not easy to create something simple it usually comes from hours of toiling hours of rethinking hours of challenging and hours of having the courage to delete what we have created and then recreated and I think that is extremely important so leave you with the start by da Vinci and I think it plays really well he says simplicity is the ultimate sophistication in life and that is absolutely true and I think it's worth striving for it and the more we attempted the more we do with the more we practice I think we develop a knack for creating something simple and I think that's very well worth doing it time over and again hope that was useful thank you you [Applause]
Info
Channel: DevConf PL
Views: 14,931
Rating: 5 out of 5
Keywords: DevConf 2017, Venkat Subramaniam
Id: R4C_JciDsuo
Channel Id: undefined
Length: 57min 38sec (3458 seconds)
Published: Fri Sep 29 2017
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.