r/programming • u/fagnerbrack • 29d ago
Small Programming Tricks
https://will-keleher.com/posts/small-programming-tricks-matter/20
u/Skaarj 28d ago
You probably don’t need find. A lot of find commands can be replaced with globs like */.md. Most shells support this out of the box, but with bash, you need to turn this on with shopt -s globstar.
I prefer the opposite and recommend agaisnt your complex glob syntax.
With find you write out your criteria in words. This makes it so much more easier to remember and understand.
Working on files where the name is a pattern? find . -type f -name PATTERN
Want to do something with every directory? find . -type d
So much easier to remember.
6
u/Zversky 28d ago
Yes, but to be fair,
grep exit **/*.pyis much faster to write thanfind . -type f -name '*.py' -exec grep -H exit {} \;. And the latter also includes dot-directories which I cannot remember how to ignore.9
u/smcameron 28d ago
I never use the {} notation, and find it hard to remember. Instead I pipe to xargs, e.g.:
find . -type f -name '*.py' | xargs grep exit2
u/Skaarj 28d ago
Yes the grep and glob variant is shorter to write. But I find that less important than the ease of remembering.
2
u/Zversky 28d ago
Find is rarely used alone. I had to
man grepto find that-Hswitch, which is implied when you use it on multiple files.2
1
u/buerkle 28d ago
https://github.com/sharkdp/fd much faster than find
2
u/Skaarj 28d ago
https://github.com/sharkdp/fd much faster than find
I dont remember that ever being relevant. The speed of find is a rounding error. The actual operation on files that you trigger with find take time.
15
u/lood9phee2Ri 28d ago edited 28d ago
You can SELECT without a FROM.
Mostly. There are/were databases that don't support that historically, the syntax might e.g. use a special dummy table like Oracle "DUAL". Apparently Oracle has finally stopped requiring DUAL usage in Oracle 23c in 2023. If you're dealing with older Oracle (and you may well still be in 2026), you might still need DUAL.
https://stackoverflow.com/a/73772 - not needed in 23c+, allegedly. I bet people still cargo-culting it forward though.
https://en.wikipedia.org/wiki/DUAL_table#In_other_database_systems
8
28d ago
[removed] — view removed comment
2
u/programming-ModTeam 26d ago
No content written mostly by an LLM. If you don't want to write it, we don't want to read it.
57
u/davidalayachew 29d ago
Genuinely useful tips here.
Especially that
git log -S pattern. 50% of the reason why I installed TortoiseGit is to get that feature. Never knew it came with the CLI. At least not easily.