Back to articles
How to write a Clean Code

How to write a Clean Code

via Dev.toCaique Santos

Introduction Clean Code is a concept popularized by the book of the same name, written by Robert C. Martin. The main ideia of the book is that a clean code can be read and enhanced by a developer other than its original author. The pillars of this concept are the following below: Clear naming: Instead of using: var x = GetData(); Prefer: var userEmails = GetUserEmails(); Functions responsability A function should be as short as possible, and do only one thing. Avoid: ProcessUserDataAndSendEmai(user); Instead, prefer: ProcessUserData(user); SendEmail(user); Low coupling Avoid tight coupling by instantiating dependencies directly: private EmailService _emailService = new EmailService(); Prefer depending on abstractions: private IEmailService _emailService; Self-explanatory code Comments can be helpful, but code should be clear on its own. Avoid: // increase processed items count count++; Prefer: processedItemsCount++; Consistency You should stick to a standard. Avoid mixing different nam

Continue reading on Dev.to

Opens in a new tab

Read Full Article
5 views

Related Articles