 All right, welcome everybody full room which is good at five o'clock usually it dies off a little bit I guess a lot of people have smelly code and we have here He's going to tell us about configuration code so Thank you Everybody can hear me especially from the back excellent Okay, my name is Tushar as he introduced me and I am a researcher in Athens University or economics and business Let's let me before I start let me do a quick reality check. How many people use puppet? Wow and Anything else any other configuration system and symbols here. Oh, that's also nice Excellent, so we are very much you are very much in the right room because I'm going to talk about puppet and that All this mess that I'm going to talk about they are more or less applicable in other configuration management system also So what I'm going to talk about smells in general configuration smells in particular I'm going to take a few examples and I'll show why we consider them as a smell and Towards the end of it. I'll I'll talk about Tools that we can use to detect these smells So Let's start with the term smell The term smell was introduced in this book by Kent back and chapter 4 of this book And he described it as certain structures in the code That suggests or sometimes scream for the possibility of refactoring This is an informal definition and I would like to Give you an idea a deeper idea better idea. What a smell may look like by and using an analogy and I would like to do using a I'm introducing a new word called Juga Anybody in this room has has heard of this word Juga Yeah, so Juga is I mean, it's okay because Juga is a Hindi word and by the way Hindi is If I'm not wrong fourth wide widely used language in the world after Chinese Spanish and English so This is this is the word from Hindi and which means a walk around a simple walk around or a heck this Whatever the definition is probably doesn't give you the sense what a Juga may look like So let me give you a few examples real world examples somewhere in somewhere in a student Some some student in night want to drink a coffee because he has some exam in next day maybe Java exam and Well, the canteen is closed in the night So well, he's using iron box to make the coffee. It's quite hot in India and if you Don't have AC and still you want to work on your PC then somewhat these kind of Arrangement you need to make to make your PC happy and yourself happy. This is what happens when you have to Whether and sister and then they have one room each and they want equal share of cold air so and By the way, if you don't recognize this, this is a pajama Well, so what if the clock is broken it it still works and you know, we can still Arrange something to make our goal The owner don't want to go to a service center and you know Spend money on the proper locking system He gone to a local store. He's just said, okay, put me a lock here and it in most cases it works Well, my aim why why I'm showing these pictures and why I introduce the a new word to you is because I think there is a relation between sugar and smells in fact, what I think is smells are jugard in software and Why I think so because Like smells jugard are temporary solutions You cannot use it for a long time They they serve some purpose. They solve some problem, but they introduce quality deficit It applies to both of them. I mean smells and jugards Although there is a big difference also So we need to understand that also because jugard come with a positive connotation and smells come with a negative connotation So normally jugards are considered innovative and when the resources are meager or limited however smells introduced gets introduced when The people don't have sufficient knowledge or they are ignorant still There are some similarities between both of these metaphors and that's why I think they are similar in nature and Let's talk about smell again. So smells Was introduced I as I told you that it was introduced in 1999 by in the book by Martin Foller and came back and then many people worked on that and If you look at literature, you will find at least 40 different terms Used for smells and I'm not talking about specific smells. By the way, they are many more these are the terms used to describe smells and I'm also I also work a lot from at least from last four or five years on on this topic and One of the things that I am proud of is this book Which I co-authored with my other two colleagues Which is on design smells the smells that may occur in design software design Okay, so but we are talking about configuration smells and before I introduce configuration smells to you Let me introduce Infrastructure as code. I guess it's not really required for me to spend too much time on Introduct introductory slides, but let me do it for the sake of completeness Infrastructure as code is a practice is a practice of a specifying computing system configuration through code automating system deployment and managing system configurations through traditional software engineering practices What I mean is that you Write if you want to have a server and which you want to make sure that a certain service is installed and work Running and you can write something like this. By the way, it's a puppet example So and all the examples that I'm going to show is is is pop are from puppet So you can write something like that. It's a very simple example Just to show what you can do and if you want to create a new user you can write something like this and you can specify the properties of the user and You are done and the puppet will take care of how to create and how to do that. You just specify what you want and Obviously, there are many more Some of them I just mention I have mentioned here, but there are many more and in the context of traditional software engineering what Infrastructure as code does it brings Infrastructure configuration code tools and services in the purview of software system what it means is you apply Traditional software engineering practices not only on production code, but also on infrastructure and configuration code and When I say traditional software engineering practices I mean like testing reviewing versioning and many more Similar practices and this is the time to introduce configuration smell Well, this is a big definition But probably two most important things in this definition is that it violates the recommended best best practices So which is these are the best practices are coming from the experiences people like you they have a lot of experiences in writing puppet code or in general configuration code and they They they derived some best practices. So these are the best practices if a newbies walleting these best practices basically He's actually introducing configuration smell and these are the smells that why we consider them as a smell because because they affect programs quality in negative way Now what we have done me and my colleagues and my university where I work that we collected all the resources started from starting from puppet Puppet website which specify how to write what would not what not to write and things like that and many other blogs many other books And we consolidated and prepared a catalog of smells Both and and we classified them as two types of smells configuration smell one is implementation Configuration smells and another one is design configuration smells. So implementation configuration smells deals with the local locally locally a local impact like styling indentation and Something like that naming convention and the design configuration Design configuration smells deals with the deals with the the module structure and And the structure of the repository and things like that So what I'm going to do is I'm going to take a few examples in both the categories And I'll show you what are what we considered as smells So this is a piece of puppet code. So let me go one by one so in puppet import is Deplicated and so if we use and probably there are there might be many other Statements which are deplicated. So when we use deplicated statements to introduce smells To do or fix me You might almost every developer in the world has at least one or two Do-dos in his code. So which which signify that you want to do something, but you are waiting for some golden time. So That's that's indicate that that's the incomplete task and we consider it as a smell If you have a long statement, it's difficult to read difficult to understand And if you have more than a certain number of number of operators in a same expression Then we also consider it's a smell Well, you use case statement, but you forget to write default then it's Wow, that's okay. It's the admission that okay. I'm doing that Deplicate entity you have a same attribute to specified multiple time Missing conditional when you have a else if but you don't have leading else So if you don't have leading else, which means that probably you should make this else if as a else There are certain conventions When it comes to usage of quotes and especially in puppet So when to use single quote and when to use double quotes and when you violate that those those best practices Then you introduce improper quote usage smell Same applies with the usage of variable So you need to guard the variable if you are using and and quotes so that's another smell and Alignment although it may look very trivial, but alignment is also Makes it a little bit difficult to read if you have don't if you don't don't align the lines in your code and Invalid property value, so you supposed to specify the property value using four digit octal number rather than three digit as it was it is done here and Misplaced attribute so the required attribute Must come first and optional attribute attributes should come later So if that's got violated then you introduce that smell similarly let's take some more examples for design configuration smells and as I said that design configuration smell deals with Module design and the structure of the project or the repository and what I'm going to do is I'm going to show some Code something like this and I'll ask you please feel free to say what you think about this piece of code so okay, there is a file and Puppet file and then you see something like this you have class declaration again class class class Or take a look. This is another snippet You have a class and you have certain resources Described so you have some one package service service package file user What you see what what what could be a problem here? Mm-hmm. Yeah they I mean These these two things are related with Apache, but okay This is my squirrel as we can see this is PHP and many other things So they don't go with each other. They are not cohesive with each other and when we say when and and people who are Who code in traditional software engineering languages? We know that that's a that's called single responsibility principle What if we write a method or a class that's supposed to follow single responsibility principle and when that gets violated? We introduce multifaceted abstraction and by the way this character is from Indian epic called a called a Ramayana and this the name of the character is Ravan who has ten heads and which is which I have put it to Show that it's a multifaceted It's doing too many things Okay, so let's Let's let's take a next example What's the problem? There is nothing right Why somebody has written a class and put nothing in that? You might find it a very You know trivial or very weird that why somebody will create a class and not write anything inside that And I was also like I was also shocked when I said this could I mean who will do that? But we actually analyzed more than four thousand six hundred puppet repositories from github and we found More than four thousand three hundred such instances So almost one instance per repository on an average on an average So it's there are many people who is doing this And I mean as you can guess it's unnecessary Whenever we Specify class or define we supposed to you write something in this obviously It's very trivial to to observe this that write something. Otherwise, maybe remove this. There is no purpose for that This is interesting What you observe here? Yes. Yes But is there any problem so what objects are allowed in puppet? Excellent, that's not declarative puppet by definition by natively, it's a declarative language what it means is that you supposed to specify What you want? What you want? It's not it's not as you're not supposed to say that exactly what you want to achieve How you want to achieve that that's not your job? you just need to specify to puppet that what precisely you want to achieve and Obviously, you can write some exact statements It's sometimes it's required actually to write exact statements But if your whole repository is containing only exact statements, then probably you are Walleting the semantics of the puppet and that's what we call imperative abstraction Smell when it is statements on the and the code is more imperative rather than declarative What do you think about this? Yeah? No class we have resources defined But they are loosely defined in a and hanging in the in the module Why not when when the language supports abstraction? I mean in form of class and define why not use them and Use and encapsulate them in a unit so that if you require we can use them or refer them wherever it's Whatever you need it So that's called missing abstraction Smell configuration smell This must be very simple anybody Yeah, they are same. They are clone. They are duplicate So it happens in even in configuration code. We have seen in normal production code, but it also happens and configuration code and it's it's it's it's when when you have a certain piece of Number of statements Duplicated across the repository then it's possibly you are missing an abstraction Maybe you need to accept that those Duplicated statements create an abstraction and use reuse whenever you want. I know you can't read it, but That's you are you're not supposed to read it Because this is what happens you open a file and you say, okay first resource second resource third resource and then you go go on and go on and you see the the scroll bar and it's very tiny in your text editor and that's Actually after after following a few resources you forget what was in the top and That's because in general we say in human cognition that a normal human mind can remember only seven plus minus two things at a time So if you increase, I mean if you have say hundred resources defined in a single file Then it's it's impossible for anybody to remember what was there and where was there and if you need to change something then where to change and that we call insufficient modernization and That happens when you have When the abstraction is large or complex and thus you can actually decompose the abstraction make it smaller This is related to the structure of the repository So when you have one module design and or The repository design in a some one way and another module in another way The structure is different in the same repository or in your project that if there are multiple repositories one Repositories following one kind of a structure and another repository is containing another following another structure then it's very difficult And if you don't many times people don't have defined structure, they just keep putting the module definitions or Or the file relevant file in just dumping in a single folder if you have something like that it's a It's it's basically an instruction module so you need to have one single consistent Structure for the repository and then you follow it across all your projects So for example, if you have modules and then you have Settlet folder for each module and you have Certain structure something like this Then and then and you follow the similar structure in the rest of the modules then it's okay But if you don't follow that then You are introduced introducing this method. What is this and who were tells me? This is a dependency graph and who was tells me that? Which software I'm talking about I will give you a book first one No No, who's at J unit? Okay. This is the dependency structure of J unit and You can see this that you can't make sense of I mean at least immediately You can't make sense of what's happening and who's depending on what? You need any a normal person need require some time to understand what's happening here and Probably in our projects also if you go and generate something like this some some diagrams something like this Then you will find something close to that. I'm sure about that and When something like this very dense happen we say it's a dense structure smell and I Mean it's basically the the repository has excessive and dense dependencies to different modules it's There are two scenarios here in the left-hand side. We have some resources rafting to each other and there are many references to other modules in the right-hand side there are more references inside a module and lesser outside the module and in Traditional software engineering we call it these concepts as cohesion and coupling So when a unit has a resources, which is tightly Related to each other we say it's showing high cohesion and when the same module it's showing It's depending on a lot of other Modules then we say it's showing high coupling and This is what we captured in this smell. We say it's a weakened modularity when it is a computed like it's a ratio between cohesion and coupling and It happens when when a module is exhibiting high coupling and low cohesion Okay, so at this point Let's take a step back and think about it Why smells are Important, I mean you may think that some of the smells at least some of the smells that we've seen they are very trivial Think for example alignment. It's very trivial and you probably ignore it But think about it why it is important to Consider the impact of a smell out of a story of a camel whose Back was broken by the straw Yes, so the straw if you look at the individual straw It's very light You can't imagine anybody can't imagine that a stroke and my break a Break the back of the camel But obviously there are many many things and if the straws are many there are many straws that are there That make it possible to put a one more straw and the camel's back is broke The same analogy applies to smells if you look at individual smells, they are very trivial many a times You think okay, this is not really I should be caring about but the cumulative effect of the All the smells in your system might be something like this So that's that's why are the considering smells detecting them and and avoiding them It's in my opinion. It's very important Okay, so we have learned about a few smells that may occur in configuration code How we can detect them? There are at least two tools First one is puppet linked. It's not our tool but we have used it And you can detect many implementation configuration smells using this tool the second tool is puppeteer Which I wrote majorly with my one of my more colleague in university and It's an open source tool. You can download from here You can clone it. You can fork it. Whatever way you want to use it. Please feel free and This is the tool that That can detect all the smells that I described You can detect all of those smells in puppet code So feel free to use them We also carried out a study Since we are at my default researchers So we carried out a research on puppet code and the quality of puppet code and we Analyze more than 4,600 repositories More approximately 9 million lines of puppet code and we found many interesting patterns there So if you are interested in that study This is the link you can download the paper and you can go into the details All you can write to me or you can call me and we can have a discussion So let's summarize What we what should I put it here? Please be louder. Hey. Yes here as and I'll here Puppet here. Yes, and what you get is maintainability Okay, that's it folks If you want me if you want to troll me This is my Twitter account if you want me if you want to troll me privately This is my email address if you want to physically troll me you can come here and you can talk to me