 Well, it's great to be here big room lots of people hello today I'm going to talk about coding combinations, but first let's start with about myself. My name is chill My pronouns are she her You can find me on github Twitter or Mastodon and I currently work as a lead backend engineer at Kraken tag meet Kraken He's our mascot and keeping me company during this talk Also, I edit logos of all the other affiliations Not all some that I love most Some you might recognize I Am doing Django development since 2008 and Since last winter, I'm serving at the Django software Foundation Board of Directors. I'm the vice president The other logo with Python it's It's cuz could you see from Istanbul? I'm one of the organizers of PyCon Turkey Also, I'm the co-organizer of London Django meetup since 2018 Proud member of PyLadies London. I'm hoping to meet with some of you in PyLadies lunch tomorrow Also, yeah, I'm a long-time young girls Workshop organizer. So if you want to have if you want to ask any questions about those affiliations of mine Feel free to find me after the talk or tomorrow and Let's kick it off. So today. We are going to talk about coding conventions But what are coding conventions? So coding conventions are like the Zen of Python if you know about it like Beautiful is better than ugly explicit is better than implicit Simple is better than complex and I was preparing this talk and I was like, where am I going to stop? If somebody doesn't stop me, I can go and list all 19. I'd love them. But yeah similar to Zen of Python like It's a list of references and Those are like things that we keep talking about improving in our code base and keep talking about improving and keep talking about improving notes comments that We copy paste all the time like I don't know you like I have this big sheet of code review of Notes I use very frequently copy paste them the list changes very slowly Sometimes we have designed an architecture discussions and when we reach a consensus If we reach a consensus we really create a coding convention out of it and also if possible introduce a Custom linter Basically, it's it's a laundry list to follow for us to keep our code base clean Why why do we use it so as I mentioned it's it's a list of guidance like it's It's not a mandatory list. It's a guidance and Why do you use it? I in crack and tech I work with Lolli engineers. We are all Brilliant, but we all come from different backgrounds. We all have different coding practices patterns preferences and They're like 400 500 of us working in the same repo same monolith Django Python repo and It's a cause if everybody brings in their own way of coding into the code base So coding conversions gives us guidance Ways of working together better It also gives us directions direction like, you know, sometimes when like you're building something you need to make a Decision like Can be as simple as shall I use this library or that library, but it's a decision You might have a preference Sometimes you don't have a preference at those times both sides be used coding conventions like if There is a preferred way of doing It should be there noted so we know What to choose I also find it quite a good way to give feedback like I think Giving feedback using coding conventions is very easy and smooth Also receiving feedback into my experiences like quite a nice May I think it's mostly because Those conventions a handshake of all team Long before that PR is created. So it's not a personal feedback. It's a It's a convention team already handshake. I think that's that's why it's a really easy way to give feedback to each other and How we use coding conventions we usually just use them during code reviews we add a link to the relevant coding convention and Like at a quick note, we also have emojis like convention emojis like if I put The three book emoji it means can we please add some dog strings here short and easy There's a section about in the dog Conventions everybody knows about it. It's a like single detailed explanation In the code information three foot that we can refer from Plur requests Also, like it's not very convenient to write To three paragraphs in a code review like it's not for teaching But this is a good way like their references there and you can just like point to them and another point is like When he like it has a snowball effect when we want to change something in the code base Can be an anti-pattern or we used to do it this way and it doesn't work anymore We want to do it that way now or there's a new library for it. So we introduce a convention and Usually when I don't know if you experience this type of changes But when you introduce a change there are usually one or one person or a team of people trying to push that change and If nobody pushes it doesn't happen but with coding conventions it has a snowball effect that Not in days, but in weeks like all teams starts to push towards that change you give it as a feedback to Colleague they give it as a feedback to other and like in two weeks You see that person that you are hundred percent sure didn't hear about this no new commission You never chat about it with them and they're like advocating it asking other colleagues to Start using it make changes It's like super nice. I'm not suggesting that you just introduce coding conventions And you can type check your Python repo in three months. It doesn't work that way But it has a high impact and Another thing is we introduce coding conventions and Not necessarily in their best form, but during by time like Either by experience or with more input like we can always go back and change it. So like maybe it's Stars like this good and it always like gets better because you keep changing we keep changing with wording We keep changing giving examples Or somebody which a little bit more knowledge about that topic joins the team and has a new Perspective So they're ever evolving and is also quite good and important and yes So let's look at some example conventions. So we're going to go over nine not ten it's my top nine If you will choose you will definitely choose another set if I will choose it last year I'll definitely choose in a different list or if I will choose it next year I'll definitely choose a different list, but this is what we have at the moment. You know to play with me. Let's go So the first one is About standard comment message format. So At first look it's easy Okay, use a summary capitalized short and Add more detailed expanse or text if necessary. I Have seen I Start to use this a year ago when I joined crack and tack and back then it was difficult for me. Like I feel like I'm just like feeling in a form Just repeating some birds from my function names Didn't Feel comfortable Didn't feel as I was doing a good job but By time I learned how to use it and it taught me how to write better code because We don't write code only to deliver features We write code so that like all of us Can work on a code base together and deliver features together So half of the time you build a feature but other half of the time you write code for other people other developers to build on top of it build next it and If I'm writing the code for others I Should also write some notes to others like what does this code do and Why it's introduced now not last month or why it's not happening next month. So let's let's take a look so According to the template the Message should follow the sentence if applied this comment will Add use case to record a good good sales chart. Okay. It adds a use case Why is this change needed prior to this change? We didn't have a use case to save charges that are created under a purchase object. Okay, and who Well, how does it address the issue this change introduces a new use case which creates charges then also we added a test This gives a good history. So when I go back when somebody or I go back later I why tell this make this change? There is a clear explanation and by time I've seen it on a Me and on each team member. I work with you start to Write better call better code more explain a explainable code and when you deliver it with a message like this, it's super Easy for others to understand it more. So if you're going to leave the talk with like one thing Let it let it be this you can also find this template in Look why they've been to bottom the titles a useful template for comment messages you can set it as a template and like every time you do git comment this template will show up and Definitely use it because like I started using it a year ago Still if I don't have the template, I don't follow the schema and like magic doesn't happen So strongly suggest you to start using this template in your get comments Okay Next one. So I said the list would be different like last year. This was two years ago. This was on top of my list I wasn't even working in crack and tack back then. I was with another company. We were using conventions there as well So make each comment automatic What does it mean? It means like in every comment the test it should pass and you should deliver deployable production code one change But a comment shouldn't break your court. I Think it is very very very useful Changing one thing at a time makes Reveal a lot easier Also, it makes you deliver robust and organized code. So Second top of the list Try to follow it Would it it's a recommendation from me. It really improves the code base quality a lot Next one Naming conventions, I don't know you but I quite So I'm not a native speaker and When I'm naming stuff, I have a hard time. I used to have a harder time Still and this one like I keep coming back So it says favor singular nonce for class names. So let's say you're creating a Product model if you call it products, then you have to say This object is a product But if you choose as your class name Singular non-like product then it's grammatically correct to say this object is a product also, like I don't know if you also experience the same thing I find myself trying to write that type of Function names a lot like get user details list like Pull a roll then list like what's it then like then you need to resolve it Because the list will return details not a detail. So it's like It doesn't work. So I quite like Combination to you more naming conventions. So I don't know you but I Also have a problem with dates like whenever I need to name a date. I'm like what should I pick the name as and In I get Incredible tech the main repo we work with has like 1050 tables and it saves me a lot of time To know that I can find the created at timestamp under created at field at each table It saves a lot of time Pick one Try using it. It will keep your code base consistent and you can introduce more naming conventions, but This we are moving away from naming conventions So Another one So it gives us guidance when we I said when we need to make a choice between one pattern or another This is another one. I like I quite like This keeps our module namespace out cleaner. We Import we do import modules. We don't import objects also like if you have If you have a little bit doesn't have to be a big corpus a little bit Mid-size code base it also helps with like, okay, this X module but X object what which module that I imported from so I Think this also makes Makes reading code a lot easier and it keeps a consistency between files as well So another favorite of mine and it Goes on. I don't know if you also had problems with mock patch But it also helped me solve all my nightmares with Mocking objects in the test it Helps to write simpler and isolated unit as so really really recommend this one also so No guidance so not all conventions work all the time Mike, okay, we can Import modules not objects, but are we going to do it like all the time? No, like this is the next convention. It tells you okay Sometimes it doesn't make like for example if it's a standard library object or etc It's still okay to do it and there are some examples. So like You don't have to Give very specific Direction and stick with it. You can like create on the directions detail it give examples and Now everybody's happy Another one I quit Like telling the story is like this is coming from It's very recent. We had an instant a few weeks ago Not an incident like we woke up one morning and a few of the will a few developers couldn't fetch anything from get up They were receiving an error about reference error We do deal with those type of problems over slack So there was a slack track like 7 to 1 messages like not one liners to paragraph one paragraph like long messages 7 age senior developer spent. I don't know how many hours to fix this problem. That's blocking I don't know how many developers for a couple of hours and at the end I it turned out somebody a pushed a Branch using upper case version of a common prefix we use in branch names and It's okay. All Linux systems, which is a case sensitive Like there is it was for the French So it says Fred in capital something else Fred on Capital something else. So Linux is very happy Under uppercase Fred. There is these branches on their lower case FRI there are other branches, but on Mecos I own Apple which has a case and sensitive file system There is this suffix with this list of branches under it and Exactly same keyword with a different list. So like it didn't know what to do Now we have a convention. So we only use lower case branch names and also we introduce Linter so that you can actually push uppercase branch names Pipeline will complain you cannot merge your branch. So I think it's not pipeline It's a precom it took but we also have a check for it now. So That's also a good example how we use coding convention and how they will Another one I quite like Do not surprise your reviewers with urgent complex pull requests. So Yeah, if you have a time sensitive pull request ask for feedback earlier and Let's change it if you have a Mid-size to big-size Pull request doesn't have to be urgent ask for help earlier Why because you don't want to surprise your reviewers? I don't know if it was this Convention is it was after this convention or not, but like our team has this good Tradition like you can totally open a draft PR Which means like you're asking for early feedback and the reviewer will probably Give you The reviewer will give you Some feedback towards the direction of the code and not going to like tackle with all the details because They know that that's an early version and you will send Final version before you merge it. So complex PR urgent or not Ask for feedback as early as possible and The last one. Okay. We said we are not writing the code only for delivering features a building software We write it for each other to build Top of it Doc strings, I'm not going to tell you about Why you should talk strings I'm going to Tell you how this convention helps my team to write more doc strings. So actually In the code base, you don't have to write doc strings for every function Just one set of functions. We call them use case. It's at the application layer Because those are important functions to the system But other than that, this is just the guidance But it really helps like it gives you a starting point to write doc strings and I Imagine someone just telling you, okay, just finish the sentence This function will you can finish the sentence and it's as easy as writing the doc string When you have this convention, somebody shares it with you It goes on a bit We actually have very explicit like Definition of how you should write it it really helps like I Already told I'm not good at picking names. I'm not also good at writing doc strings, but with this It encourages me a lot to write more doc strings. It's easier. There's a template. I use it You might be great and very dissimplified in writing doc strings But don't remember you might have like fellow colleagues like me a little bit encouragement Makes your code base a lot more better And This is the end of our examples. Let's Move towards last section. So what you can take home You can take home the conventions So I told you I think I started using coding conventions three years ago. What I did is I Didn't know this will happen. What I did is like a There's this open source Github repo with a set of conventions that crack and type team uses Two years before I joined the team. I didn't know about this repo. I just forked it. I Think I I keep 70% of it because they're good conventions and we Did it the other 30% we add our own and how it work with us like I Introduced it and asked my other team members to start contributing it and I mentioned before like it's a it's a great way of receiving feedback. I don't know like this is just one experience I had but they they loved it. They really almost like instantly Accepted it and they started to like also make like suggestions. I'm like, okay, that's a repo If you have a suggestion open a PR and we will discuss and change the or add the convention and Yeah, it really worked fine. So you can just make it your own And another thing I think like Again, it's it's not a monetary list. It's a guidance and I we is it doing code reviews But we also try to introduce like Linters and auto formators for some stuff you should don't need to write a convention even you can just introduce at a auto-formatter to your pre-commit or pipeline and It will do most of the work, but for example, I don't know if you can read it, but this is custom flag a check So it it runs This application This custom check on application layer use cases use case functions. So I each line represent one rule from the doctrine convention I showed earlier like and Step-by-step line by line like first line should be in and pretty much first line should end with period and I find it quite useful and I Also figured writing custom linters is not that difficult that might be another Topic for another talk, but today I'm going to finish With a quote from our internal the private coding conventions repo So it says Everyone is happier when the code we interact with is clean and consistent Even if it doesn't match your own style perfectly Consistency is the most important thing and that's all for me. Thank you very much for listening. I have one question though Like the previous talk like which one would be the 10th of the conventions Which one would be the 10th of the convention the next one? The next convention. Yeah, that's I Don't know probably somebody's like already introducing something. I Don't know Maybe we can discuss it later because I have another million of questions I would say let's give an applause for that's all Thank you very much