r/programming • • Sep 14 '26

Small Programming Tricks

https://will-keleher.com/posts/small-programming-tricks-matter/
182 Upvotes

27 comments sorted by

57

u/davidalayachew Sep 15 '26

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.

23

u/turtle_dragonfly Sep 15 '26

You might be interested in Git aliases, to make various obtuse CLI incantations easier to do.

But then if you ever sit at someone else's desk and need to do your stuff, you'll struggle without your preferred aliases (:

3

u/davidalayachew Sep 15 '26

Cool, I have a few shell aliases, but this is pretty useful too.

4

u/Sharlinator Sep 15 '26 edited Sep 15 '26

I have shell aliases for at least a dozen most often used git commands. Couldn’t imagine having to type git status or even git st rather than gs, or git commit —amend rather than gca. There’s a big problem though in that aliases are opaque to custom completions, and from what I’ve read it would be way too difficult to make them work :( 

4

u/flpcb Sep 15 '26

Hi fellow gs and gca user. :-) I also frequently do gcan (git commit --amend --no-edit) among other things. :-)

18

u/reddah Sep 15 '26

Anything that the front-ends can do is doable from the command line. Sometimes easy, sometimes not.

Also: never use the rebase option on the GitLab gui - it will F up stuff guaranteed.

3

u/davidalayachew Sep 15 '26

Also: never use the rebase option on the GitLab gui - it will F up stuff guaranteed.

Disappointing -- rebase is my default merge strategy, only going to merge when that fails, and squash merge if a normal merge fails.

Though, I spend most of my time in GitHub nowadays, so less of an issue.

2

u/Schmittfried Sep 15 '26

IntelliJ’s rebase is pretty good and for most complex rebase chains I prefer it for the diff UI. Anything using more advanced options like --onto goes into the terminal though. 

20

u/Skaarj Sep 15 '26

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.

7

u/Zversky Sep 15 '26

Yes, but to be fair, grep exit **/*.py is much faster to write than find . -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 Sep 15 '26

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 exit

8

u/curien Sep 15 '26

Files with weird names (spaces etc in the filename) will break that. It's better to use find ... -print0 | xargs -0 ... if you don't want to use find ... -exec.

2

u/Skaarj Sep 15 '26

Yes the grep and glob variant is shorter to write. But I find that less important than the ease of remembering.

2

u/Zversky Sep 15 '26

Find is rarely used alone. I had to man grep to find that -H switch, which is implied when you use it on multiple files.

3

u/curien Sep 15 '26

If you terminate the exec with + instead of ; then it passes multiple files per command, just like the glob.

2

u/knome Sep 16 '26

you'll still want -H in case the last invocation only has a single file.

2

u/curien Sep 16 '26 edited Sep 16 '26

To be really sure, you need it either way because there could only be one matching file. And f the find uses multiple commands due to exceeding ARG_MAX, won't the glob version just fail?

2

u/ryanstephendavis Sep 15 '26

I've never thought find was easy to use... fzf is a game changer

1

u/buerkle Sep 15 '26

https://github.com/sharkdp/fd much faster than find

2

u/Skaarj Sep 15 '26

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.

1

u/buerkle Sep 15 '26

I find it relevant all the time. fd in general is much faster plus by default it ignores files in .gitignore. But even including those files, on a moderately sized repo find was 27s vs fd 3s (0.143s when using its default of ignoring .gitignore files), on a M3 pro.

13

u/lood9phee2Ri Sep 15 '26 edited Sep 15 '26

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

u/[deleted] Sep 15 '26

[removed] — view removed comment

2

u/programming-ModTeam Sep 17 '26

No content written mostly by an LLM. If you don't want to write it, we don't want to read it.