The Art of Clean Code by Victor Rentea

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
before we start I didn't want to do something first this is the the biggest room I ever was I want good so it sounds like good I really wanted to do that to be in the whole equally bigger than our opera back home good so the art of cling coat really excited to be here with you to talk to you about my favorite topic Who am I first of all I'm the polenta a consultant technically one of the debug effects for the largest one of the largest client of IBM Romania but there's not me actually I'm a clinical divan jurist and I talked about clean coding clean architectures and all these conferences that I keep talking about that because this is what I love to do with my free time however my passion is basically to train and teach and coach others I already have some experience with it so that's why I'm here with you today from this passion I talk about I teach Spring Java Enterprise being called architectures even if faculty I teach design patterns coding dojos performance in many more ok enough about me what will we talk today about first of all why am I here what is this clinical stuff and why do we need it there in the names or better yet the power invested tips then about the single responsibility principle a principle which many might say that it's the most important principle of programming then about the Autopia we've been learning about then about about incompetence then some how to handle this lightsaber that we were given by Java 8 right how do we arrive drink or regenerate if we had enough time to cover like link oh there's one thing well so the inventor of C++ right you can already see the things responsibility principle in their main code we'd like well written pros like a book you can see that the author of green code really put as for interacting expressive nice elegant coat beautiful god-king code is where each method you read turns out to be pretty much what you'd expect it in the context of you have founded a multi flower comes and says that anyone can write code with a computer can understand light mode ax bakes but few conceal programmers are able to write code that the human can understand and that's what we here today to talk about how to communicate instead of clothing okay this pretty this is pretty interesting the code it reads needs to turn out to be pretty much what you've already expected in the context you found it before we can move on do you know the International lead of measuring for code quality yes that's it I want the I wouldn't say it out loud but is the number of times the developers scream and the curse when they review the code right and this is actually the the essence of the principle of least astonishment you don't want the clothes to shock you at each step you want your code to work with you to be familiar to be easy to read understand why do we need think it but easy you all know probably this the true cost of software realizing it's maintained is not in initial development eight percent go that why why so much because we get slower slower time passes by a task that you do now in five minutes you're doing one month in one hour in two years in my even become impossible so we just slowly store because the code quality degrades you may not be concerned of this financial consideration but the fact that you turn out to read code ten times more when you get to write code it should tell you something you should do your very best to write good code even if that means it writing becomes quite hard so a rule that you can an idea that you can follow in this spirit is that whenever you take code of get to write some changes to fix on something don't limit yourself to that fixing that thing also do some random acts of kindness some a little improvement to the code from extract method some extract variables and renaming to help you to make it to keep the code allowed otherwise your to work in a place like this dominated by fear you will come to work your sit on the chair and suddenly you'll feel satisfied by changing the code right you don't want to go to come to work to such a place right actually it is said that the day in which you stop refactoring it is a day that your application has become a legacy and you all want work in legacy code onto your right so avoid that the point is if you continue to postpone a certain refactoring once twice in the end it will become harder and harder to do that refactoring and you will end up not doing it so don't be afraid to refactor always when it has the idea go ahead the fact that otherwise you will have a legacy code right soon now a lot of us of developers are me also are fascinated by this power that we have at work we literally can invent things can put them in code give them names and make them alive very few professions are able to run the thing that they create a right to give life in a sense so this is a huge responsibility because we have to invent new things we have to select names for these things and as you all know with great power comes great responsibility right so you have to be good at picking up good names for the things which we create talking about writing prose here of course the function should not sound like that right what does the production function do but it's a create persist what does it do you should have obviously some verbs in them right now with boolean things use the very name of that thing which is a spite boolean should scream it so that it's a boolean there you can't possibly answer with 17 with such a question like these are predicates these are names that screen to you that this is true or false now for class names it's pretty straightforward they are nouns of course the other thing that we work with but when you select names for your classes try to avoid adding these useless plastic cells or suffixes like this tell me what is the difference just by looking at the class name what's the difference between ordered info and order let me let me take my shot or the info healthy I'll slide the it class it can have feel so this is right - refusing your power which is just like not willing to take up the responsibility and putting the good name this is one guys with said on Twitter that his search for a glass name for four hours four hours for a classmate addressing tomorrow you should put your data task search for a classroom for four hours but the point is that by the end of those four hours that this developer clarifies his entire domain by looking the conditions the possible meanings the related concept of that thing that sieves searched for so take the time to find good names for the classes it's create in the same spirit if you encounter a thing named I customer service tell me what is this it if an interfacer and it there is also a class named customer service which implements this quite quite obvious the same applies for this naming convention this is just stupid actually it's just stupid and I will tell you delete your interfaces fully remove them with three exceptions in case you really will send your interfaces to your remote clients for remote locations or if you are using religious stategy pattern and you are selecting the implementation to use dynamically based on some data or in case you are doing dependency inversion like I've discussed in the morning in the in the clean architecture talk cool now tell me honestly how do you understand the function you see a function you want to use it how do you do what do you do you probably would read the comment that sits there right and then probably you will start hunting for the other places in which that function is being called in you will invoke in a similar way the same function right there also Spartans of you will probably open up the implementation or the function and they will start reading so the reverse engineer the function is this tremendous effort and you shouldn't need to do that each time the name of the function should tell you all that is about it it's in tension that's why whenever the things you found a better name go ahead and refactoring but at times there is this thought that occurs to you oh my god is impossible I couldn't have found a better name that was done by the elders who wrote the application 15 years ago right this is complete nonsense you should find better names as you learn the applications or go ahead and rename it rename it on the spot the ideas will help you a lot it gives us stuff with a different idea and it really fails this renaming it's usually it goes okay the only places where it might fail if you have reflection going on in your application or if you have some it's somewhere that reference that some class names but you will find out which classes are more fragile and you will take care next time if even hasn't named it named comprehension recycling it something like ah look what I found let me rephrase the code not afford for the following developer to be easier to understand I talking about the continuous renaming process as you learn the application because there are no perfect name you know this code I repeat myself I mean from the morning but there are only two things have been programming cache invalidation and naming things and I'm putting about finding good names here the whole team will be grateful yourself will be grateful in three months tell me one thing honestly how many of you have cursed the code some code and then found out that they were the author of that code right you redundancy oh my god it was me why why does this happen probably you didn't review your code back then enough but more importantly you forget the design decisions you forget the code that you write we can you already don't remember all the decisions or did not micro design that you put in place so yourself will be grateful for them I'm talking about the continuously naming it continuous refining of the name just like a distillery for example now the names of course should be pronounced about how could you argue with someone about this function it's it's a complete nonsense so use words but I'm talking about avoiding abbreviations not inventing new abbreviations every five minutes of course all the smart and writes value added tax in your code right Val of course it's a well-known distance term that you should embrace in news in our code but I'm talking about not inventing new abbreviations each time because they have to be learned names should be consistent if we go to database with find special yet I don't I don't mind the only thing that I mind is that always to use the same verb when fetched answers and the database enforce conventions and help your developers of fallodon why because the code will look familiar to you even if it's not you who wrote it all developers should follow the same naming conventions now when selecting a name don't don't refer to a customer with wire and client in different places because the reader will get confused or why the heck what's the difference why is it by rat and customer here there is no reason the author was just being overly creative he should have he should have written poetry instead that code in the code you want to be exact precise concise don't leave room don't leave any ambiguity then on this gap right on the one side is the business with money on the other side it's us with the pipe and we need to exchange four bytes with their money so the first thing we need to build is a bridge between us so learn their domain always and have also them to understand the limitations of our world that you cannot possibly have to submit buttons on the same page for perfect explain them these things make them understand so both of you should learn something from the other one on other words words now with treasure is pretty straightforward it's all about the single responsibility principle a function should do one thing it should do it well and it should do it only says uncle bow for the purpose of translation be small how small should the function be tell me five why's that what the Bible says five lines files lines of code oh my god oh my god a first time that I've read that I was like what the heck how come five why is it impossible why so small but it can't possibly do many things in five lines of code right if you do it right yet you're done you have try-catch and you have two more lines what would you do in those two lines you will you will call the functions of course you will invoke other functions so the thing is if I raise the - you can't possibly write much of a logic much of many so you have a better chance of having a good of finding a good name for that needs to the functions interesting enough either this file is just empirical right in our applications we are we often have this boilerplate code going on Get Set Get Set Get Set that make sense to have five lines of code or method with such code the eristic that I use personally is that is a function it takes me more than three seconds to understand I break it up just if it's too much logic in it if it's a form with complicated things I break it up in smaller methods so the idea is that the function should never exceed even so one screen and I don't mean you should rotate a monitor at one screen means I don't know 25 times if it's boilerplate stupid code cool now this is don't you'll end up with such a function like I did years ago deliberately prohibiting myself of any kind of refactoring and then I affirm now at the end of the day for me it was very easy to work with this function because I just wrote it I knew only to save it when it was perfect I mean it is super familiar I orient it very well in it by just following the indentations and the fourth is that I knew where there however for the rest of the team this is like complete while the rest this is like like an completely unknown landscape but honestly what would you do is I would give you two first to implement a change request in such function first of all you are working with me in the teams are probably will start reading from the beginning to make sure don't do anything stupid and you will read read read read read in a third point the phone rings it's the matter okay the cat is sick oh my god then you keep reading the beginning and there come to the lunch break what do you do go for the lunch of course not the pyramid of needs we have to feed first rock then you come back from the lunch you don't recall exactly what will their way to keep reading reading and as I'm going to say Arica I found out here I need to do something else I think additional what do you do now what you puta you put a leaf yes you put a leaf and you add the parameter there above right yes effect it's like working in on the street with a dirty little used tissue in the hand and you find a trash bin that overflows what do you do we do that with a tissue but you just added one more responsibility to the same function what you watch you should have done is to break it up into smaller solutions little ones extract them all end up with 25 functions like I did and then be terrified why was I terrified when I ended up with with 25 functions please don't any performance because smaller methods were proven to work faster because of because they get hot faster and get compiled creative code faster so now the performance is not the problem with performance there is just one now that we perform at least one single rule to follow measures longest like pepperdine sir actually the major stimulation is the root of all evil to clutter your code upfront just because you think you might have a performance problem don't don't do that measure the problem and then clutter your call with optimizations by always looking at begin in milliseconds that you achieved using Bible by braking by making your code ugly so no it wasn't performance that scare me but is the fit was the fact that instead of having one single familiar function I now had 25 functions to remember come on I had 25 functions to remember I was doubling with 25 new functions well by the end of the day I don't even recall the names of those 25 functions for me the open it was very hard to work with so many names but for only 4 for the entire team things were a lot clearer because the function the names that has put to those new functions were looking like this let me read one for you remove all past canceled orders of concern with all due respects if you can't understand what this function does I don't want to work with you so you have to be brain dead simple the readers understand because you might be debugging this function Friday evening at 12 o'clock at night so be kind to your readers like leave behind you wrong names that tell what the function is doing since we're talking about single responsibility principle let's look at this example this is a function that receives two boolean's right like before how many things do you think this function can do but maximum but this for right mm I'll fastest so break it up break it up and in many melamine methods and then combine the invocations to these methods to achieve what you want now this particular kind of function mean not only laziness or fear but mean also rush and more importantly this function tells us two things first of all the team is terrified by refactoring this function is scared to touch this function and also this function was recently changed a boolean parameter was added it means that the function is ugly I mean scare the developers and changes it is the perfect candidate to start refactoring with because it's the maximum gain can bring these changes and it annoys people so refactor this one in the same spirit if you ever make accept customer to be null you will also do a null check write your test if customer different in now then you continue and again we are doing two things for formal and what for not moon so I'll tell you don't accept mutable parameters oh my god what am i telling you I'm telling you then the question is when when and where we fight with anybody data okay this brings us to the moon Wars let's suppose you can build a fortress inside your code it can put some kind of code inside the fortress and the rest of the coding they'd have to be outside inside the fortress I will personally want to have my drawing services and the essential business logic of my application in a safe green peaceful Zen place I want to have my logic there and read it and and and let all the corrupt they that surrounds me outside the walls for leave all the data out then at the entry point enter in your photos we do it with a bodyguard a strong body part which does defensive programming total it takes every kind of vivid it wants to enter the photos if you do that you can gain a sense of confidence of trust you no longer have to check any kind of data for invalid data for negative age for empty name so dude is a dmg point in your system and then trust the data you have inside however at some point you might end up with a mole inside your photos and this mode might actually have a business meaning like for example the fact that the customer doesn't have a gold card it might be business wise reasonable right if it makes sense in a business mindset then you could wrap a optional and I keep saying that optional is the best the best I'm the use feature of the raid so wrap it in an optional and work with the optional don't pass the new around but if the new left will represent a fatal condition don't be afraid of throwing an exception and the slow on the spot with no fuss and this brings us to exceptions you know that there was a war between random and inject exception the war is over we'll all go over because you don't want to do this right and this particular example will help me will schedule 15 minutes of personal discussion with you I mean if you do that ever you know swallow exceptions it's absolutely horrible so another not to be forced to do this always prefer to throw and handle runtime exceptions because we don't see those Randall exceptions now just my preference is now I always have a global exception handlers at the at any thread entry point in my system because not only HTTP threads play in your application but there are also either no file Polar's timers GMS messages coming to your application make sure that any where a thread enter the application is half destroy catch and place to load it nice in the in the log then if you have to have nice message translated in the in the in the in the language of the user put some code inside your exception and then translate it outside using some messages or table now if you do that and there is one more thing here avoid kitchen avoid writing catch in your business logic code how can you do that actually the most the vast majority of area of the exception that appear are fatal conditions there are only a few exceptions that you can retry for example HTTP connection timeout or something like that you could imagine a written ISM for the rest of the cases exceptions are usually fatal condition so don't be afraid to throw them here and leave them propagate down to the exception handler at the end so in in short don't do in your code don't don't use catch so minimize as much as possible there are quite a bunch of principles and guidelines to follow quite a few and it's pretty practically impossible to write this kind of function without continuous refactor it's impossible to write these functions from scratch absolutely impossible the only way to do it is by continuously refactoring the code once you have it working so you are not done when the console first starts working and I look at my colleagues my junior colleagues what they do if they always get up and run take a break after they finished some use case then the next project probably that guy won't be in my team but if I see him every once in a while maybe reflecting a bit and thinking on better ways to expressing the design that she just did then I love them I like him the point here is that the best moments to refactor the code that you've just written it is after you see it working it is very many should clean up your code it is this is this way how you can grow your design one smart eye says that the time that you see your code first start working it is the moment in which you start investing in your career and you start building your own design skills because we all screw the design up the first time we do it let's let's let's admit some of us have remorses have this bad feeling about what they just did but if you feel this this remorse don't just get up and run stay for five more minutes and refactor the code just roll in in your head there are all the micro decisions all the D remorses all the traders which it just did it's the best time to refactor not the model not after lunch break Venice but who now cut example finally how can you simplify this bit of code this huge skills first of all you see if the reader get past the if he automatically gets tired because she has to remember that an else will follow then he enters another if with another else then a fourth will try catch then you know and when it when he reaches finally the actual business logic is like this I mean what the heck he has to remember so much it turns out actually that the number of consecutive tabs indentation that you have in a function is a good measure of the complexity of the function you can evaluate the extent we can recycle it them like this litany animation it can refactor this by reordering this test so first check the parameter is facing Israel abruptly exit the map on the early return refactor and if you live in is always well then continue on now you can see the number of consecutive stops is just one right and it's actually good measure I told you and I actually had a client that had a maven plug-in setup that in case it detected any three consecutive tabs it will fail the built I mean wow well because little made all the the nastiest function we ever saw were deeply nested if you see a function is just just like a poppy rose that you down down down during indentation we can easily probably cut it into multiple pieces without fast so that may be many complications but this is super deeply nested is it's a mess now that the most simple refactor we can ever imagine now let's talk about the most on tricky IntelliJ actually offers it out of the box for you but let me let me dissect it a bit now you have to respect for a method that has one thousand nine we did you how many of you have ever seen a method of 1,000 lines yeah I love you guys what do you do we have 1000 line to recite well quick hint a class should never exceed 300 lines what do you do if I have a function a function what 1,000 eyes they tell you about this function when you get hired they tell you you will work in this function at the hiring interview so you have this humongous function what do you do you promote it as a class this is called the extract method object inspector and I quickly quickly want to show you what it means when it has a huge function with lot of local variables and deep nesting if you don't extract this block as a method you will need to pass this brought a lot of parameters and at some point it may even be impossible in this weed patch two local variables from the outer scope so in that case you could do you could create a new class that will have all the local variables will become filled in the other place the parameters you take via the constructor and then the rest of the logic you put in an execute for example matter given from that point on you can extract any block from the original code in different methods because the the formerly local variables are now filled in the instance and it'll they are readily accessible you can change to totleigh field and you don't need to pass seven arguments to that function so it's acting method becomes possible however i want you to realize something in the left side i'm just invoking the function in the right side i'm instances in the class I'm using it and then I'm throwing it away right for that purpose the right-hand class is stateful it has field which store intermediary computations of the current processing it is a stateful class and stateful is bad it is hard refactored hard to understand hard to work with so my point is that if you're right if you design some new functionality from scratch don't aim for such a design this is a tool you should use only when you're affected monstrous legacy code right and the use of this pattern in Greenfield should be an exception well documented and well debated okay that being said let's talk about object or the LP utopia how many of you now see alright good now oops I just wrote it so it was lovely just a collection of data nothing more okay that's one particularly lovely example of a stroke in Java it is immutable ah cool it can never change that's why it's easy to work with it will remain valid please it's safe to put increases receiving sets and maps whatever it's lovely the other example you anticipated probably I would feel with getters and setters and I get I'll repeat myself in the morning this is nothing exhalation this is nothing to do with LP it's actually an anti-pattern you do more than just setting the field in the setter so this is nothing different than having public fields take down that funnel I'm joking but the idea is it's nothing different actually now what these are all be in one slide you will allow me the elegance but the all these basically explore periods in that data exposing instead of expanding your own internal data exposed methods for your user do start engine this way in the next version you can have three states for your engine for example and when you really have to tell something to users expose found in a program make sure it is you expose it in the most app way as possible so don't tell just ring in liters neither percentage fuelers tell some estimated remaining kilometers if you go this way in the next version of your car you can implement it as a hybrid car right just how many cables can I go on with my battery so it's an API which will remain more I question Pat ability here it will remain more stable so OB it's all about hiding the implementation details from the code that uses your API well but that work we don't do our be doing despite the interview right we don't do our P and there's a reason for that because in our enterprise applications at least in my world we write procedural code why because most you enter both applications just translate existing procedures in the real world and implement them in software and I found it quite straightforward to implement procedures using procedural code so we are just we are just writing tons lots and not just figures within our enterprise applications well and then our question is how do you organize it how do we keep it simple simplicity is the most important principle for any any large enterprise application it's simple how to organize this huge amount of procedure to do that we will distribute this huge procedural code into many classes but these classes are nothing more than but containers of logic they are just like namespaces basically it have services in the order service is not an object is not a structure just a way of organizing become the huge amount of procedural code so just as me tips that you are not doing a LP you are not you are not doing structures also there is another form of class which is basically a container of logic then after all did they really asked us for nothing those stupid questions that the interview when when in your career you will you ever care of of not breaking your client the code that uses a certain class I usually have this as a question but now let me tell you why will you wake up at night terrified now shivering what why when will that happen when you create some when you dare to create some mini libraries and mini framers a mini reusable code that you dare to publish on your corporate Nexus like my court - Commons - why one point zero and the one point zero is not the problem that wakes me up in the night because other applications will rely on my 1.0 version and the next day obviously I understand a bug in my code and I would want to fix my library and I will go begging the clients of my jobs to migrate to one point one but if the migration is more than just changing the version number in the poem XML then they will just not do it for me in my bag will go to production so when you're right whenever you write the mini reusable code mini library always think of how hard it will be for your clients to migrate to the next version and then it is the place to employ IOT to make sure your API stays stable there is when you have to employ all those or biscuity to have who's now about formatting and comments do you see this farming glasses in this bit of code this is a code right let's go do you see the sunglasses let me take you a broader overview do you see the sunglasses let me help you well it's but you know you know it's not magic at work it's all about teamwork you are not me oh you shouldn't call yourself improve how dqr how obfuscated code you can possibly write you are working in teams despite the subtlety of who that only gives us homework if our individual works so your assistant is the faculty you come to work then suddenly there is someone standing next to you now and he's alive he moves if you touch him oh my god I have a colleague what's that a colleague it's a human being I have to interact with him how look at this this is a major major problem for any graduate to work in teams to support and to tolerate what is human presence and why are you getting the whole earth shift because it's all about caring for the other team member otherwise they will hunt you down so don't call this is our message never co-op to skate don't you see you know what what did you do today I caught it I already see you with the Enigma machine encrypting a message you know don't do that right communicating code tells your thoughts express your intention respectively but the code you wrote in ten minutes will be what the code you wrote Internet will be read for almost two hours by someone and you don't want to know the thoughts in that person's mind about you so be nice to your reader be nice to the one who will maintain your code alright literature right nice phrases explain what you want to do and never ever obfuscate again I repeat myself if you have energy in one day invested into optimizing it is simplifying into making a mini framework for distance so test is the most challenging activity you can ever do an America professional how experienced you want so invest all your energy into good test there is another thing that I always say there is no reason for pride in any software can besides having fast super high coverage significant non-overlapping clean dry tests there is no other reason to brag about the software now if you join the army they will tell you that look this is your crash nickel for now this is your wife your mother your this weather I can move in right I'll tell you the same about your IDE it is the bitter foster you must dream about you must know it by heart learners belt circles the contest refactoring contests in which you put the mouse here in your ear say start who finishes first games the beer no so learn those circles make sure you are as fast as hell when using those circuits because when you will have to do a major restructuring you need to move lightning fast configure reasonable static import reasonable default complex make sure you have a short short short tiny feedback loop like Venkat setting the time you have into building a fast feedback look into having the instantaneous deploy instant then supermini testers are now just some suggestions the line the lab should never go over 120 140 because otherwise we will force the reader with his mouse to click on the dance crawl into drag the scroll bar you don't want to do that to your reader so never force a reader to scroll horizontally for metal in earnest I already discussed with you the point is to be easy to understand never more than one screen but for the length of the class I already told you somewhere about 200 300 lines more these are just suggestions what I use pub for 2 characters whether your Egyptian style or not whether you use spaces how you put the bracket I don't care all that matters is that the whole thing follows the rule that were established by the team so play with them making the code as similar as as idiomatic as possible with their clothes in my favorite slide talents are failures comments are a written expression of your incompetence this a good one is really good one why some of us have remorses when they finish writing some code and what did they do they drop a comment there and hoping the next one we understand and run away this is not because they know we screwed up what I tell you is don't do that take a walk use the bucket of work of clean cold water next euro in next to your desk you should let me clarify a bit the mind come back and refactor improve the expressiveness of the code why am I so it gives comments because statistically somewhere about fifteen twenty five twenty percent of the good developers always remember to update the Java dot when they change the implementation of something so inevitably the comments will turn will end up lying to you Ryan to you in the face telling you a story ten years ago or five years ago that even wise even intelligent eclipses display the comments in a washed away color not to disturb your eyes not to none because everybody knows that the oils too is the live running code all that is a part of that it's it man says it will not be specification observer that it all falls out of think the only thing that matters is the live code what I do what I what I ask of you is to improve the expressiveness what effect is that I mean really valid interest the one word in the array it's my god least one and the best thing is X of zero this is the ultimate stuff I mean it's of real really equals four really these are magic numbers that you need to explain the riddles of course then introduce new useless variables new explanatory variables to name some fun bit of computation for example is like equals cell of status equals light you see this is variable you would laugh at me but this will exist for two lines we will be tended to in line it to destroy it but no leave it like that because it turns something it fails that this means that the cell is flagged and this also please well when you have this if and then you start a boolean expression hit enter you continue or also end and enter and and a lot those right and you need to click on the bracket to see where it ends it is absolutely adorable so what I do about this I extract all the brackets as a temporary variable let's say I put them names and I then compose them in one single line to an incensed respect your predicate respectable on tests it really does that complicated that they deserve more than one creepy line introduce new variables to store the intermediary test now what I did next is I even created a method but who to host you you told you may laugh at me again but I created a method that does just get this bit or one line for 25 structures I created a method name is flat this is so frequent to you that it has a name this is called encapsulate conditionals when it will take a bullying condition put it in a method and give it a name I get this matter just to be more expressive what I mean and even now I even switch to object oriented stuff so now if I say that this is a bit of school from - eh but you won't be shot free I mean is game where the cell is like I know you can write this in one line with Java 8 but hold on this along with splitting your methods into multiple methods with long expressive names is the way you want to leave out behind you in a life documented to tell the very code explained in your intention cool now example of bad comments with this one it is my favorite now beside the fact that the author probably needed a professional professional counselling from someone in this psychology because this guy expressed his negative feelings in the code you should never do that it conveys your negative emotions to your reader never read how many of you have seen cursing and bad words in code in the production ball don't don't avoid that because it will make you read a selection so besides that what scares me most is that the fact that this might be a forgotten to do so as a minimum make sure you put to do and everyone to continue something this is it is matrix this is the victory of machine against human this is sonar teaching you how to program make sure you tune those don't follow rules like they make them work with you not against you this is a clear sign of a to long the class of courses should be broken up commander dart code is not there for you to read it is not there for you to uncomment it from duck deleted it is probably problem with that the gate is still there ok mum vocal if you really have to put a commented on the same line not a function not only class no on that line to be in front of the eyes of the reader and then if you really have a lot of energy don't describe to me what the abstract factory design pattern is in the Java doc or but are you are picky I know I did yesterday evening but don't explain it to me in two paragraphs perspective right so don't be overly effusive energetic test again now there are also examples good common see when you just can't say that you want to use jigsaw algorithms for navigating for traversing an oriented graph stuff that is too complicated to put it to express it in code there are occasions but then only put the URL of the thing that you wanted the bit to follow it may be a bug work around it might be some classic algorithm put the URL cannot now it really has to pass travel as an argument to a strange API explain what that seven means like may you can put some Java doc there in case you are in for what kind of developer profile will maintain your code you can leave behind this kind of I don't put simple days format or as a field in a class disk understands to do that followed by the name sometimes will meditate preparing for the debugger I mean delivery be public Java doc if you really have to write it write your own library make sure I mean you need to write more Javadoc just to keep the decline code the client developers out of implementation won't explain them as nice as possible well yeah I mean to avoid them to go into your implementation biggest okay now lightsaber will lower lambda right because they are cool I mean they literally caused a dramatic increase in the popularity of Java after they were introduced the thing about Java is that is the code cleaner than Java 7 that was my concern it can be more expressive but if you ability can even become very very very cryptic and I said several talks about this problem this topic and there are what are the best practices for writing clean code in Java all nowadays because time is running out just an examples here yes you see here this 4 dots has line not in stock is a method in the same class that hosts some bit of actually predicate in the in essence but this predicate is specific to the use case implemented in that class so it's no use of the braces and I put it as a private method in the cell plus then you can see here our deadline is not you stop this is an incomplete pretty a negatory conditional application which actually created the boolean function in this very entity then it can even work with predicate as long as variables that creepy but you can even do more can have found higher-order functions that return you parameterized predicate this is creepy it's supposed to be creepy if a predicate takes some parameters for example believe in two days before Sunday then this predicate cannot be writing the entity on anywhere else you have to have some factoring methods for the predicate it's pretty creepy I know so the point is you will work with predicate and respect your predicate work nicely with them generates of course is a new language it's a new paradigm shift loss little advantage actually it's switching slowly towards the declarative way of programming essential learning not only a new language but a new paradigm you need to know it all because simple against it simple is not necessarily what you are familiar with so we have to learn it first and then it may prove to you to be more simple but after you've learned that don't use lambdas able than the day before a adopted progress may be either in C maybe nine months in order for all the team to be sure that they understand what you're doing that then don't ever do Aero bracket in a way because that's an anonymous function you agree when you do that you are about to write an anonymous function and it's precisely my problem it's a nonnamous doesn't have a name and I will love names I love to be told what the function does so don't do that instead write a method in the same class and reference it from this using four dots in the name of the method don't do that much as possible use the map function and the flat map function of the optional learn about monads what you were told then finish about predicate a work with an eye like I showed you in the slide before and in the end find the simplest form ask for review from the other essential peer review is essential in the best form of peer review no I thought this talk this discussion over another peer review is equal to peer criticism to peer arguing to peer blaming don't it's better yet to have their programming to proactively better ways together and not have someone criticizing your code like so prefer to the program it is possible okay as the key points study factor equals start legacy and when you stop in fact if you put in the kennel and drink to that then names it's all about refining and continuously searching for better names in your code function should be small with long names and expressive names classes are of three kinds struct which are the best immutable objects which hide their data and their things inside a logic containers if you're a feature called lots of procedural code for formatting comments are failures admitted and prefer always to refactor to refine your names to express it in code with lambda if you're learning a new language a new paradigm make sure someone per programs with you daily profits good deal work this is a key point now how to apply this in mind or logistical I continue I contend to say that over and over practice practice over and over do cutters do dozers do go to code repeat days grow your skills is hard it takes months maybe years of practice but in the end you'll love it okay books books this is the Bible no developer can ever write any line of code until sis has finished at least half of this book at injera read book written I mean that was it thank you all for your attention a little of the infinity you
Info
Channel: Devoxx
Views: 26,150
Rating: 4.8827586 out of 5
Keywords: DVPL17
Id: AeWbJ5LIFNg
Channel Id: undefined
Length: 50min 28sec (3028 seconds)
Published: Wed Aug 02 2017
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.