Clean Coding

Clean Coding

Clean Coding Tips

 

1.Variable, Functions, ParametersNaming.

2.Comments, Documenting Code.

3.Code Breakdown (also called SRP).

4.Code Readability.

1.Variable, Functions & Parameters Naming – The first thing we all face while writing code is

Flutter Clean Coding

Variables, Constants, Functions. These are the very start of your code. Naming it smartly will make it much much easier for you and also for the other developer working with you or reading your code. I had witnessed many developer mostly juniors/freshers making these silly mistakes while naming variable/functions and through the time this becomes habit “A BAD HABBIT“. This small but quite important tip couldn’t be neglected.

As you write code you name your variables and functions that you like. Instead, your naming should be this much good that it reflects its purpose. Same goes for the functions. Every function name should reflect its purpose. What that function does. Because you are not the only one who will be working on this or reading your code, who knows when others will have to work on it.

 

2.Comments, Documenting Code

 

Comments are your besties. When it comes to clarification of code sometimes naming couldn’t help you out. So just write comments wherever necessary. Comments can help us explain to other people why we wrote what we wrote, and why we wrote it in that specific way. As a result, other people will not have to guess. One important point to note here while adding comments to your code is always be clear and careful where to add comment and why you need this. Irrelevant or unnecessary commenting can make your code hideous

 

instead of clean code. Try to add short comments up to 2 lines.

Returns the magnitude of a vector in three dimensions.

func magnitude3D(x: Double, y: Double, z: Double) -> Double {

return sqrt(pow(x, 2) + pow(y, 2) + pow(z, 2))}

clean coding

 

3.Code Breakdown (Single Responsibility Principle) – This tip is very important for a clean code. Lets

 

discuss what SRP means. SRP is Single Responsibility Principle means one function should perform only one task. We shouldn’t create mess that we often do. One should break functions into subs and each will have its unique responsibility.

 

I noticed many in my company doing this (Sometimes me also). We simply write down a function and starts writing code in it no matter what the name is, we just put everything in it. They just become unpredictable.

 

Example – We write code for login. We created a function for login user.

 

func LoginUser(email:String, password:String)

{

if !email.isEmpty && email.isValid{ if !password.isEmpty{

Auth.auth().loginWithEmail(email:email,

password:password)

}

}

}

See here we named function for login but we are using it for validation and login. It should only login user. We can breakdown it into two function one for validation and other for login. Code readability will improve a lot and one can predict outputs, functions become predictable.

func validateInputs(email:String, password:String)->Bool{

if email.isValid {

if password.isValid{

return true

}

else{

return false

}

else{

return false

}

}

func loginUser(){

if validInputs{

Auth.auth().loginWithEmail()

}

}

4.Code Readability

The last and the most basic tip, is to keep your code as simple and readable as possible. Don’t get fancy if you don’t have to, and don’t over-complicate problems (a common issue among software developers). By keeping it simple you can produce higher quality code, solve problems faster, work better.

#Content Credit: Chanpreet Singh

160 thoughts on “Clean Coding

Leave a Reply

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

  1. hello there and thank you for your info –
    I have definitely picked up something new from right here.
    I did however expertise a few technical issues using this site,
    since I experienced to reload the website many times previous to I could get it to load correctly.
    I had been wondering if your web hosting is OK? Not that I am complaining, but sluggish loading instances times will
    very frequently affect your placement in google and could damage your high-quality score
    if advertising and marketing with Adwords.
    Anyway I’m adding this RSS to my e-mail and can look out for
    much more of your respective exciting content.
    Make sure you update this again soon.

  2. I just want to say I am newbie to blogging and honestly enjoyed your blog site. Probably I’m going to bookmark your blog . You surely come with very good stories. Thanks a lot for sharing with us your webpage.

  3. Pretty nice post. I just stumbled upon your weblog and wished to say that I have truly enjoyed surfing around your blog posts. In any case I?ll be subscribing to your feed and I hope you write again soon!

  4. Great beat ! I wish to apprentice while you amend your website, how could i subscribe for a blog site? The account helped me a appropriate deal. I were a little bit familiar of this your broadcast offered vivid transparent concept

  5. First off I would like to say great blog! I had a quick question which I’d like to ask if you do not mind.
    I was interested to know how you center yourself and clear your
    mind prior to writing. I’ve had difficulty clearing my thoughts in getting my ideas out.
    I do take pleasure in writing but it just seems like the first
    10 to 15 minutes are usually wasted just trying to figure out how
    to begin. Any recommendations or tips? Thanks!

  6. Wow, incredible weblog layout! How lengthy have you ever been blogging for?
    you made running a blog look easy. The full look of your website is excellent, let alone
    the content!

  7. Great goods from you, man. I have take note your stuff prior to and you’re simply too fantastic.

    I really like what you’ve obtained here, really like what
    you’re saying and the best way during which you say it.
    You’re making it entertaining and you still take care of to keep it sensible.
    I can not wait to read much more from you. That is actually
    a tremendous website.

  8. This design is wicked! You obviously know how to keep a reader amused.
    Between your wit and your videos, I was almost moved to start my own blog (well, almost…HaHa!) Excellent job.
    I really loved what you had to say, and more than that, how you presented it.
    Too cool!

  9. It’s actually a nice and helpful piece of info. I’m satisfied that you just shared this helpful info with us.
    Please stay us informed like this. Thank you for sharing.

  10. I really love your website.. Very nice colors & theme.
    Did you build this website yourself? Please reply back as I’m looking
    to create my very own blog and would love to know
    where you got this from or exactly what the theme is named.
    Thanks!

  11. Just want to say your article is as amazing. The clearness on your put up is just cool and that i can assume you are a professional on this subject.
    Well with your permission let me to grasp your RSS feed
    to keep up to date with drawing close post. Thank you 1,
    000,000 and please continue the enjoyable work.

  12. Attractive section of content. I just stumbled upon your blog and in accession capital to
    assert that I acquire in fact enjoyed account your blog posts.

    Anyway I will be subscribing to your feeds and even I
    achievement you access consistently rapidly.

  13. Nice post. I was checking constantly this blog and I’m impressed!

    Very useful info specifically the last part 🙂 I care for
    such information much. I was looking for this particular information for a
    long time. Thank you and best of luck.

  14. I was recommended this blog by my cousin. I am not sure whether this post is written by him as
    no one else know such detailed about my trouble.
    You are incredible! Thanks!

  15. After going over a handful of the blog articles on your web
    page, I seriously appreciate your way of blogging. I added it to my bookmark webpage
    list and will be checking back soon. Take a look at my web site too and tell me your opinion.

  16. I’m extremely impressed with your writing skills as well as with the layout on your blog. Is this a paid theme or did you customize it yourself? Either way keep up the nice quality writing, it is rare to see a nice blog like this one these days..

  17. Attractive part of content. I just stumbled upon your weblog and in accession capital to assert that I get actually loved account your blog posts.
    Anyway I will be subscribing for your feeds and even I success you get right
    of entry to constantly quickly.

  18. I have been browsing online more than three hours today, yet I never found any interesting article like yours. It’s pretty worth enough for me. Personally, if all website owners and bloggers made good content as you did, the internet will be a lot more useful than ever before.

  19. Thanks for your marvelous posting! I seriously enjoyed reading it,
    you can be a great author. I will ensure that I bookmark your blog and may come back in the
    foreseeable future. I want to encourage yourself to continue your great posts, have a nice weekend!

  20. My spouse and I stumbled over here different page and thought I might check
    things out. I like what I see so now i am following you.
    Look forward to looking over your web page again.

  21. This is really interesting, You are a very skilled blogger.

    I’ve joined your feed and look forward to seeking more of your fantastic post.
    Also, I’ve shared your web site in my social networks!

    Juventus ny trøje

  22. Thanks a lot for sharing this with all of us you really know what you’re speaking approximately!
    Bookmarked. Kindly additionally talk over with my web site =).
    We can have a link change arrangement between us

  23. Hello just wanted to give you a quick heads up.
    The text in your article seem to be running off the
    screen in Safari. I’m not sure if this is a formatting issue
    or something to do with internet browser compatibility but I thought I’d post to
    let you know. The layout look great though!
    Hope you get the issue solved soon. Cheers

    Everton tröja

  24. I’m amazed, I must say. Seldom do I come across a blog that’s both
    equally educative and interesting, and let me tell you, you have hit
    the nail on the head. The issue is an issue that not enough folks are speaking intelligently about.
    Now i’m very happy I stumbled across this in my search for
    something relating to this.

    Chelsea Ny drakt

  25. Simply wish to say your article is as astounding.
    The clarity in your post is simply nice and i
    could assume you’re an expert on this subject.
    Well with your permission allow me to grab your RSS feed to keep updated with forthcoming post.
    Thanks a million and please carry on the enjoyable work.

    Billige juventus fodboldtrøjer

  26. What’s Taking place i am new to this, I stumbled upon this I have found It
    absolutely useful and it has aided me out loads. I hope to contribute & assist other customers like its aided me.
    Good job.

    Maglie Psg Bambino

  27. Woah! I’m really enjoying the template/theme of
    this website. It’s simple, yet effective. A lot of
    times it’s challenging to get that “perfect balance” between user friendliness and visual appeal.
    I must say you have done a awesome job with this.
    Additionally, the blog loads extremely quick for me on Internet explorer.
    Excellent Blog!

  28. Hello are using WordPress for your blog platform? I’m new to the blog world but I’m trying to get started and create my own. Do you require any html coding knowledge to make your own blog? Any help would be greatly appreciated!

  29. Heya terrific blog! Does running a blog such as this
    require a massive amount work? I have no knowledge of programming however I was hoping to start my
    own blog in the near future. Anyways, if you have any recommendations or techniques
    for new blog owners please share. I know this is off subject however
    I simply needed to ask. Thanks a lot!

Please wait...

Subscribe to our newsletter

Want to be notified when our article is published? Enter your email address and name below to be the first to know.