Skip to content

Instantly share code, notes, and snippets.

View canattofilipe's full-sized avatar
🎯
Focusing

Canatto Filipe canattofilipe

🎯
Focusing
  • Campinas - SP
View GitHub Profile
@canattofilipe
canattofilipe / clean_code.md
Created November 14, 2021 22:01 — forked from wojteklu/clean_code.md
Summary of 'Clean code' by Robert C. Martin

Code is clean if it can be understood easily – by everyone on the team. Clean code can be read and enhanced by a developer other than its original author. With understandability comes readability, changeability, extensibility and maintainability.


General rules

  1. Follow standard conventions.
  2. Keep it simple stupid. Simpler is always better. Reduce complexity as much as possible.
  3. Boy scout rule. Leave the campground cleaner than you found it.
  4. Always find root cause. Always look for the root cause of a problem.

Design rules

const y = (text) => {
return `this is the text "${text}"`;
};
console.log(y("Hi"));
function execute(fn, ...params) {
return function (text) {
return `${text} ${fn(...params)}`;
};
}
function sum(a, b, c) {
return a + b + c;
}
// A pure function is a function that the returned value
// is determined ONLY by the input values
// without side effects (change things out of function scope)
const PI = 3.14;
// example of impure function (PI is a external thing)
function circleArea(radius) {
return radius * radius * PI;
}
public class Pessoa {
String nome;
String sobrenome;
public Pessoa(String nome, String sobrenome) {
super();
this.nome = nome;
this.sobrenome = sobrenome;
}
@canattofilipe
canattofilipe / NamesSorter.java
Last active November 27, 2019 13:18
Sorting an ArrayList of objects with Java 8
// sort arrayList of objects with java 8
List<User> users = new ArrayList<>();
users.add(new User(10L, "Jon"));
users.add(new User(120L, "Robb"));
users.add(new User(190L, "Sansa"));
users.add(new User(100L, "Arya"));
users.add(new User(150L, "Bran"));