this post was submitted on 03 Jan 2024
38 points (100.0% liked)
Programming
17313 readers
165 users here now
Welcome to the main community in programming.dev! Feel free to post anything relating to programming here!
Cross posting is strongly encouraged in the instance. If you feel your post or another person's post makes sense in another community cross post into it.
Hope you enjoy the instance!
Rules
Rules
- Follow the programming.dev instance rules
- Keep content related to programming in some way
- If you're posting long videos try to add in some form of tldr for those who don't want to watch videos
Wormhole
Follow the wormhole through a path of communities [email protected]
founded 2 years ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
I find Python difficult - no idea why, it just doesn't feel right. I've tried a few times but never been able to do anything useful with it - that's why it's not in my list above. It does seem though that my proposed project, and development "style", is best suited to Python. Maybe it's time to try again.
If you work in bash and don’t like python, maybe it’s too strict. Look into Ruby. It was inspired by Perl. I found it more to my style in that there are many correct solutions and not one implied correct solution.
It was just a recommendation. If you feel like python isn't for you, you can try any other language and the only difference will be how much time it'll take to make it, but otherwise you can use C if you want. Maybe you're so used to low level programming like managing memory and having to declare types everywhere that python dumb proof approach is difficult for you. Just don't think too hard about it, if it's a personal use script then there's no need to think about it's efficiency or ugliness. If it works, it works.
If you have experience with COBOL why use anything else?
I hear it's very popular and nice to use.
Python is basically runnable pseudo code that you would write on a napkin to explain stuff to somebody. There you don't care about curly backets and naturally indent to show scope. It's way simpler C and if you want to, you can add type hints (aka faux static typing).
Package management is done with
pip
although nowadayspoetry
is better as it uses one file to define everything about your project and configure the tools (linter, tester, autoformatter, static type checking)The advantage of python is that it has lots and lots of libraries. You don't need to fiddle around with the lemmy API - use a library:
Want to connect to musicbrainz? https://pypi.org/project/musicbrainzngs/ is probably the best.
-->
Create a virtual env (basically allows you to install all your project dependencies in an environment separate from the global one):
python3 -m venv .venv
.Activate the virtual in your shell
source .venv/bin/activate
.Now you can start installing dependencies. If you want it super simple, use
pip install $package
, but updating the list of packages you want in your project is manual:pip freeze > requirements.txt
(install them again withpip install -r requirements.txt
afterrm -rf .venv
should you want to start fresh) and you can run into problems with clashing dependencies.So, I recommend using poetry
pip install poetry
.poetry new .
to setup basic project structure, then add runtime dependencies withpoetry add $package
e.gpoetry add pylemmy musicbrainzngs
.It's possible to add dev dependencies with poetry like
ruff
for linting and autoformatting your code andmypy
for static type checking. Your unit tests can be written usingunittest
from the standard library.CC BY-NC-SA 4.0
Thank you for your detailed response. It's a bit much for my proposed "project". I won't be using any libraries (other than built-in python json etc.). I've prototyped most of it and it's currently about 15 lines of code. Literally one call to lemmy, a search to Musicbrainz and a playlist update to listenbrainz. I know it will grow lots as I make it a bit more robust, but it's still very small.
I see. No problem :) If it's simple, does what you need it to, and you're happy with it, that's all that matters.
Another (mostly) retired Unix sysadmin here. I never could make Python work in my brain, but last year discovered Svelte/SvelteKit and really like it. I'd always kinda hated on JS, but actually it's pretty nice these days.