0% found this document useful (0 votes)
4 views10 pages

Coding Tips 1673023474

H

Uploaded by

lillypons94
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views10 pages

Coding Tips 1673023474

H

Uploaded by

lillypons94
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

@Aakash Kanojiya

Tips for writing


Readable Code
@Aakash Kanojiya

Code is written once,


but read
Multiple times
So it is important to write source
code that is easy to read and
understand

Here are some quality tips ->


@Aakash Kanojiya

01
Keep functions and
classes small
Smaller units are easier to comprehend
mentally. I personally breakdown a
function into multiple if it grows beyond
10 lines.

It also makes it easy to test.

Each function should do only a particular


thing.
@Aakash Kanojiya

02
No Ninja Code

Prefer mode readable syntax over shorter


syntax.
@Aakash Kanojiya

03
Avoid boolean traps
Take a look at the following function and try
to guess what true it does

Such arguments can be replaced with


named arguments, configuration object or
builders depending upon the programming
language.
@Aakash Kanojiya

04
Avoid magic numbers
Numerical value that are hard coded are
called magic numbers - they don't clearly
convey a meaning.

They can be replaced with named constants.


@Aakash Kanojiya

05
Avoid deeply nested code

> Nested code is hard to read and follow

> Breaking down functions into smaller


functions help to flatten the code.

> You can also you the early return patten,


where you handle negative conditions first
and exit the functions to avoid nesting
multiple conditions
@Aakash Kanojiya

06
Proper variable naming
Variables and functions should be
named sufficiently clear to convey what
they represent and do - but do not use
unnecessarily long names.

Avoid abbreviations

Be consistent in naming For eg : do not


use displayX, printY if both do the same
thing
@Aakash Kanojiya

07
Sufficient documentation
& commensts

Document functions with a brief


description of what they do, input
arguments, return value and exceptions
thrown if any

Use comments to add more clarity to


code where necessary
Thanks for reading !
Follow my profile for more
coding related contents

Like and Share the post


with your network
@Aakash Kanojiya

You might also like