0% found this document useful (0 votes)
113 views2 pages

That Humans Can Understand. - Martin Fowler ": 4 Simple Ways To Make Your Code Cleaner!

1. The document discusses 4 simple ways to write cleaner code, including using meaningful names for variables and functions, writing smaller functions that do one thing, having classes with single responsibilities, and applying common design patterns. 2. It emphasizes writing descriptive names, breaking functions into smaller pieces with fewer arguments, and having classes focused on single tasks. 3. Design patterns like singleton, factory, adapter, and strategy are recommended to make code cleaner and more reusable. The document advises refactoring code over time using these techniques.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
113 views2 pages

That Humans Can Understand. - Martin Fowler ": 4 Simple Ways To Make Your Code Cleaner!

1. The document discusses 4 simple ways to write cleaner code, including using meaningful names for variables and functions, writing smaller functions that do one thing, having classes with single responsibilities, and applying common design patterns. 2. It emphasizes writing descriptive names, breaking functions into smaller pieces with fewer arguments, and having classes focused on single tasks. 3. Design patterns like singleton, factory, adapter, and strategy are recommended to make code cleaner and more reusable. The document advises refactoring code over time using these techniques.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

4 Simple ways to make your code cleaner!

“Any fool can write code that a computer can understand. Good programmers write code
that humans can understand. -Martin Fowler “
In software development, clean code is a widely used term and to be a good software
developer, the concept of clean code is must-have knowledge. But it is not an easy task to be a
clean coder as software developers need a big amount of time to learn and practice clean code.
It is a myth to write clean code at the first attempt even if you have great knowledge of it. It is
an incremental approach to make the code clean which needs time to time refactoring. You
need to invest a good amount of time to learn and practice them. But there are few of them
which can make your code easy to understand and more maintainable with very little effort. I
must say these are the only basic level of refactoring approach to make your code clean.
We will discuss 4 of the easiest approach to make the code clean, understandable and easy to
maintain.
1. Meaningful Names
Developers sometimes hesitate to write long meaningful names to introduce variables, classes,
functions which makes code difficult to understand. Software codes are like writing literature,
so take your time and think carefully to write meaningful names. A meaningful name is the first
impression in any code to understand the intention of the programmer. So, don’t write any sign
word, rather write meaningful names whatever the length is.
2. Functions
We write functions everywhere in our code. So, writing functions effectively can make your
code very easy to understand and representative.

 “the very first rule of functions is that they should be small”- Martin Fowler. Yes! If you
can make each of your functions smaller, then you can achieve the first level towards
clean code. Try to keep your function as smaller as possible and it should hardly ever
reach 15 lines but I recommend a maximum of 10 lines of code.
 Your function should do only one thing. Review your functions and ask if that describes
more than one thing. If yes, then break it and asks again the same question and take
action.
 Each of your function should express the same level of abstraction.
 Your command and query task need to be separate
 Try reducing the number of arguments to at most three or if possible two. If you need
a greater number of arguments, you can make it as object/model but if you cannot do
that, then they are a good candidate for separation with different functions.
 Your function name should be self-descriptive that by reading the name anyone can
understand what it does. Even when you write the function name you can easily
understand if it does more than one thing and will prompt to break into two.
3. Classes
“One responsibility one class” is the first thing come to mind when thinking about a clean and
good design class. The length of the class will depend on the description of the class name. If
the class can be written to describe only one task then it will force the developer to write code
of the same abstraction level. Simple and clear, just write functions, properties that will
describe only one responsibility. Unfortunately, bad developers are afraid of breaking one class
into multiple which leads the code very undisciplined and hard to understand.
4. Design patterns
Design patterns is reusable solutions to solve some existing problems. There are few categories
of design pattern and very much important to write clean code. Among them try to learn and
implement the Singleton Pattern, Factory Pattern, Adapter Pattern, Decorator Pattern,
Strategy Pattern, Observer pattern are frequently used and easy to understand. Lean and apply
the concepts and your code will be more beautified and cleaner.
It’s not possible to achieve the goal of clean code for the first time. So, write them first to
complete the requirements and then take a little time to refactor codes with the above-
mentioned concepts.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy