1) Clean code is easy to understand, extend, and refactor. It has small, single responsibility classes and methods that work as expected and are easily testable.
2) To write clean code, follow principles like SOLID and Law of Demeter. Name things clearly and use verbs for functions, nouns for classes.
3) Functions should be short and do one thing. Classes should contain related variables and functions. Handle errors gracefully and return exceptions. Write tests that are fast, independent, repeatable, and self-validating.
2. Lack of etiquette and manners is a huge turn off.
KnolX Etiquettes
Punctuality
Respect Knolx session timings, you
are requested not to join sessions
after a 5 minutes threshold post
the session start time.
Feedback
Make sure to submit a constructive
feedback for all sessions as it is
very helpful for the presenter.
Mute
Please keep your window on mute
Avoid Disturbance
Avoid leaving your window
unmuted after asking a question
6. Clean code
● easy to understand the execution flow of the entire application
● easy to understand how the different objects collaborate with each other
● easy to understand the role and responsibility of each class
● easy to understand what each method does
● easy to understand what is the purpose of each expression and variable
● easy to extend and refactor
7. Clean code
● Classes and methods are small and only have single responsibility
● Classes and methods are predictable and work as expected
● The code is easily testable and has unit tests (or it is easy to write the tests)
● Tests are easy to understand and easy to change
15. Universal Principles to follow
● Follow SOLID principles
● Follow a Design Pattern if it fits the problem space that you are trying to solve.
● Follow Law of Demeter
● Follow TDD (Test Driven Development)
19. Cleaning Naming Convention
● Name should be simple
● Names should reveal intent
● Use pronounceable name
● Use one word per concept
● Use verbs for function names and nouns for classes and objects
21. Cleaning Functions
● Functions should be short as possible
● It should follow SRP (Single responsibility principle)
● No side effects
● No nested control structure
● Prefer less number of arguments
● Must only do what the name suggests and nothing else
● Should either do something or answer something, but not both
23. Cleaning Classes
● Classes should contain variables and functions that do one thing (SRP)
● The name of a class should describe what responsibilities it fulfills
● Do one thing (SRP) : It is forbidden to create classes that have many
responsibilities
● Variables should be private so that we can change their type or
implementation when required
● Classes should be small
● Classes should provide abstraction
25. Cleaning Error Handling
● Code should be both clean and robust, it should handle errors with
grace and style.
● Catch everything. Better to be safe than sorry.
● Be informative. Return Exceptions instead of Error Codes. Each
exception thrown should provide enough context to detect the error
root cause and location.
27. Cleaning Unit Tests
Clean tests should follow F.I.R.S.T principles:
● Fast: Tests should be fast. They should run quickly.
● Independent: Tests should not depend on each other. One test should not
set up the conditions for the next test.
● Repeatable: Tests should be repeatable in any environment. They should
run in the production environment, the QA environment, and even on your
laptop while riding home on the train without a network.
● Self-Validating: Tests should have a boolean output. Either they pass or
fail.
● Timely: Tests need to be written in a timely fashion.
29. Cleaning Comments
● The only truly good comment is the comment you found a way not
to write.
Don’t comment bad code, rewrite it
● Don’t comment bad code, rewrite it
● Explain your intention in comments
● Warn of consequences in comments
● Never leave code commented
31. Cleaning Formatting Skills
● When people look into your code, you want them to be impressed
with the neatness, consistency, orderliness and attention to
detail that they perceive
● You should strive to keep your lines short. You should never have to
scroll to the right.
● A function that is called should be below a function that does the
calling.
● Each line represents an expression or a clause, and each group of
lines represents a complete thought.
33. Conclusion
We can simple remember these points while writing code...
● KIS : Keep It Simple
● DRY : Don’t Repeat Yourself
● YAGNI : You Aren’t Gonna Need It
● Composition over Inheritance
● Favor Readability
● Practice Consistency