-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkiss.ts
More file actions
34 lines (25 loc) · 739 Bytes
/
kiss.ts
File metadata and controls
34 lines (25 loc) · 739 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// KISS PRINCIPLE
/*
Fast Overview
- K: Keep
- I: It
- S: Simple,
- S: Stupid!
*/
// The code should always be more simple to read and understand (for another dev or for yourself in 6 months)z
// Dont overengineer the code with useless abstractions, crazy generics (TypeScript) and so on...
// ? Wrong Example
// To make the sum of two number this is too much
class MathOperation<T extends number> {
constructor(private value: T) {}
add<V extends number>(other: V): number {
return (this.value as number) + (other as number)
}
}
const crazyResult = new MathOperation(5).add(10)
// ? Correct Example
// More readable, mantainable and easy
function add(a: number, b: number): number {
return a + b
}
const result = add(1, 6)