Editors #
pick one and spend some time tweaking it. You will be writing, re-writing and refactoring code so make a good choice there.
Tips selection:
- Main features these are the initial features some developers
look for in an editor:
- syntax highlighting, very useful
- showing line numbers, very useful
- auto-completion, sometimes useful
- brace matching, sometimes useful sometimes anoying
- auto indentation, I don’t care for it much
- general purpose Having a function specific editor like PyCharm is cool but if you have to write C, C++, Rust, Golang etc. too it is no use.
- activly maintained
- extendable For example vscode has a plugin that allows transparant development through containers which is invaluable in a lot of scenarios
- customizable I for example like line numbering and hate case insensitive searchs (for me there is a difference between Var and VAR).
- keyboard focussed If you need to mouse too much it slows you down.
- completion/snippets at least 40% of code is more of the same. If you have completion you can be a lot faster. I build 500+ shell scripts easily within an hour, 90% of that is in my library.
Tips on use:
- Take time to get to know and use your editor. Dedicate some time on it. My tool of choice is Vim which is notoriously hard to learn. Most of my speed in development comes from being able to develop code w/o having to thing about the editor.
- If possible version your config.
Tip
If by now you don’t know how to properly work Git, start.
Habits #
Good habits are very important. It allows you to get more consistent results increase your speed and quality.
- Use either virtualenv or poetry for project setup. I like virtualenv because I still miss features in poetry.
Virtualenv #
Virtualenv allows you to setup an environment and use it without breaking your machine. If you combine that with PyScaffold you can have the basic structure of a project setup in seconds.
For example we’ll make a project called cardoplanner:
[user@host Workspace]$ mkdir trainer
[user@host Workspace]$ cd trainer/
[user@host trainer]$ python3 -m venv --system-site-packages --prompt cardoplanner venv
[user@host trainer]$ source venv/bin/activatethis is recommended but not needed
(cardoplanner) [user@host trainer]$ pip install -U pip
Requirement already satisfied: pip in ./venv/lib/python3.9/site-packages (21.2.3)
Collecting pip
Downloading pip-24.0-py3-none-any.whl (2.1 MB)
|████████████████████████████████| 2.1 MB 5.3 MB/s
Installing collected packages: pip
Attempting uninstall: pip
Found existing installation: pip 21.2.3
Uninstalling pip-21.2.3:
Successfully uninstalled pip-21.2.3
Successfully installed pip-24.0
(cardoplanner) [user@host trainer]$Install the PyScaffold package:
(cardoplanner) [user@host trainer]$ pip install PyScaffoldSetup the application:
(cardoplanner) [user@host trainer]$ putup cardoplanner
done! 🐍 🌟 ✨(cardoplanner) [user@host trainer]$ cd cardoplanner/This folder will have all the structures you need to setup something proper. A key tool in this is “tox” this tool like poetry allows you to manage your development environment.
tox is configured through the “tox.ini” file. Make sure you have an up2date version of tox to avoid headaches.
A lot of components become re-usable. For example in https://github.com/jvzantvoort/gltools I have a number of files that I use and re-use. In the setup.py file you will see the following:
entry_points='''
[console_scripts]
glt=gltools.cli:cli
''',This means that the “cli” method in “https://github.com/jvzantvoort/gltools/blob/master/gltools/cli.py" is used to create the “glt” command. And that file is a “click” based configuration. The click library allows you to create better command line handling in your code. The most important part of that is that is allows you to create library’s that have command line interfaces.
Important distinction: libraries can be unittested, command line tool not (or it becomes very difficult). Therefore: always create libraries first, commands and tools later.
Once you’ve setup something like this it’s quite easy to use:
- enter your project root (the one with the setup.py in it)
- run:
pip install -e .
This will create an editable project with the commands you defined.
Documentation #
Another good habit: documentation. For this look at the Sphinx project
Sphinx allows you to generate human readable documentation from sourcecode. For example in https://github.com/jvzantvoort/gltools/blob/master/sphinxdoc/source/gltools/git.rst you will see that the code only refers to a module called “gltools.git”.
In the source itself you will then see comments like this:
|
|
Sphinx will autodoc this and generate documentation much like the sources you will find on the python documentation site.
Important tools to include in your setup:
- black, this tool will reformat your code to proper standards.
- https://github.com/astral-sh/ruff very fast analyzer
Videos #
The one I mostly follow is Arjan he has a channel called ArjanCodes. Some cool vids: