# Review No. 1

Published 2024-04-17

This page contains miscellaneous concepts briefly explained.

# What is the meaning of "Clean Code" ?

"Clean Code" signify a code which is easy to

  • read
  • maintain (fix bugs, add new functionalities with ease)
  • test

Here we need to consider:

  • Single Responsibility Principle
  • meaningful names
  • comments are not a substitute for Clean Code
  • error handling
  • no code duplication
  • proper modularity
  • keep the code simple
  • good observability
  • use code analysis tools like SonarQube or CodeClimate

# Shared vs Exclusive lock

  • A shared (S) lock permits the transaction that holds the lock to read a row.
  • An exclusive (X) lock permits the transaction that holds the lock to update or delete a row.

# Pessimistic vs Optimistic Locking

  • Pessimistic Locking (when we READ/WRITE to a database) - a conflict is likely to happen and thus locks data before it is read or modified.
  • Optimistic Locking (when we WRITE rarely to a database) - a conflict is NOT likely to happen and thus the data is not locked. However, a "version" column (which is incremented on each UPDATE or DELETE) and the 2nd parallel operation on the same row will not be done.

# Isolation levels in a database

Isolation Level Dirty Read Non-repeatable Read Phantom Read
Read Uncommitted Yes Yes Yes
Read Committed No Yes Yes
Repeatable Read No No Yes
Serializable No No No
  • Dirty Read : you can read committed data;
  • Non-repeatable Read : during a transaction you can get different data for the same row (data is always committed);
  • Phantom Read : during a transaction you can get different rows for the same query (data is always committed).

# What is Test-Driven Development (TDD) ?

The key idea of TDD is to write a failing test first, before the actual implementation exists. The tests will not compile and will fail. When the class is created, the tests will compile and will pass if all is good.

# TCP/IP

TCP/IP is a suite of communication protocols used to interconnect network devices on the internet.

TCP/IP includes a number of protocols organized into 4 layers, often mapped to the OSI model:

Application Layer: Protocols like HTTP, FTP, SMTP, DNS, SSH. Transport Layer: Includes TCP and UDP. Internet Layer: IP (Internet Protocol), ICMP (Internet Control Message Protocol). Link Layer: Protocols that handle physical network connections, like Ethernet.

# memory leaks

When memory that is no longer needed by the program remains allocated.

# feature flags

  • a value which enable/disable some features of the application, compiler, etc.

# Hook vs Webhook

  • Hook: Modify or extend functionality of an action (For instance, when we save something we what to add a logging, etc).
  • Webhooks allow external services to be notified when certain events happen. Generally, when the specified events happen, we'll send a POST request to the remote service.