2023-01-10T13:06
Multiple inheritance and the diamond problem
2023-01-10T14:14
- Structural subtyping checks the interface at runtime
- Class inheritance checks the interface at compilation time
- Structural subtyping is more flexible in the sense that you can have the same class implementing different protocols (interfaces) but without the tight relationships imposed by classical class inheritance.
- The way to do that in class inheritance is to make your classe to inherit multiple classes, which could be a mess. Additionally, with subtyping you can decouple the interface (protocol) from the class it implements.
2023-01-10T14:26
- The diamond problem often appears when one uses inheritance while it should be used composition. These approaches are not conflicting. Actually, it is recommended to use both, it it makes sense.
- An engine is a component of a car, but a car is not an engine.
- A Secretary is an Employee but a Secretary has a SalaryPolicy.
2023-01-10T14:33
This design is what is called policy-based design, where classes are composed of policies, and they delegate to those policies to do the work. Policy-based design was introduced in the book Modern C++ Design, and it uses template metaprogramming in C++ to achieve the results.
2023-01-10T14:35
I stopped here: https://realpython.com/inheritance-composition-python/#abstract-base-classes-in-python
2023-01-10T14:35
And here: https://peps.python.org/pep-0544/
2023-01-23T15:08
Script Kit
Tool to create daily scripts. I would like to do/watch some tutorials to check if it is useful. Link to website
2023-02-08T17:43
Brushup January 2023
How to do all the following things at the same time: - start a process with Popen - capture the stdin, stdout, stderr - redirect the data from stdout and stderr to another files, but keep printing them to stdout and stderr - write to stdin and display it in the stdout Something like this, but the stdin part is not working:
import concurrent.futures
import io
import subprocess
import sys
#TODO: The stdin is transmited, but it is not displayed.
process_result = subprocess.Popen(
[
"bash",
action.entrypoint,
terrier_folder,
],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
encoding="utf8",
)
temp_out = io.StringIO()
temp_err = io.StringIO()
def read_stdout():
for line in process_result.stdout:
sys.stdout.write(line)
temp_out.write(line)
def read_stderr():
for line in process_result.stderr:
sys.stderr.write(line)
temp_err.write(line)
with concurrent.futures.ThreadPoolExecutor(max_workers=2) as executor:
f1 = executor.submit(read_stdout)
f2 = executor.submit(read_stderr)
concurrent.futures.wait([f1,f2])
2023-07-12T15:51
Overload pattern in C++
https://www.cppstories.com/2019/02/2lines3featuresoverload.html/
2024-06-10T09:06
Brush-up 2023/2024
Python 3.12
Update tomldataclass such that it works for every python version from 3.6 to 3.12
- What is new in Python 3.12
- New generic type syntax.
- deprecation of distutils
- better f-strings
- collections instead of typing
