diff --git a/README.md b/README.md index bc6549d..3160d72 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Snippets -Snippets is a repository that stores snippets from languages I want to work on. +_Snippets is a repository that stores snippets from languages I want to work on, as well as some theories / thoughts that I have on the same topic._ [![Code Formatted](https://github.com/rentruewang/snippets/actions/workflows/format.yaml/badge.svg)](https://github.com/rentruewang/snippets/actions/workflows/format.yaml) diff --git a/python/src/sub.py b/python/src/sub.py new file mode 100644 index 0000000..764469f --- /dev/null +++ b/python/src/sub.py @@ -0,0 +1,40 @@ +# Copyright (c) 2024 RenChu Wang - All Rights Reserved + +from typing import Any + + +class Super1: + @classmethod + def __init_subclass__(cls, **kwargs: Any) -> None: + print(cls, kwargs) + + +class Sub1(Super1): + pass + + +class Sub2(Super1, param="hello", argument=123): + pass + + +class Super2: + @classmethod + def __init_subclass__(cls, required: str) -> None: + print(cls, required) + + +# Would fail: +# TypeError: Super2.__init_subclass__() missing 1 required positional argument: 'required' +# class Sub3(Super2): +# pass + + +class Sub4(Super2, required="yes"): + pass + + +if __name__ == "__main__": + Sub1() + Sub2() + # Sub3() + Sub4() diff --git a/thoughts/fundamental.md b/thoughts/fundamental.md new file mode 100644 index 0000000..a019f77 --- /dev/null +++ b/thoughts/fundamental.md @@ -0,0 +1,18 @@ +# Computation fundamentals + +There are 2 main components in computing, data (measured by space complexity) and compute (measured by time complexity). + +I theorize that +Data = entities, storage, intrinsically exists +Compute = mutation on data + +Data is more fundamental than computation, because computation are performed on data (data = symbol, compute = instruction in Turning machine). + +Think of the types of data as Markov, then a library / app is just moving on a path on this Markov state / graph. This state is exactly a Turing machine’s state as I can ask TM to simulate a function for me. + +Even transmitting a packet counts as computation, because it's changing state (location) of a piece of data. + +How do abstractions come into play? + +- I think it's just types of data and the type of compute (abstract, reasoned with invariance) that can be performed on them. Considering that every function is data -> compute -> data, abstraction in terms of breaking down functions are just composing data into intermediate representation, and abstract interfaces are shared traits of different data + specialized compute for each kind of data. +- Abstractions are just using computation to transform underlying data into the same mathematic model. Compiler optimizing this away = 0 cost. Some data structures might happen to have a better complexity but those are implementation details.