Live data from Hacker News

Small programming tricks

will-keleher.com

201–210 of 214 posts

Re: Small programming tricks

#201
post #151

Those were not programming tricks, but computing tricks or command line/sql tricks. Anyways I find it mind boggling how many useful actions are not known by „normal people”. Most people are really using computers in a very inefficient way. My idea is if we would spend time making people learn computers or software they use daily better - we wouldn’t need AI agents and we would triple GDP.

Maybe, but there's all sorts of habits and skills that would make us enormously more productive/healthy/etc. if only the masses would learn them. This is a very old problem.

For sure! It was on Hacker News too that I learned not that long ago via this thread[1] how to tie my shoes in such a way that the knot won't come undone by itself. It has definitely saved some time with some shoes with laces that would always undo themselves on their own with my old method.

[1]: https://news.ycombinator.com/item?id=48397028

Re: Small programming tricks

#202
Not exactly programming tricks, but there's also stuff you just recognize quickly because it's a pattern you've encountered before. Like yesterday I had to diagnose a bug where some newly deployed and barely tested software hung while generating a gift certificate. Customer's name was O'Brien. Anyone wanna guess the bug?

Re: Small programming tricks

#203
post #38

A lot more tricks can be learned from just watching AI work. Instead of allowing AI to work autonomously, go back to the old days where you manually approve every command the AI runs. Just recently while doing performance optimization work, I found Opus using the `perf` command in ways I didn’t know possible. Just give AI a real task and carefully read what commands are used by the AI to solve the problem; most likel…

This makes me think of something I hate about how LLMs write CLI scripts. Even with the same model on the same day, there's never any consistency with the way CLI arguments are written or handled. Sometimes they want to split on an equal sign, and specifically write that into the code. Other times they write code to pair keys and values based on spacing and order, even and odd.

--date=2026-09-16

--date 20260916

and all variations thereof. It's annoying enough to have to check which script expects what format that I probably should've wasted some time or tokens to align them all, or at least put it into an MD file. But it's just an illustration of how LLMs can make CLI commands more obscure than they need to be.

Re: Small programming tricks

#205
post #37

`find` does a lot more things than that.

I'd wager that most people just don't get that the second "arg" (composed of multiple args) to find is an expression. Expressions are, somewhat unfortunately, code, so there's essentially a mini DSL there.

  find -name '*.md' -and -not -type d
Of course, then it becomes more obvious why there are parens, why those parens must be escaped for the shell, etc. E.g.,

  find '(' -name '*.md' -and -not -type d ')' -or '(' [...] ')'
I think once someone groks the nature of the expression args, then find becomes easier to start working with.

The most messed up part in my mind though is that while most things in find are clearly helping the expression towards its goal of "true" or "false" on whether to include the file or not in the results, some, like -prune or -exec do so but with side-effects. And since they're usually invoked primarily for their side-effect, it isn't immediately obvious that they even return a value, or are participating in the expression itself. (-prune is true, and -exec depends.) And this is where it becomes important that `find`'s -and & -or are short-circuiting, too. (In a purely logical expression, it wouldn't really matter except as an optimization.)

People also sometimes omit -and, which I'm not a huge fan of the legibility of. (But using -and makes it not POSIX; you can do -a but ew. which brings me to the last bit…)

macOS: the find there requires the starting-point arg; so my examples above, on macOS, would all need to be,

  find . [expression args...]
… which is lame. Brew install GNU find and be done with that.

While I agree with globbing (or fd) for interactive use, I think for scripting I'd still say "you might want find"; there are limits to arg list lengths (see xargs) that (esp. recursive) globs can exceed; unless you know you'll never glob the world, find might be appropriate. Also:

  echo *nope*
Globs will betray you on the zero-match case. (`man bash` & cf. `nullglob`.)

Re: Small programming tricks

#207
post #77

The thing with a lot of these tricks is that you have to get into the habit of using them. I knew `Ctrl+r` for history since I learned about the command line. I even have a nice shell integration with fzf. But I still used the up/down arrow keys for years or scrolled up when I was looking for a previous command, because I never remembered the shortcut and just took the path of least resistance to find something. Usua…

I’ve read that if you’re trying to overturn a habit with a new habit, it’s best to undo whatever it is you did the old way, then redo it the new way. So if you want to use ctrl-r, but you’re using the up key, use the down key to navigate back to a clear line, then use ctrl-r. Do it enough times and your brain will work overtime to find a shortcut (aka just doing it the new way).

Temporarily binding the up arrow in the shell to echo "Use Ctrl-R" is probably the quickest way to un-/re-learn

Re: Small programming tricks

#208
post #160

Earlier quoted context omitted.

You just have to do it so often that you’re annoyed by it and then you learn the shortcut and then you force yourself to always do the shortcut.

That's how I learned Emacs!

being annoyed and forcing yourself is how everyone learns Emacs

Re: Small programming tricks

#209
post #151

Those were not programming tricks, but computing tricks or command line/sql tricks. Anyways I find it mind boggling how many useful actions are not known by „normal people”. Most people are really using computers in a very inefficient way. My idea is if we would spend time making people learn computers or software they use daily better - we wouldn’t need AI agents and we would triple GDP.

> if we would spend time making people learn computers or software they use daily better - we wouldn’t need AI agents

There's no amount of skill/efficiency/productivity a human worker can reach that will make employers give up on the dream of one day replacing them with software. The AI companies looking to profit from renting out the collected works and creativity of humanity certainly wouldn't shut down if the GDP tripled either.

People should still take time to learn how to use computers though. As long as they're going to use computers they can save themselves a lot of trouble and anxiety by investing some time in learning about them a little. Same with many other things people use and depend on.

Re: Small programming tricks

#210

A few tidbits I wish I had known about sooner: bash: Ctrl-L to clear the screen VSCodium: Shift+Alt+[arrows|mouse click] to select a rectangular block scp for moving files (instead of ftp)

Yes, but try rsync instead of scp. Mind the slash though!

Both rsync -avz /path/to/file user@server:/another/path/to/ or rsync -avz /path/to/file/ user@server:/another/path/to/file

Will create directory named /another/path/to/file which will contain all contents of the original directory (/path/to/file/*).

Basically, if you include the trailing slash in the source path, only contents of the directory will be copied (useful when you need to rename it).

    rsync -avz path/to/old_dir/ user@server:/path/to/new_dir
If you omit the trailing slash in the source path, rsync will create the target directory for you. See man rsync for more info.
Post reply on HN