DEV Community

loading...

Design Patterns, good habits and good sense!

jessicanathany profile image Jéssica Nathany ・2 min read

This week we made a recording on the Café debug podcast about Design Patterns, good habits and good sense. The podcast is in Portuguese, but I dcided to write our conversation in English, of course just a summary.

Let's start with Clean Code. The book Clean Code for some people is considered the Bible of developers, because it teaches some techniques to make yours code cleaner and more inteligible.

But, why do we need to wirte code? Let´s see.

  • Because we want to deliver results faster;
  • The requirements were changed during development;
  • The code was bad and a given situation´s refactor is not a good idea;

And what changes in a programmer´s life when you write clean code?

  • Evolution as a developer: you make your code cleaner, to improve your skill;
  • Produtivity increase: the team can have a produtivity increase and fast delivery;
  • Clean, cohesive code: a code that everyone can understand where everyone talks the same "language" fallowing an standard;
  • Reduce bugs: of course, the quantity of bugs redeced in your code the project and you have less time for correction.

Let's see some good practices that can be applied to clean code.

Meaningful Name

Your method, class or variables need to have meaningful names. It's not important if your code name is long, but the name needs to be specific according to its functionality.

Comments are not very good!

You cannot put comments in your code, I think it depends on the situation. Normally we can put comments when we are talking about the code version, or business roles or something specific. So, avoid comments in code.

Make your code elegant

Try to make your code more elegant, write very well, think about someone that will read your code.

Last but not least: you need to test your code!

Unit testing is important, very important and you know this. Unit testing prevents future bugs in your project, and tests will teach you if you're learning.
But why don't we test it? Let's look at some reasons why some developers don't test their code.

  • A small amount of people understand that unit testing is very important
  • Don't know how to test your code
  • Short deadlines
  • The project is not prepared to implement unit tests
  • The pressure from the team or manager
  • Bad architecture and "code smell"

So I will leave some links about documentation of the unit test on the Microsoft platform .Net and the documentation of the framework Moq.

1- Best practices for unit testing with .NET Core e .NET Standard
https://docs.microsoft.com/pt-br/dotnet/core/testing/unit-testing-best-practices

2- Framework Moq no Net
https://discoverdot.net/projects/moq

3- Moq documentation
http://www.nudoq.org/#!/Projects/Moq
https://github.com/JessicaNathany/cafedebug

4- Link to technology podcast Café debug
https://soundcloud.com/cafe-de-bug/40-design-patterns-e-boas-praticas-e-bom-senso

5 - Code smell (Martin Fowler)
https://martinfowler.com/bliki/CodeSmell.html

6 - Refactoring
https://refactoring.com/

Discussion (1)

Collapse
sistemassouza profile image
Denis Souza

Article great

Forem Open with the Forem app