Live data from Hacker News

Small programming tricks

will-keleher.com

181–190 of 195 posts

Re: Small programming tricks

#181

It’s sad, I used to love little tricks like this: optimizing my workflow, learning the keyboard shortcuts, reading the manual. But now I just prompt codex or cc. The appeal of “sharpening the axe” is greatly diminished. I fear much of this type of knowledge will soon be lost to time.

I prompt a lot, but I also still run a lot of commands and do quick edits with vim myself, not gonna prompt "increase X to Y" when it takes ~3 seconds to do myself vs ~30 seconds for even a fast model to do it.

Re: Small programming tricks

#182

Earlier quoted context omitted.

I think that "everyday" would be a stretch, but i dont understand why youd think thats annoying, someone took the time to consider helping the rest of the engineering team grow, by posting something useful. I frequently do the same, but not everyday; only when i think its something actually useful/helpful beyond the everyday crap. Most recently, we have had a huge push to use ai (just like everywhere else), ive been…

Why just one each day then? Why not a shared knowledge base? Do you start with a "bag of tricks" and then hand them out one by one each day to remind people you're the guy with the bag of tricks? "Oh, yeah, I know a cool trick, but y'all have to wait until tomorrow to find out what it is." "Look! It's a way to evaluate SQL expressions with a select with a from! Oh, you already knew about it?" I have nothing against s…

Because it's about the journey and not just the artefact. If you're not thinking of something that's useful and preparing snippets to share every day you are not practising it. Having to come up with something stretches your imagination and critical thinking skills. What's true for the writer is true for the reader - if you just shared a simple repository with tricks, exceedingly few are going to read that, and the ones who do will forget it. Daily practise is important.

Re: Small programming tricks

#184
post #104

I keep a ~/scratch.txt file and a bash alias "scratch" that will just grep it. Then I put a lot of relatively infrequently-used but often-forgetten command recipes in there, so that I can just do "scratch keygen" or whatever and it will find it. It persists longer than bash history. If anything, I wish I had paid a lot more attention to this in the early days and made a nicer shell environment full of my own utilitie…

this is a great idea, thanks!

Re: Small programming tricks

#185
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).

Re: Small programming tricks

#187

Earlier quoted context omitted.

I'm struggling to comprehend how branches can be avoided (or why one would want to, as they are the cornerstone of programming). I can only think how to obfuscate them, which is rarely useful.

What people refer to when they say "branchless code" is something very particular, and it refers to not triggering the CPU's branch prediction. That is, don't make the CPU have to guess which fork in the code you're going to take. This is usually accomplished in one of two ways: either bit twiddling hacks or specialized instructions that do not affect the CPU's branch prediction, such as the 'cmov' family in x86. If…

Rust is an expression language and so it doesn't have "the ternary operator"† you can use conditionals like if anywhere in your expression anyway.

If you want to tell the Rust compiler that you're certain a branch predictor can't help here [be very sure, most often humans are wrong which is why historically these "I know better than the branch predictor" features get ignored by optimisers] you can core::hint::select_unpredictable(condition, a, b) rather than using a dedicated operator.

† That's not its actual name, some languages have an operator with three operands which does something else, such as fused multiply-add so in a multi-lingual context better to say explicitly you mean the ternary conditional operator.

Re: Small programming tricks

#188
post #120

Earlier quoted context omitted.

Clearly I am missing some setting. On zsh on macOS and I tried what you just said and it doesn't work like this

FWIW I'm also on macos 15.7.9, zsh 5.9, oh-my-zsh - and I do get this behavior (TIL). type eg "rg" then up or down arrow, and the history shown is filtered by that rg prefix.

Isn't oh-my-zsh one of those batteries-included distributions? It sounds like that's just one of the configurations that it provides.

Re: Small programming tricks

#189
post #120

Earlier quoted context omitted.

Clearly I am missing some setting. On zsh on macOS and I tried what you just said and it doesn't work like this

I was missing it too. Google says it's a builtin zsh feature but mac doesn't turn it on by default, so you add these to `~/.zshrc` bindkey '^[[A' history-search-backward bindkey '^[[B' history-search-forward So far it works. Thank you diath.

I'm not really sure what "turn it on by default" even means in the context of a shell. I've had that manually in my config for years.

Re: Small programming tricks

#190
post #117

Earlier quoted context omitted.

I found atuin way too hard/slow to use, I think I went two days before I nuked it and went back to pure omzsh. Has it gotten any better in the past 2ish years?

(hi! I work on atuin!) yes, it's improved a lot in the last couple of years! what in particular bothered you?

Not the parent commenter, but I also tried it a year or two ago and my recollection is that I had a similar experience. I have a really long history file that dates back like a decade and if remembering correctly I tried to import it, and it made using my shell very laggy so I ended up removing it. I'm not 100% positive that I'm remembering the exact way that I started experiencing the lag though, so if I have time tomorrow I'll try it out again and see if it's still something I encounter.
Post reply on HN