Writing Clean Code
Md. Masud Rana
Agenda
● Types of programming
● Definitions of clean code
● Characteristics of clean code
● Example: Meaningful names
Programming!
There are two types of programming -
- Programming and
- Good Programming.
Programming is what we have all been doing. Now is the time to do good programming. We
all know that even the bad code works. But it takes time and resources to make a program
good. Moreover, other developers mock you when they are trying to find what all is
happening in your code. But it’s never too late to care for your programs.
Clean code
Clean Code — A Handbook of Agile Software Craftsmanship is a must-read book
for developers, especially when you want to be a better software developer.
“Master programmers think of systems as stories to be told rather than programs
to be written” — Uncle Bob.
Definition of clean code
“I like my code to be elegant and efficient. The logic should be straightforward to
make it hard for bugs to hide, the dependencies minimal to ease maintenance,
error handling complete according to an articulated strategy, and performance
close to optimal so as not to tempt people to make the code messy with
unprincipled optimizations. Clean code does one thing well.”
- Bjarne Stroustrup
Definition of clean code cont.
“Clean code can be read, and enhanced by a developer other than its original
author. It has unit and acceptance tests. It has meaningful names. It provides one
way rather than many ways for doing one thing. It has minimal depen- dencies,
which are explicitly defined, and pro- vides a clear and minimal API. Code should
be literate since depending on the language, not all necessary information can be
expressed clearly in code alone.”
- “Big” Dave Thomas
Characteristics of Clean Code
● Elegant: Clean code is pleasing to read, should make you smile.
● Readability: Clean code should read like well-written prose.
● Simple: Do one thing with the Single Responsibility Principle (SRP).
● Testable: Run all the tests.
An example: Meaningful Names
Everything in an application has a name, from variables, functions,
arguments, classes, modules, to packages, source file, directories.
Naming things is the most common problem of every developer. As Phil
Karlton said that:
“There are only two hard things in Computer Science: cache invalidation and
naming things” — Phil Karlton
Meaningful Names
It’s not only you, parents get difficulties to find a meaningful name for their child.
Finally
Names are the powerful way you communicate your code’s intent to
developers who read your code, including yourself. Choosing good names
takes time but make your code better and cleaner. It makes your code easy
to read by other developers, as well as yourself in the future.
Questions?
Who’s responsibility to make sure “Clean Code”?
It’s only you, you, you ….. and you. - Why?
Team member’s if you are working in a team - Why?
Your employer/Organization. - Why?
Your industry. - Why?
Thank you!

Writing Clean Code

  • 1.
  • 2.
    Agenda ● Types ofprogramming ● Definitions of clean code ● Characteristics of clean code ● Example: Meaningful names
  • 3.
    Programming! There are twotypes of programming - - Programming and - Good Programming. Programming is what we have all been doing. Now is the time to do good programming. We all know that even the bad code works. But it takes time and resources to make a program good. Moreover, other developers mock you when they are trying to find what all is happening in your code. But it’s never too late to care for your programs.
  • 4.
    Clean code Clean Code — AHandbook of Agile Software Craftsmanship is a must-read book for developers, especially when you want to be a better software developer. “Master programmers think of systems as stories to be told rather than programs to be written” — Uncle Bob.
  • 5.
    Definition of cleancode “I like my code to be elegant and efficient. The logic should be straightforward to make it hard for bugs to hide, the dependencies minimal to ease maintenance, error handling complete according to an articulated strategy, and performance close to optimal so as not to tempt people to make the code messy with unprincipled optimizations. Clean code does one thing well.” - Bjarne Stroustrup
  • 6.
    Definition of cleancode cont. “Clean code can be read, and enhanced by a developer other than its original author. It has unit and acceptance tests. It has meaningful names. It provides one way rather than many ways for doing one thing. It has minimal depen- dencies, which are explicitly defined, and pro- vides a clear and minimal API. Code should be literate since depending on the language, not all necessary information can be expressed clearly in code alone.” - “Big” Dave Thomas
  • 7.
    Characteristics of CleanCode ● Elegant: Clean code is pleasing to read, should make you smile. ● Readability: Clean code should read like well-written prose. ● Simple: Do one thing with the Single Responsibility Principle (SRP). ● Testable: Run all the tests.
  • 8.
    An example: MeaningfulNames Everything in an application has a name, from variables, functions, arguments, classes, modules, to packages, source file, directories. Naming things is the most common problem of every developer. As Phil Karlton said that: “There are only two hard things in Computer Science: cache invalidation and naming things” — Phil Karlton
  • 9.
    Meaningful Names It’s notonly you, parents get difficulties to find a meaningful name for their child.
  • 10.
    Finally Names are thepowerful way you communicate your code’s intent to developers who read your code, including yourself. Choosing good names takes time but make your code better and cleaner. It makes your code easy to read by other developers, as well as yourself in the future.
  • 11.
  • 12.
    Who’s responsibility tomake sure “Clean Code”? It’s only you, you, you ….. and you. - Why? Team member’s if you are working in a team - Why? Your employer/Organization. - Why? Your industry. - Why?
  • 13.