r/shittyprogramming • u/dankey26 • Nov 21 '22
at last, ++ -- operators for python
https://github.com/dankeyy/incdec.py
i actually did this one a while ago but you guys seemed to dig swap.py, so i thought i'd share this one here too
may wanna wash your eyes afterwards idk
179
Upvotes
3
u/ericanderton Nov 22 '22
Fantastic! Now Python programmers can be burned by "what do you mean x++ evaluates to x before increment?!" problems.
But seriously, this is inspired work. I never would have thought to hijack the encoding scheme to bootstrap a compiler extension. Bravo.
I'm going to make a practical request: can we get a
deferstatement next? That would define a block that runs when the current scope exits. I know thattry/finallyandwithexist to cover this, butdeferis way more ergonomic, IMO.83
u/[deleted] Nov 21 '22
q: What
a: this
I may start documenting functions this way.
27
u/Drasern Nov 22 '22
I appreciate your commitment to absurd solutions for silly problems.
51
u/[deleted] Nov 21 '22
You know I once saw someone say Python is a bad language because it doesn’t have in place increment/decrement operators but clearly they just weren’t thinking on this level.
7
u/PityUpvote Nov 22 '22
Horrifying, thank you.
9
u/[deleted] Nov 22 '22
Amazing! Submitted to mCoding. Hope you get a video and thus lots of repo stars ⭐️
3
u/[deleted] Nov 22 '22
Anybody who is whining because python doesn't have this by default clearly never used Lua.
4
u/MerrittGaming Nov 22 '22
I’ve only recently started using Python (been using C/C++ my whole time at university) and asked myself why they didn’t think to implement this in the first place. Thanks for making this a reality
0
u/krishna-sai Nov 22 '22
The real question is would they be faster than normal incremation of adding one
-1
u/[deleted] Nov 22 '22 edited Nov 22 '22
Python is the only language I’m really familiar with, so I don’t see the big deal here.
-= and += make sense to me, whereas ++ or — does not.
I already hate it because ‘- -‘ just looks like ‘—‘ unless you have the right font.
Edit: who are the people with extra chromosomes that are downvoting this? Lmao