Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Continually Learning (From Home)

Zaymon Antonio ZaymonFC

🏠
Continually Learning (From Home)
View GitHub Profile
View oop(s).md

Thoughts on OOP.

Note: This is written as part of a letter in response to a good friend who asked for my opinion on OOP. This is mostly an off the cuff work in progress:

What a question to try and tackle. I have so much that I want to say but I am going to try and distill my thinking to what I believe are the most relevant points. This might get long because I'm going to use this as a recap of my own understanding on the topic as well 🧠.

Mutable State

By far the most dangerous thing about OOP is the use of mutable state. You've probably noticed in your programming career, especially making the jump to the front-end that mutable state makes everything harder. Every guarantee breaks down. When you have some object with a mutable API, and multiple things holding a reference to that object or it's state, there's no good way to coordinate updates to that object without breaking consumers, especially in a multi-threaded context.

View sudoku.clj
(require '[clojure.set :as set])
(defn vertical-line [board line]
(->> board (map (fn [l] (nth l line)))))
(defn vertical-lines [board]
(->> (range 9) (map (fn [line] (vertical-line board line)))))
(defn subgrids [board]
(let [board (->> board
View Floyd-Warshall-ShortestPair.cpp
// Dynamic.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <vector>
#include <algorithm>
#include <iostream>
#define INT_MAX 1000