Xamarin

4 tips for writing cleaner code 🤓

Howdy!!! 🙋‍♀️ For today’s post, we’ll be learning about some tips that are extremely important to keep in mind for developing an application.


Let’s start!

1⃣Indentation above all  📝

A good indentation can make the difference between whether our code is readable or not. Let’s look at the example of both scenarios presented and think … which one can we understand faster? … 🤔 In the second scenario, we can see how a simple thing as indents, can improve the readability of our code.

La imagen tiene un atributo ALT vacío; su nombre de archivo es Screen-Shot-2020-12-12-at-9.17.34-PM-1024x352.png


2⃣Don’t accumulate commented code, if you no longer use it delete it 🤷‍♀️

Please keep your code clean. Version Control Systems hold the history of the code, so If you wrote and code and then for some reason you are no longer going to use it, it’s good practice that you delete it, not stacking unused and/or commented code blocks.

La imagen tiene un atributo ALT vacío; su nombre de archivo es Screen-Shot-2020-12-12-at-8.48.01-PM-1024x466.png

Let’s imagine the example of the image above, it started by implementing the Grid with the old structure, but then the optimized Grid structure was implemented!! 🤩 For this reason, the code block of the previous Grid was commented on by the new one !! …🤔 But in the first scenario, the implementation of the previously commented structure is left. To keep our code clean we must delete that commented code, in this case, another solution was implemented with the same results, therefore there is no reason to have those lines of code that we will no longer use.


3⃣. Use intuitive names for xmlns namespace prefix

Naming is an important aspect of writing cleaner code, it’s important that developers that read your code understand what does it do, so, when adding a namespace it’s important to use an intuitive name for it, so that throughout our code we fully understand why we are using it.

La imagen tiene un atributo ALT vacío; su nombre de archivo es Screen-Shot-2020-12-12-at-11.35.30-PM-1024x258.png


4⃣. Naming of Pages and ViewModels

In both when creating a Page or a ViewModel, make sure of the following points:

➖ The name must be intuitive and consistent with the functionality / Design.

➖ Additionally, at the end of this name, add the word “Page” or “ViewModel” respectively.  For example: TalentPage or TalentsViewModel.


Thanks for reading ?💕!!

Spanish post: https://es.askxammy.com/4_tips-simples-para-escribir-codigo-mas-limpio/

Tagged ,

Leave a Reply

Your email address will not be published. Required fields are marked *