Encapsulation
Encapsulation is the mechanism of binding the data together and hiding it from the outside world. Encapsulation is achieved when each object keeps its state private so that other objects don’t have direct access to its state. Instead, they can access this state only through a set of public functions
Abstraction
Abstraction can be thought of as the natural extension of encapsulation. It means hiding all but the relevant data about an object in order to reduce the complexity of the system. Abstraction helps by hiding internal implementation details of objects and only revealing operations that are relevant to other objects
Polymorphism
Polymorphism is the ability of an object to take different forms and thus, depending upon the context, to respond to the same message in different ways. Take the example of a chess game; a chess piece can take many forms, like bishop, castle, or knight and all these pieces will respond differently to the ‘move’ message.
How do i write clean code?
The boy scout rule
Why does good code rot?
serialization (encoding)
deserialization (decoding)
Binary serialization (encoding)
Load Balancers
API Gateway
Linear and non linear data structures
Linear
Direct access: array, matrix
Sequential access: LL, stack, queue
Non linear
Hierarchy: tree, trie, heap
Unorder: Hash table, set, graph
Arrays
Search unordered: O(n) linear
Search ordered: O(log n) can use binary search
Matrix
[<return> <outer> <inner> <inner> ... <option>]</option></inner></inner></outer></return>
TCP vs UDP
TCP
- Ensures reliable, ordered, and error-checked delivery of bytes between apps
- Retransmits lost or corrupted packets
- Establishes a connection/handshake before sending
- Used when data accuracy is more critical than speed
UDP
- Connectionless
- Sends messages called datagrams without establishing a connection
- Does not guarantee reliability or order
- Low overhead and fast
DNS Resolver
DNS resolvers are usually provided by internet service providers (ISPs) or other organizations. They act as intermediaries between users and DNS servers, receiving DNS queries from users and sending them to the appropriate DNS servers to be resolved. Once the resolver receives the answer, it caches the information and returns it to the user.
DNS Resolution
DNS resolution is the process of converting a domain name into its corresponding IP address. There are two types of DNS queries involved in this process: recursive and iterative queries.
To speed up the DNS resolution process, resolvers and servers cache the results of previous queries. When a resolver receives a query, it first checks its cache to see if the answer is already available. If it finds the cached information, it returns the answer without contacting other servers, saving time and reducing network traffic.
Each DNS record has an associated Time To Live (TTL) value, which specifies how long the record should be stored in the cache. TTL is measured in seconds, and once the TTL expires, the cached information is removed to ensure that outdated information is not used
Hashing
Takes an input (a message or key) and returns a fixed-size string which looks random. This output is the hash value.
The hash function converts the input data (like a book title) into a fixed length value
Examples:
- Quick data retrieval
- Data integrity Checks: Can hash the value for that file and even if a tiny portion changes the hash value will be different
- Password security
- Hash tables. Uses a hash function to compute an index where the desired value is stored
- Data deduplication: If you don’t want duplicates, just save the hash as opposed to all of the data
- Load balancing
Clean Code - Meaningful Names
Clean Code - Functions
High level of abstraction: getHtml()
Intermediate: String pagePathName = PathParser.render(pagePath)
low: .append(‘\n’)
Heap
1) Max heap: every parent node has a value >= children
2) Min heap: every parent node has a value <= children
This ordering property allows for efficient operations like finding max or min values
Find min/max O(1)
Insert O(log n)
Remove O(log n)
Heapify (create heap from array) O(n)
Clean Code - Comments
Generator Functions - Python Morsels
Iterator - Python Morsels
If you want a class to be iterable it needs to implement iter and next
class MyIterable
def \_\_iter\_\_(self):
return self
def \_\_next\_\_(self):
# must raise StopIteration or can use yielditer