ChallengeRocket
  • Product
    • Recruitment Challenges
    • Skill Assessment
    • Direct Hire
    • Hackathons
    • Intern Challenges
  • Challenges
  • Case-studies
  • Employers
  • Log in
  • Join talent network
  • Book demo
Menu
  • Home
  • Employers
  • Robert Bosch Sp. Z o.o.
  • Inspirations
  • 3 basic rules of Clean Code
Robert Bosch Sp. Z o.o.
  • About
  • Jobs
  • Inspirations 9
Robert Bosch Sp. Z o.o.

Robert Bosch Sp. Z o.o.

Invented for life
Robert Bosch Sp. Z o.o.
  • t
  • a
  • n
  • t

202 followers

Warsaw, Poland
www.bosch-career.pl/IT
Company size
400,000
Industry
Engineering and Electronics
  • About
  • Jobs
  • Inspirations 9

3 basic rules of Clean Code

b
bosch
Dec 07, 2020
3 basic rules of Clean Code

Developers write business ideas as code. Sometimes we don't realize that our code can be clean and more readable. Clean code is the way of creating elegant, readable and testable code. Applications written according to clean code rules are easy to scale, pleasant to work with. Proper naming of variables, methods, classes as well as keeping application layers in order is very important.


Do you need a clean code?

Here is the clean code main idea: anybody who will ever read your code, will know exactly what was your intention and what code is doing. Code is explaining itself by good naming. Sounds legit, right? But why exactly? Why do we care if code is self-explanatory?


Before I answer, please ask yourself: “How much time I'm spending on writing code, and how much time I'm spending on reading code?”


If you spend most of the time coding – congratulations! Although most developers spend more time on reading code, than writing it. That is why it is crucial to be sure, that code is easy and pleasant to read. The benefit will be for example less mistakes and less stress.


Nobody writes clean code at the beginning, code is evolving and changing. That’s why it is very important to rethink what you write. Pair programming and consulting with team-mates will help you with that, thus improve quality of your work. You can take a part in creating ideal work environment, it is a continuous process which need constant improvements. Write draft of code, look at it and make it more clean. When I think about it, clean code might seems similar to sculptor’s work – shaping our masterpiece by reducing volume.


Pair programming

Working in pairs improves code quality and speed of work, it creates a possibility for two developers to share knowledge and ideas with each other. The result will be better, than a person could achieve alone, and solutions born during discussion might be way better. Pair programming looks basically like this: two coders are sitting at one desk, one person is writing a line of code, and second person is commenting on it immediately, offer with idea what can they write in easier way. Pair programming is also a nice way to share the knowledge between experienced colleagues. It's about brainstorming, boosting two different mind processes while writing and analyzing what was written.

 

Some clean code guidelines:

1. Less code is always better.

When it comes to writing a software, it's often that while starting and writing the very first lines of our class there might be a bit of more code, than it's needed. For example, public method in service can contain some variables which are not necessary needed, block of logic or "if" statements which should be extracted into separate method. For example, result of method can be used directly in code, creating variable and assigning a result to this variable is not mandatory.


Reduce the amount of code in one place. Remove unused variables. Remove comments as well - code should be self-explanatory.


2. Extract method.

How long is your method? If it has 20+ lines, many “if” statements, loops etc., then you should think about it. Extract it to another method with a proper name that gives the impression what it's doing clearly in one glimpse of an eye without analyzing the logic. Why use method extractions? Because it helps to hold easy, to read method structure. It's always better read one method containing 20 lines calling 10 different methods, than method containing 400 lines unnamed logic and twisted commentary.


3. Good naming.

It's worth to spend some time to find proper name for a class, method, variable we are creating. It will save our colleagues a lot of time. Don't use abbreviations, names should be simple and self-explaining. For example, “usersAction” is an unclear method name – to know what it means, you have to look inside a method body. For contrary, a method with a self-explaining name could be “saveUserInDataBaseAndSendAnEmail”. This name tells exactly what method does. Inside you can expect separate methods with names: “saveUser”, “sendAnEmailAboutSavedUser”.


- Variable, name should tell what data it's holding or what service is hiding behind of it.

- Method, reading a method name. You should know exactly what it's doing, without diving into logic.

- Class, should be named according to domain (part of system logic it is responsible for, for example, domain can be payments, invoices etc.). If Class start to grow more than 200+ lines, think about dividing it.


I will stress this once again. Clean code means benefits: pleasant work, less stress, unit tests, easy debugging and better quality.


I know that if you are dealing with a messy code, working with such environment will take more time, nerves and energy than it should. It's not because you are a bad programmer, it’s simply because analyzing this code is taking a lot of time, and is (as we are only humans) frustrating and tiring. Nobody like working with badly designed code, where a bug is inevitable. There are many reasons why bad code appears in many projects, maybe this is lack of time, lack of knowledge about technology. Maybe because you just didn't know that it can be written in different way. Now, when all excuses are gone, go and reshape your code! Introduce one good practice at a time, and results will come sooner than you expect! Good luck!


Piotr Żak, Software Developer at Robert Bosch Sp. z o.o.


Source

Other articles

O pracy i rekrutacji w BOSCH: poznaj odpowiedzi na najczęstsze pytania kandydatów
O pracy i rekrutacji w BOSCH: poznaj odpowiedzi na najczęstsze pytania kandydatów
b
bosch
Jan 19, 2021
From KNOW-HOW to WOW - The Bosch Global Podcast [Episode 2]
From KNOW-HOW to WOW - The Bosch Global Podcast [Episode 2]
b
bosch
Dec 07, 2020
From KNOW-HOW to WOW - The Bosch Global Podcast [Episode 1]
From KNOW-HOW to WOW - The Bosch Global Podcast [Episode 1]
b
bosch
Dec 07, 2020
ChallengeRocket
Tech talent
Challenges Blog Find jobs Employers
Companies
Business HR Blog Pricing
Challengerocket
FAQ EU Join Us Contact Us
Copyright © 2023 ChallengeRocket. All rights reserved.
Privacy Terms and Conditions Service status

Let’s talk

Proven effectiveness - get up to x3 more candidates and shorter recruitment time.

In view of your consent, the data you provide will be used by ChallengeRocket Sp. z o.o. based in Rzeszów (address: Pl. Wolności 13/2, 35-073, +48 695 520 111, office@challengerocket.com) to send messages as part of the newsletter subscription. Don't worry, only us and the entities that support us in our activities will have access to data. All information on data processing and your rights can be obtained by contacting us or at www.challengerocket.com in the Privacy Policy tab.

We will reply within 2 business days.

Log in


Forgot your password?

OR
Don’t have an account?
Create a candidate account or a company account

Log in

Forgot your password?

Create a candidate account

Already have an account?
Log in
OR
  • At least 10 characters
  • Uppercase Latin characters
  • Lowercase Latin characters
  • At least one number or symbol

Not a candidate?  Sign up as an employer

Reset your password

Remember your password? Log in Log in for business

Create an employer account

Sign up for free.
Select the best plan to publish job ofers & challenges.

Company name introduced here will be visible on your job ads.
  • At least 10 characters
  • Uppercase Latin characters
  • Lowercase Latin characters
  • At least one number or symbol

Not an employer?  Sign up as a candidate