-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d8eb423
commit 66cc51f
Showing
3 changed files
with
147 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# Principles for Code Quality" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## The Law of Demeter" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"\n", | ||
"It's also known as the Principle of Least Knowledge, saying that an object should only communicate with its immediate neighbors, avoiding to access deeper and deeper objects.\n", | ||
"\n", | ||
"See below for a small example how we would violate and obey the Law of Demeter." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# Bad Example\n", | ||
"class Department:\n", | ||
" def __init__(self, manager):\n", | ||
" self.manager = manager\n", | ||
"\n", | ||
" def get_manager_name(self):\n", | ||
" # Bad: Accessing a method of an object deep within the hierarchy\n", | ||
" return self.manager.employee.name\n", | ||
"\n", | ||
"class Employee:\n", | ||
" def __init__(self, name):\n", | ||
" self.name = name\n", | ||
"\n", | ||
"class Manager:\n", | ||
" def __init__(self, employee):\n", | ||
" self.employee = employee\n", | ||
"\n", | ||
"# Good Example\n", | ||
"class Department:\n", | ||
" def __init__(self, manager):\n", | ||
" self.manager = manager\n", | ||
" \n", | ||
" def get_manager_name(self):\n", | ||
" # Good: Not going deeper\n", | ||
" return self.manager.get_name()\n", | ||
"\n", | ||
"class Employee:\n", | ||
" def __init__(self, name):\n", | ||
" self.name = name\n", | ||
"\n", | ||
"class Manager:\n", | ||
" def __init__(self, employee):\n", | ||
" self.employee = employee\n", | ||
"\n", | ||
" def get_name(self):\n", | ||
" return self.employee.name" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"language_info": { | ||
"name": "python" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# Tooling for Python Projects" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## `uv`: Super-fast pip Alternative " | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"Forget plain pip for installing packages.\n", | ||
"\n", | ||
"Use `uv` for Python package installing.\n", | ||
"\n", | ||
"`uv` is a blazingly fast package installer and resolver, written in Rust for high performance.\n", | ||
"\n", | ||
"It is a drop-in replacement for pip and pip-tools, being up to 115x faster.\n", | ||
"\n", | ||
"`uv` is still in an early phase, but it's interesting to see where it goes." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"vscode": { | ||
"languageId": "plaintext" | ||
} | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"!curl -LsSf https://astral.sh/uv/install.sh | sh" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"vscode": { | ||
"languageId": "plaintext" | ||
} | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"!uv pip install requests" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"language_info": { | ||
"name": "python" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |