You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+49-3Lines changed: 49 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -58,9 +58,9 @@ Sooner or later I will complete it with the relative answers. Feel free to contr
58
58
* What is an Anti-corruption Layer?
59
59
* 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?
60
60
* 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)
64
64
* 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?
65
65
* 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?
66
66
@@ -559,3 +559,49 @@ class Crew {
559
559
}
560
560
```
561
561
<br>[⬆ Back to top](#table-of-contents)
562
+
563
+
### Write a snippet of code violating the Don't Repeat Yourself (DRY) principle. Then, fix it.
564
+
565
+
Code violating the DRY principle:
566
+
```javascript
567
+
classEmployee {
568
+
calculateSalaryNet() {
569
+
returnthis.hoursWorked*this.hourlyWage;
570
+
}
571
+
572
+
calculateSalaryGross() {
573
+
returnthis.hoursWorked*this.hourlyWage+TAX;
574
+
}
575
+
}
576
+
```
577
+
578
+
Fixed code:
579
+
```javascript
580
+
classEmployee {
581
+
calculateSalaryNet() {
582
+
returnthis.hoursWorked*this.hourlyWage;
583
+
}
584
+
585
+
calculateSalaryGross() {
586
+
returnthis.calculateSalaryNet() +TAX;
587
+
}
588
+
}
589
+
```
590
+
<br>[⬆ Back to top](#table-of-contents)
591
+
592
+
593
+
### How would you deal with Dependency Hell?
594
+
595
+
1. The most basic approach is to manually update dependencies to satisfy other package versioning or to ask the maintainer to do this.
596
+
2. If I trust the semantic versioning libraries I use, I try to do more relaxed versioning.
597
+
2. A better solution for this problem is to keep projects in monorepo. This approach implies other challenges though.
598
+
3. Another interesting solution is a [system for easier dependencies management](https://www.youtube.com/watch?v=VNqmHJtItCs) introduced by Netflix Engineering.
599
+
600
+
<br>[⬆ Back to top](#table-of-contents)
601
+
602
+
### 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`?
603
+
604
+
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.
605
+
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.
606
+
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.
0 commit comments