Skip to content

Commit b39f06b

Browse files
53
# Conflicts: # README.md
2 parents dc994d1 + 8d6cc01 commit b39f06b

File tree

1 file changed

+47
-3
lines changed

1 file changed

+47
-3
lines changed

README.md

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ Sooner or later I will complete it with the relative answers. Feel free to contr
5858
* [What is an Anti-corruption Layer?](#what-is-an-anti-corruption-layer)
5959
* Singleton is a design pattern that restricts the instantiation of a class to one single object. Writing a Thread-Safe Singleton class is not so obvious. Would you try?
6060
* [The ability to change implementation without affecting clients is called Data Abstraction. Produce an example violating this property, then fix it.](#the-ability-to-change-implementation-without-affecting-clients-is-called-data-abstraction-produce-an-example-violating-this-property-then-fix-it)
61-
* Write a snippet of code violating the Don't Repeat Yourself (DRY) principle. Then, fix it.
62-
* How would you deal with Dependency Hell?
63-
* Is goto evil? You may have heard of the famous paper "Go To Statement Considered Harmful" by Edsger Dijkstra, in which he criticized the use of the `goto` statement and advocated structured programming instead. The use of `goto` has always been controversial, so much that even Dijkstra's letter was criticized with articles such as "'GOTO Considered Harmful' Considered Harmful". What's your opinion on the use of `goto`?
61+
* [Write a snippet of code violating the Don't Repeat Yourself (DRY) principle. Then, fix it.](#write-a-snippet-of-code-violating-the-dont-repeat-yourself-dry-principle-then-fix-it)
62+
* [How would you deal with Dependency Hell?](#how-would-you-deal-with-dependency-hell)
63+
* [Is goto evil? You may have heard of the famous paper "Go To Statement Considered Harmful" by Edsger Dijkstra, in which he criticized the use of the `goto` statement and advocated structured programming instead. The use of `goto` has always been controversial, so much that even Dijkstra's letter was criticized with articles such as "'GOTO Considered Harmful' Considered Harmful". What's your opinion on the use of `goto`?](#is-goto-evil-you-may-have-heard-of-the-famous-paper-go-to-statement-considered-harmful-by-edsger-dijkstra-in-which-he-criticized-the-use-of-the-goto-statement-and-advocated-structured-programming-instead-the-use-of-goto-has-always-been-controversial-so-much-that-even-dijkstras-letter-was-criticized-with-articles-such-as-goto-considered-harmful-considered-harmful-whats-your-opinion-on-the-use-of-goto)
6464
* The robustness principle is a general design guideline for software that recommends "*be conservative in what you send, be liberal in what you accept*". It is often reworded as "*be a tolerant reader and a careful writer*". Would you like to discuss the rationale of this principle?
6565
* Separation of Concerns is a design principle for separating a computer program into distinct areas, each one addressing a separate concern. There are a lot of different mechanisms for achieving Separation of Concerns (use of objects, functions, modules, or patterns such as MVC and the like). Would you discuss this topic?
6666

@@ -604,6 +604,50 @@ const titlePage = myBook.getTitlePage();
604604
2. This design violates SRP, so it might lead us to huge classes with lots of responsibilities.
605605
4. It's easy to hit the database multiple times (e.g. in foreach loop) because of the leaking abstraction.
606606
<br>[⬆ Back to top](#table-of-contents)
607+
### Write a snippet of code violating the Don't Repeat Yourself (DRY) principle. Then, fix it.
608+
609+
Code violating the DRY principle:
610+
```javascript
611+
class Employee {
612+
calculateSalaryNet() {
613+
return this.hoursWorked * this.hourlyWage;
614+
}
615+
616+
calculateSalaryGross() {
617+
return this.hoursWorked * this.hourlyWage + TAX;
618+
}
619+
}
620+
```
621+
622+
Fixed code:
623+
```javascript
624+
class Employee {
625+
calculateSalaryNet() {
626+
return this.hoursWorked * this.hourlyWage;
627+
}
628+
629+
calculateSalaryGross() {
630+
return this.calculateSalaryNet() + TAX;
631+
}
632+
}
633+
```
634+
<br>[⬆ Back to top](#table-of-contents)
635+
636+
637+
### How would you deal with Dependency Hell?
638+
639+
1. The most basic approach is to manually update dependencies to satisfy other package versioning or to ask the maintainer to do this.
640+
2. If I trust the semantic versioning libraries I use, I try to do more relaxed versioning.
641+
2. A better solution for this problem is to keep projects in monorepo. This approach implies other challenges though.
642+
3. Another interesting solution is a [system for easier dependencies management](https://www.youtube.com/watch?v=VNqmHJtItCs) introduced by Netflix Engineering.
643+
644+
<br>[⬆ Back to top](#table-of-contents)
645+
646+
### Is goto evil? You may have heard of the famous paper "Go To Statement Considered Harmful" by Edsger Dijkstra, in which he criticized the use of the `goto` statement and advocated structured programming instead. The use of `goto` has always been controversial, so much that even Dijkstra's letter was criticized with articles such as "'GOTO Considered Harmful' Considered Harmful". What's your opinion on the use of `goto`?
647+
648+
I wouldn't be so radical in either direction. I think that structured programming won the debate because it's the right thing to do. It's easier to reason about a program written in this manner.
649+
On the other hand, even writing this kind of programs we often use the `goto` like style (early returns, exception handling) and it doesn't do any harm.
650+
In my opinion the same applies to the `goto` statements - function-scoped `goto` statements here and there might really make our program simpler and easier to understand.
607651

608652
### Data-Mapper is a design pattern that promotes the use of a layer of Mappers that moves data between objects and a database while keeping them independent of each other and the mapper itself. On the contrary, in Active-Record objects directly incorporate operations for persisting themselves to a database, and properties corresponding to the underlying database tables. Do you have an opinion on those patterns? When would you use one instead of the other?
609653

0 commit comments

Comments
 (0)