Skip to content

Instantly share code, notes, and snippets.

View sizovs's full-sized avatar
🌴
Mentoring software developers @ principal.dev

Eduards Sizovs sizovs

🌴
Mentoring software developers @ principal.dev
View GitHub Profile
@sizovs
sizovs / osom.md
Last active January 19, 2021 19:48
OSOM.md
// 1. refactor the code so it's at the same level of abstraction (SLAP).
0.
Range range = new Range(8000, 8005);
var port = Port.freeWithin(range);
1.
int from = 8000;
int to = 9000;
  1. README.md: no information on how to run and test the app.
  2. README.md: no information on minimum runtime requirements (Java 11+).
  3. Unused code: getSurname(), getLoans(), setLoans(...) etc. Best practice: never write/generate code "just in case".
  4. Packaging: according to Common Closure Principle, classes that change together must be packaged together. So, instead of putting closely related classes in different packages (exceptions, models, enums, repositories, requests, services), put them together or split by domain (lending, client). More info here.
  5. API: the API tries to be, but is not RESTful. E.g. plurals should be used: /loans, /loans/{clientUUID}
  6. Architecture: domain model leaks to the API. Instead, we should decouple the domain model from our API/screens, because they change for different reasons. In practice, our APIs should always return DTOs, not entities.
  7. Excepti
package com.homework.services;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.homework.exceptions.CountryResolverException;
import com.homework.models.Country;
import com.homework.repositories.CountryRepo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Configurable;
@sizovs
sizovs / Playtech.java
Last active May 28, 2021 07:39
Playtech May
// 1. refactor the code so it's at the same level of abstraction (SLAP).
int from = 8000;
int to = 9000;
IntStream
.rangeClosed(from, to)
.mapToObj(Port::new)
.filter(throwingPredicate(Port::isFree)) // sneakily throws the original exception (faux-pas)
.filter(wrap().predicate(Port::isFree)) // wraps unchecked exception (noexceptions)
.findFirst();
// 1. refactor the code so it's at the same level of abstraction (SLAP).
int from = 8000;
int to = 9000;
int availablePort = IntStream
.rangeClosed(from, to)
map(Port::new)
.filter(Port::isAvailable)
.findFirst();
class Port {
@sizovs
sizovs / Playtec Nov 11.md
Last active November 12, 2021 18:43
Playtech Nov 11-12 2021
@sizovs
sizovs / Solutions.java
Last active December 5, 2024 16:49
Solutions.java
// 1. Fix bad naming.
class ShoppingCart {
UUID id();
boolean isEligibleForFreeShipping();
remove(OrderItem item);
add(OrderItem item);
Collection<OrderItem> items();
}
@sizovs
sizovs / Principal.md
Created January 22, 2022 07:27
Principal TrueLayer Jan 20-21

Good morning, team!

Below I'll share some "the missing parts".

  • The idea of "Behind every request, there is an unsatisfied need" comes from the Nonviolent Communication book by Marshall Rosenberg. It's the best communication book ever written and it has helped me understand people better, and build the family I always dreamed of.
  • Other 5 forces of influence are: