6 ms·
Small Programming Tricks
- behnamoh 18d agoThis reminded me to ask: To what extent are people still coding by hand these days? In my profession (academia), literally no one codes anymore. On one hand, it sucks because the joy and fun of programming has been replaced by constant agent orchestration tasks, but on the other hand, it's hard to go back to the way things were before because the productivity gain is so good. I remember learning a lot of these programming tricks over the years. They would give me happiness: learning something new about nvim, or some new shortcut in the Fish shell, or a new Vim macro, or the difference between 1 bracket or 2 brackets in Bash scripts, etc. But now it seems like all of them are irrelevant, and I wanted to see how others think about the situation.
- dgacmu 18d agoAlso in academia but I'm old and my real work is done withy students. I'm coding by hand much less than I used to (boo) but solving more problems with code myself than I used to (yay). Having an llm do things turns out to be similar to having a student do them but with fast turnaround and it's fine to have them work on your home automation system. ;)
- huurtehoog 18d agoAnother academic. LLMs are great for opening searches. I state what I would like to get into and let it get some initial paper recommendations. It seems to solves a hard problem: discoverability. Maybe I'm just getting subjected to more subtle bias but it is extremely easy and fast now to get a nice selection of relevant literature to review. Analysis and any artifacts are all handcrafted by me. I mean, that is the work. I have never seen papers or code as an outcome. What I want is to learn and enable other to learn. That I can only get from doing the work myself.
- cindyllm 18d ago[dead]
- SoftTalker 18d agoI do hand-code for the most part. I will use LLMs as a "smart reference" when I can't recall how to do something or maybe to scaffold out a starting point if I'm working in a less familiar language or framework. I use them as a better search engine, where I would have probably have looked at Stack Overflow, mdn, or online docs in the past. I'm fortunate I guess in that most of my work tasks have very loosely defined deadlines, if any at all.
- catlifeonmars 18d agoI hand code entirely at work still, while almost all of my colleagues do not and I am still able to keep up. I do use coding agents on personal projects, but have not felt the impetus to switch to agent based coding at work. I don’t mean this to brag, mostly to point out that in my line of work, actually writing the code is not the biggest bottleneck. For context I work on greenfield network security appliances
- skydhash 18d agoMy coding by hand is always exploratory. Either I’m getting familiar with a new library/platform or I’m sizing up the architecture of the software. Then it’s a heavy dose of copy/pasting, snippets, and emacs-fu. What I spend most time on is reading docs. Apart from that, it’s thinking (mostly away from the computer).
- catlifeonmars 16d agoThis for me too. I read specifications and then go on walks.
- bradly 18d agoI still hand code backends and frontends. I also review code by reading it manually, and ideally running it and then screenshot'ing receipts of it working and attaching those in my PR approval.
- acedTrex 18d agoIm not TYPING a lot of code by hand anymore (still some, inference is slower than typing in a few cases) but im still in the shell zipping around doing other stuff like i always have, the LLM is helpful in a lot of ways but it in no way shape or form is the ideal way to interact with a computer. So i still get daily use out of these tricks. Are there people that are literally ONLY interacting with a computer via an LLM? thats crazy if its true
- spprashant 18d agoWhile I mostly just do AI-assisted coding at work nowadays, after a long time yesterday I did some scripting in a python REPL on a remote server which didn't have any AI tooling. It felt rewarding. I was also surprised my programming muscle memory was still alive and kicking.
- louthy 18d ago> To what extent are people still coding by hand these days? I write everything myself. After 41 years of coding, I think in code — code flows from my brain through my fingers effortlessly: translating my thoughts to English for an LLM to then translate back to code is much, much slower than me. And once my hyperfocus kicks in, the last thing I need is to be jolted out of it by an LLM prompting loop. JetBrains Rider has an AI auto-complete which I do use for the 5-10% of the time that it can predict what I’m going to write next. But even the next-word/next-block-of-code prediction seems so hopelessly out of its depth (which is supposed to be LLM’s party piece), it’s genuinely shocking how wrong it is most of the time. Disclaimer: I’m not writing vanilla line-of-business code or bog standard web apps, so I suspect I’m just not in the training data.
- feelamee 18d agowhat are you writing? like - what type of programs?
- louthy 18d agoWell, there's my super-secret future-of-software-development-and-data-autonomy project, but we're not to talk about that, so shhh! (basically my next startup idea, once I've finished inventing it). Then, there's language-ext [1], which is my large open-source functional-programming framework for C#. And although this isn't beyond the realms of an LLM: they know FP and they know C# and even my library has been around for more than a decade, so it'll be in the training data, when it comes to bending C# to my whims or to trying to eek out exceptional performance, they're all at sea. A good example would be what I am working on at the moment, which I have in a standalone prototyping repo [2]. Basically I have introduced functional traits to C#, like `Functor<F>`, `Applicative<F>`, `Monad<M>`, etc. This brings more rigour to things like LINQ comprehensions and allows for the building of truly generic trait-based behaviours. Something that just doesn't really exist in C#. In language-ext today I have `Foldable<F>`, which is a little bit like `IEnumerable`, but pure. I want to be able to provide a super efficient set of default implementations for any `Foldable` (or enumerable/iterable). For this I need an efficient lazy-stream or co-routine system. The one built-in to C# (`IEnumerable` and `IEnumerator`) is impure (it mutates as it enumerates), so I am trying to build an efficient iterator/enumerator that: * Takes around 0.25 nanoseconds per-iteration-step for its housekeeping (this speed is then on a par with the mutable IEnumerators that are a core part of C#). * Doesn't allocate any memory * Is immutable * Is lazy * Can be stopped at any point and the iterator reference be passed around (because it's immutable) * Can be composed with standard functional operators (functor map, applicative apply, monad bind, etc.) without performance degradation and without a large memory-allocation cost. I've been building several prototypes to try different ways of bending C# to my whims. I've managed all but the last item on that list. Not allocating memory means using value-types (stack allocated types), but that also means the entire state of the co-routine needs to be stored in the value-type as each value is yielded (because control needs to be given back to whatever code is processing the values). To solve it, I'm pretty much building my own runtime, stack-machine, and memory manager on top of the .NET CLR so that I don't have to submit to its rules. I'm trying to apply as many of my old-skool low-level engineering chops as I can (without making it brittle); but to do the last item on that list needs more space in a value-type than would be reasonable (to avoid copying costs), so I'm looking at other pooling strategies and into building lots of bespoke to-the-metal memory managers. After all of that, it may be a fools errand, and not doable. The LLM wouldn't understand, and that's for just one feature! Also, it must be stated, I just love doing this shit, it's brain fuel. The idea of having this conversation endlessly with an LLM as it continuously gets it wrong is nightmare fuel. I'm not anti-AI, I love the fact that people who can't, now can. But, at this point in my journey with code, I think quicker and can produce quicker than an LLM. I think it's akin to a virtuoso piano player. If the piano player had to describe what they wanted to an LLM, the magic would go, the enjoyment would go, and potentially the quality would go. It would it also take much longer than if they had just played. That's how I feel with code. An LLM can maybe churn out more code than me, but I can build more value and I can invent. And when in my flow state, nothing can stop me. I will certainly keep checking in though, I'm sure there'll be a point where I feel like it augments me rather than hinders. It's just not there for me yet. Too much information? :D [1] https://github.com/louthy/language-ext https://github.com/louthy/language-ext [2] https://github.com/louthy/iterator-prototype https://github.com/louthy/iterator-prototype (this is messy prototype code, don't hate me).
- bigstrat2003 18d agoI write code by hand because LLMs do not provide any significant productivity gains. They turn out code fast, but then I have to review it to make sure the code is correct. That takes me about as long as it would to write the code myself in the first place, so I continue to write the code myself.
- elendilm 18d agoPeople in academia generally doesn't code much. So I am not surprised. LLM's have not affected us in the slightest when it comes to coding. Maybe we write a snippet, post it for llm to scrutinize, and usually LLMs spout bullshit and wrong suggestions and after enough verbal abuse it points to some issues with the code. But I don't get this delegation to LLM's for your entire coding. I hope everyone delegates to LLM :) (sarcasm)
- bitwize 17d agoso are you a time traveller from like, 2023 or something?
- elendilm 17d agoYou must be from 2029. How is the cost and technical debt looking over there? Here in 2026, we are trying hard to reduce those. Here economics still punishes us for bad decisions. In 2026, some of us use LLMs as a tool and not as the brain.
- hirvi74 18d ago> To what extent are people still coding by hand these days? That's basically I all do. I might ask a few questions to LLMs here and there like Google/StackOverflow in the days of yore. Still, every line in all my codebases are still hand-typed. I get everything I need out of the chatbots, and I cannot use any kind of agentic coding tools at work, oddly enough. Trust me, I'd love to have access to something like Codex at work. That way I could save my mental bandwidth for personal projects that I find interesting and enjoying.
- internet_points 17d agoThe code I check in at work is nearly all hand-written. I'll often send files and functions and snippets and questions and `git diff`'s to an LLM. In particular the code review is very helpful for catching silly mistakes. But if it generates code, even if it looks fine, I always end up manually moving it around and rewriting and renaming things. I need to understand the code I maintain, and those "prosaic" changes and refactorings that I do while incorporating the code help ground me deeply in how it works. Also, I'm mostly not very happy with the architectural choices the LLM makes. It can be good at little details, and sometimes I learn about language features or idioms or libraries by reading its code, but I find it often uses wrong patterns. E.g. just this week I saw it creating two huge intermediate data structures for parsing something in a "cleaner" way, completely missing how the library it had suggested actually had something builtin (and prominently featured in the tutorial) that obviated the need for those intermediate structures and was both safer and more readable. When I've tried full agent coding, I kept getting distracted while waiting. I also have the feeling that my questions to the LLM were getting "dumber" as I lost contact with the code. And I don't have the hardware for local LLM's, so giving full repo access is out of the question for work. Altogether I feel like I've found a fairly good balance in how to use them in such a way that I can avoid a lot of the downsides and still have a tool that gives me much value that I didn't have before: I check in fewer bugs, I waste less time picking libraries/methods, I have a better rubber duck, I learn little tricks all the time, I never send LLM-generated text to humans.
- VCFundedGenYer 18d agoI would probably retitle this less as "programming tricks" rather instead make it "bash/zsh CLI tricks" as this only really tangentially refers to programming.
- Natashash23 18d agonice content
- rdevilla 18d ago[dead]
- winternewt 18d agoOnly a few of these are actual programming tricks. The problem with sharing them is that they'll typically seem obvious to you, since you know them. It's difficult to know what is actually unknown to other people, and if you share stuff everybody knows you risk coming off as arrogant. Here's one that I think more people should know: avoid branches. If I can do the same thing without an if statement and even a logical expression, the code typically both becomes easier to understand for people and easier to run for the CPU.
- cachvico 18d agoI'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.
- craftkiller 18d agoHere's an example of removing a branch that was posted to HN a little over a month ago: https://www.greyblake.com/blog/branchless-rust/ https://www.greyblake.com/blog/branchless-rust/
- metabagel 18d agoOK, but the code with the branch is easier to understand.
- jamiejquinn 18d agoGenerally agree. As with many optimisations, branchless code can easily be less obvious than the branchy equivalent.
- robby_w_g 18d agoYeah, I don't buy the premise that branchless code is intrinsically easier to understand. Maybe OP's point is that adding unnecessary branches makes code harder to read? But that's generally the case for any unnecessary code.
- overflowy 18d agoIf you want to level up your Zsh history experience, I built zhist[1] specifically for that. It uses fzf underneath, but provides considerably more context than simply using fzf. There's a demo video in the README. [1] https://github.com/overflowy/zhist https://github.com/overflowy/zhist
- jawns 18d agoI would love for someone to package up some kind of script or AI skill that evaluates your current terminal config/set-up and applies all of these tips and tricks. For instance, it might detect that you currently use ag, install ripgrep, and offer a short tutorial on how users accustomed to ag should use it. Or it might look at the history of git commands you've run and offer tips on efficiency improvements.
- popzxc 18d agoI think it's a great way to stop understanding what's going on in your terminal. IMHO the value of these nuggets is that you understand what you're doing and why; opening yourself to large amounts of non-default behavior likely will end up in a less than pleasant setup. Not taking into account that different users might disagree on what is convenient and what is not, which is basically the point of making things configurable.
- farrellm23 18d agoI doubt you need a full script or skill for that. I would try something like this straight in Claude Code (and will as soon as my 5 hour quota resets :-): Review this page: https://will-keleher.com/posts/small-programming-tricks-matt https://will-keleher.com/posts/small-programming-tricks-matt... Then, review my shell init scripts (both bash and fish) and shell history. Make recommendations based on the tips and tricks from the page.
- kccqzy 18d agoGoing from ag to ripgrep is not unequivocally better. Sure ripgrep is faster, but its file filtering using -g is so much more cumbersome than -G in ag. The latter uses a regex and the former uses glob. I type many more characters to do the same search, and the same search is maybe 0.1s faster for a medium codebase. So no for me. Maybe it’s worth it for a larger codebase that isn’t large enough to require indexing.
- rustyminnow 18d agoag is also a little more ergonomic with its default flex casing: your query is case-sensitive if it has any uppercase letters, otherwise case-INsensitive. rg defaults to case-sensitive (but does have flags for insensitive and flex casing)
- NegativeLatency 18d ago> At a previous company, I shared a trick on slack every day with the engineering team, both technical and company-specific, and folks found them pretty useful. I would find that annoying, however to not be seen as a jerk I wouldn't say anything.
- blooalien 18d agoI think I would prefer an optional separate channel specifically for people to share such things with each other who wanted to see that exact sorta thing. Then nobody gets bothered by it who's not interested in such things, and people who are have a place that's dedicated to exactly that.
- CableNinja 18d agoI 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 getting pretty creative with it, and at this point have a well polished setup that i can give a shitty sentence on a problem, not only does it understand the task, but theres a full ticket->branch->work->pr review->ready comment flow that it uses. My team also uses ai but they havent quite wrapped their head on ways to really work with it. I have built and shared a number of helpful things with the team to try and help them grow. One such thing was a doc i had my ai instance write, based on how ive been using my setup. This alone has started to get the rest of the team up to where i am. My team doesnt share the same types of things i do, but they still share helpful things. Call it what you will; I think if youre not helping your team grow by providing insights and helpful things, then youre not the kind of person i want to work with.
- NegativeLatency 18d agoI think there's a fine line between helping your team grow and the sorta annoying self promotion I've seen people do in overly broad slack channels. One is actually helping and the other is making yourself more visible to mgmt for promotions.
- adzm 18d agoMy favorite is generating a sequential resultset of the numbers 1-4096 in SQL Server with this simple query: ;with [[[]][[[](_)as(select 1 union select 0),[[]][]][](_)as(select 1 from [[[]][[[] []]]][]]],[[[]][[[] _),[]][]][[](_)as(select 1 from [[]][]][] []]]][]]],[[]][]][] _),[[[[[]][](_)as(select 1 from []][]][[] []]]][]]],[]][]][[] _),[[[]][]]](_)as(select 1 from [[[[[]][] []]]][]]],[[[[[]][] _)select _ from(select row_number()over (order by _)from [[[]][]]])[[[]][[[](_); /s
- williamcotton 18d agoAdditional tip: In the macOS terminal you can... Ctrl + Option + - ...and it'll undo your typing. Dunno about other OS keys!
- brewmarche 18d agoDidn’t know about that one, and can’t find any references, but works in my fish I’ve always used Ctrl+U, it’s an Emacs shortcut, so it works in many shells and other prompts (especially since readline supports it) by default. (For example Ctrl+Opt+- doesn’t seem to work in the Python REPL whereas Ctrl+U does.)
- okinternets 18d agoAnother one I use often is <command returning output > | pbcopy on macOS. Pipes the the result directly into your clipboard
- AJRF 18d agoI started writing little "that's useful to remember" tips on my website. Bit more durable than shell history, and you can share them! https://adamfallon.com/til.html https://adamfallon.com/til.html
- aDyslecticCrow 18d agoWrote "script" by accident once in my terminal. Turns out the unfortunate naming of that gnu tool from unix days makes it rather unknown. Record a debugging terminal session including output to a file. Its pretty great.
- topaz0 18d agoI was using that a few days ago
- elendilm 18d agoThese bash commands along with similiar others makes a developer so productive. For me, I personally use nothing fancy other than normal KDE Kate for backend development. Function and variable names are chosen after putting a lot of thought into it which also includes being amenable to grep and sed.
- ahmedhossamdev 18d ago+1 for git log -S. Two I use daily: rg --hidden -g '!*.lock' to skip noise, and python3 -m json.tool to pretty-print API responses.
- lucasoshiro 18d agoI wrote this about git log -S and other Git tools for code archaeology and debugging: https://lucasoshiro.github.io/posts-en/2023-02-13-git-debug/ https://lucasoshiro.github.io/posts-en/2023-02-13-git-debug/ You can see the discussion about it here: https://news.ycombinator.com/item?id=39877637 https://news.ycombinator.com/item?id=39877637
- cachvico 18d agoI find myself using ctrl-r less and less as I make sure that anything of value that I work out goes into a Makefile or the app tooling, for me this is the basis of the dev-ops approach to work (make sure everything is scripted, not worked out on the fly).
- CableNinja 18d agoCtrl+r is great, sometimes. History saving sucks which can make using it difficult, but i usually use it out of laziness than trying to recall a command, especially with ssh or repeated iterations requiring flipping between two settings/states. Its hard to rely on it for other things, but its still super useful.
- throwaway219450 18d agoI use history | grep quite a lot, because of the non-fuzziness with default ctrl+r. If I know exactly what the substring is, then that's great, but sometimes I also want to see the sequence around the command too (e.g. two step processes like eval ssh agent + ssh add key)
- FlyingSnake 18d agoI’m lazy so With fish, I just type a part of the command and press up few times to get to where I want. There’s also fish-fzf.
- jamiejquinn 18d agoI've relied on this so much that I copy my entire history between machines...
- RSHEPP 18d agoSelf hosted Atuin would do this for you too. Unless you don't want the added tooling/complexity
- monideas 18d agoAlmost all of these are irrelevant in the age of AI, except for the logarithm thing
- bigfishrunning 18d agoUsing a computer is irrelevant in the age of AI, you should stop doing that.
- twinwest 18d agoI have the same feeling, there are new approaches and tricks to get things done, mainly from how to work with AI more efficiently. But the human brain still needs to be trained and learn new things to not get rotted
- thatcherc 18d agoCan you explain that one (the logarithm trick)? I have no idea what it's trying do to. Is it saying that it's convenient or useful to know the order of magnitude of a number rather than its value?
- wiredfool 18d agoYou might not need find due to advanced globs, but it's too easy to run into expansion limits when you match hundreds or thousands of files, so you're back to find for that.
- PennRobotics 17d agoSomething about the find syntax never sat well with me, and I don't search often enough that I feel I need to learn it. My "find" is almost always tree -if | grep "<whatever-pattern>$" | head -1 head, of course, being optional The tradeoff is needing to learn regex, which is not any easier to learn than find arguments.
- IsTom 18d ago`find` does a lot more things than that.
- laweijfmvo 18d agoDefinitely. The whole Unix philosophy of each command doing one thing and being easily composable always seemed to break down in my mind when it came to find. find does a lot. similar to ripgrep, though, fd is a modern replacement that’s a bit friendlier to use.
- jimmaswell 18d agofind is absolute agony once you get a taste of fd.
- internet_points 17d agoI tried fd but it seems to ignore so much that it's basically useless. If I wanted `git ls-files|grep` I would `git ls-files|grep` yells at cloud ..it's probably ok actually and I should give it a real go, but I'm too used to find and even have a keybinding in my ~/.inputrc to insert a find + where loop "\e\C-f": "find . -type f -print0|while read -rd '' f; do ; done\e-b\C-b\C-b\C-b\C-b\C-b\C-b" (yes I know about -exec; I find the loop easier to work with)
- lucasoshiro 18d ago> `find` does a lot more things than that. And I don't think that's a good thing. Especially because AI coding agents use it a lot. They only need to hallucinate a little to destroy your filesystem.
- 1718627440 18d agoIt is just a query language for the filesystem, which is what "finding" means. It's essentially like the SQL SELECT expression.
- deathanatos 17d agoI'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`.)
- kccqzy 18d agoA 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 likely the AI uses a trick or two that you didn’t know existed.
- teekert 18d agoThis is interesting, I also do this, it will not let me remember the commands, but, I will learn what is possible and roughly how. And in this day and age that is more important. Just like stamping knowledge into your head also became less important (but not 0 important) with books and the internet.
- louthy 18d ago> “the old days” Is this just plain old rage baiting? I literally can’t tell any more.
- kccqzy 18d agoIt’s a figure of speech. I use that phrase for anything older than three months.
- lencastre 18d agoto shreds you say
- AIiscoming 17d agoI find it a valid statement. IT was always fast, and I explained my students what IDE cable was and they don't even knew about SWAP because they never had memory issues.
- dhosek 15d ago
- jonstaab 18d agoI miss posts like this
- AirMax98 18d agoWhile AI has made my life as a developer worse in many, many ways, I am conversely really glad the conversation has shifted past these types of tricks, framework wars, etc.
- disinterred 18d agoThe most useful shell trick I've used to date is mapping the 'cd' command to 'zoxide', which is a more powerful version of cd that remembers folders you've been to.
- qxxx 18d agoyes! zoxide is also probably my most used tool. I did not map it to cd yet, but I use the z command to jump into directories indexed by zoxide.
- BeetleB 18d agoI go a step further. When I press Alt + j, it sends all the directories in zoxide to fzf (in order of frequency), and I quickly choose the directory and jump to it. I rarely type "cd" anymore. A huge quality of life improvement!
- maleldil 18d agoYou don't need to use fzf. Zoxide has an interactive function too.
- 1718627440 18d agoIs it much more powerful, than pushd?
- SAI_Peregrinus 18d agoYes, because you don't have to pop in order. "zoxide <subpath>" is "search the history of working directories for a path ending in <subpath> and cd to that".
- gnoack 18d agoI can recommend https://www.oreilly.com/library/view/unix-power-tools/0596003307/ https://www.oreilly.com/library/view/unix-power-tools/059600... The "Unix Power Tools" book is an excellent source for Unix and shell usage tricks
- sixtyj 18d agoAfter 24 years and it is still useful. I would add Sed and Awk books as well.
- bufordtwain 18d agoThese bits of knowledge are becoming less useful to me now that AI is doing a lot of the work.
- phforms 18d agoThe 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. Usually what I do is writing these tricks down to a document that is easily accessible at a place where I know that I will look for when failing to remember them. I have a directory of docs where I write stuff like this down by language/tool/etc., so I can quickly look it up without having to search the internet. But I also have to actively remind myself that these things exist whenever I have a problem, stop me from just doing the inefficient thing.
- diath 18d ago> But I still used the up/down arrow keys for years or scrolled up when I was looking for a previous command It's not even that bad of a habit with zsh either where it will only scroll through history matching a substring in your history, for instance if I type "rg -i" and then start pressing up arrow, it will only cycle through history entries starting with "rg -i".
- weaksauce 18d agoif you enable history substring search in zsh you can get that feature anywhere in the command and not just the start. it's very useful if you remember some snippet of the command like it had the word debug in it etc. in fish that is built in and on by default. though one function that i recently added will narrow your history down based on a space separated set of filters which i found useful function hgrep set -l cmd history for pattern in $argv set cmd "$cmd | grep -- "(string escape "$pattern") end eval $cmd | cat end use `hgrep ruby debug foo` would filter for a line that contained all the words ruby, debug and foo.
- harikb 18d agoClearly I am missing some setting. On zsh on macOS and I tried what you just said and it doesn't work like this
- olexsmir 18d agothe biggest trick I have is to learn to use curl properly
- rf15 18d ago> You can SELECT without a FROM welllll that depends entirely on the DB Software you're using. A certain IBM product certainly has opinions on this.
- wuhhh 18d ago[dead]
- thih9 18d ago> git log -S pattern (”git pickaxe”) Another option is to do a ‘git log -p’ followed by a string search ‘/‘. It can give more context and let you browse more easily, especially if the project has small commits. It won’t work well for every project or search though.
- titzer 18d agoI 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 utilities, as I felt my skills just kind of slowly erode over the years with each migration. Make a nice little nest for yourself and curate those tools as your own (text) UI.
- seaucre 18d agothis is a great idea, thanks!
- thebelal 18d agoWas not expecting to see my per-directory-history project mentioned in this, glad the author found it useful!
- SebasDev 18d agoI've noticed the same thing with AI coding tools. Sometimes I learn more from the commands they use along the way than from the actual solution.
- GNOMES 18d agoSimple trick I use almost daily for navigating backwards to an exact directory: https://gist.github.com/GNOMES/6bf65926648e260d8023aebb9ede9573 https://gist.github.com/GNOMES/6bf65926648e260d8023aebb9ede9... I use this often instead of chaining together multiple '../..'. Also nice for when I use Zoxide to CD into a deep nested directory. I quickly found out unless you manually CD each hop, the different parent directories aren't added to your Zoxide DB. (I have come across snippits to recursively CD into all directories in a path to "prepopulate" Zoxide). I made this to jump directly from say `/foo/bar/batz/abc/123` to `/foo/bar/batz`.
- exdeejay_ 18d agoThis is a neat and useful trick, and I will be borrowing it. Thanks!
- RhysU 18d agoAbbreviate moving up in the directory hierarchy: alias ..="cd .." alias ...="cd ../.." alias ....="cd ../../.." Just keep typing period and hitting enter until you get where you want according to your prompt. I haven't found much use for more than four periods. One period would be well-defined but useless.
- segfaltnh 17d agoI have a shell function called "up" that finds a project root and jumps back to it (e.g. a dir containing something like .git) Now I have these to complement - thanks!
- nandkeypull 16d agoI used to have these aliases, but then I shortened it even further to a vim-inspired single character which I can spam really fast: alias k='cd ..'
- zh3 17d agoSomewhat along the same lines, as I regularly SSH to other hosts with the same network filesystem mounts, 'scd' starts an SSH session on a remote host in the same directory. #!/bin/bash # SSH to remote system and change into same (current) directory DIR=$(pwd) ssh -t $1 "cd $DIR; bash -l -i"
- 1vuio0pswjnm7 18d agoAside from the NodeJS "trick", these seem like system administration "tricks" not programming "tricks" Of course shell scripting is programming according to some HN commenters Perhaps others would call SQL a programming language
- forty 18d ago> In NodeJS, you can keep a connection open to an external resource by creating an https.Agent and then providing it to your http requests: fetch(url, {method, agent}). This can have a dramatic impact on latency. Is it true that you can pass a nodejs agent to fetch ? I don't think so
- nulltrace 18d agoNo. Node's built-in fetch uses Undici. The custom hook is dispatcher, with an Undici-compatible dispatcher: fetch(url, { dispatcher })
- lucasoshiro 18d ago> You probably don’t need find I think for most cases `git ls-files` does this job quite well. If you provide pathspecs, this can be very powerful!
- ozim 18d agoThose 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.
- xhevahir 18d agoMaybe, 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.
- layman51 18d agoFor 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 https://news.ycombinator.com/item?id=48397028
- autoexec 17d ago> 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.
- utopiah 17d ago> 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. I agree... but also this is so wrong it's painful. If you do have a good worker, they don't cost money, they MAKE money. Of course if you as the CEO think you are smart enough to cover everything and anybody but you is just wasting money, then that doesn't work and optimizing makes sense. Corporations have grown in size to be mindless heartless engine, literally, and that comes at the heavy price of ... not thinking, just an automaton with a single goal, growing profit, leading to an even more inhumane setup within which removing costly humans makes perfect sense.
- jwpapi 18d agoIn Jetbrains I do secondary shortcuts and I name them as what they are in my hand: Alt M + V = Move Alt E + C = Extract Component Alt S + E = Search Everywhere _ many more. Or just vim combos.. with ideavim
- lsofzz 18d agoGood one. :(){ :|:& };:
- klez 17d agoFor today's lucky 10,000 who don't know what this is https://en.wikipedia.org/wiki/Fork_bomb https://en.wikipedia.org/wiki/Fork_bomb (See in particular the "Implementation" section where there's an explanation of how it works)
- lsofzz 18d agoA small side note I want to raise: Folks need to be sufficiently motivated to learn it. All hell break loose when `RTFM` becomes taken offensively; What do I know - I am just a weird guy with a beard. And folks always wanted to type the commands without RTFM'ing - now we have two problems instead of one. Also, these were hard learned tricks YOLO'ing until 3.30AM debugging a failed DNS clusters or why the HSM suddenly decided to trip up at 5AM! Nobody even cares about the things we learn these days - Google and then your AI agent already does 98% of what I know already. So, let them blow up the clusters and the racks - your pal AI agent knows. Go ask them instead.
- irishcoffee 18d ago“Small programming tricks for webdev” - title
- meken 18d agoI switched from vi readline mode to emacs recently primarily for Ctrl-r and Alt-. (insert the argument from the last command). I love how interactive they feel. You can accomplish the same things in vi editing mode (with ? and !!) but they’re not as interactive.
- computermadeofc 18d agoIt’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.
- embedding-shape 18d agoI 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.
- StilesCrisis 18d ago[dead]
- backend_dev82 18d agoMy main trick is to use fish and enable vi key bindings. Especially on mac where there is no Home And End functionality.
- hiAndrewQuinn 17d agoCan't say enough good things about fish from a UI/UX experience. There's a reason Shell Bling Ubuntu [0] swaps out your underlying shell to fish. Unless you need a terminal up ASAP for scripting purposes or shelling out (in which case dash is still much faster than bash) it's just such a better experience. [0]: https://hiandrewquinn.github.io/shell-bling-ubuntu/ https://hiandrewquinn.github.io/shell-bling-ubuntu/
- the-mitr 18d agoOne of the things I frequently use with Emacs is writing/recording macros on the fly with F3 and running them. I am sure this is present in the other editors as well, but this has helped me a lot at times https://www.gnu.org/software/emacs/manual/html_node/emacs/Basic-Keyboard-Macro.html https://www.gnu.org/software/emacs/manual/html_node/emacs/Ba...
- hiAndrewQuinn 17d agoI do this all the time with Vim. To the point that it astonishes me that this isn't like the third or fourth thing people learn about Vim. You can just record and play back your exact keystrokes like a _Super Smash Melee_ game plays back your inputs to replay matches. If you can figure out how to do any mildly complex action once you can literally replay it a thousand times. Just like AutoHotKey! To my that's the essence of citizen programming!
- noduerme 18d agoNot 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?
- asphodele 17d agoA 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)
- imp0cat 17d agoYes, 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.
- urxvtcd 17d agoCtrl-lpj is ingrained in my fingers. Ctrl-l to clear the screen, Ctrl-p to select previous command, Ctrl-j to enter it again. I don't even use Enter key when in terminal anymore. When you want to pause entering a command for a moment do Ctrl-a to go to the start of the line, and type # to comment out. Then Ctrl-j. You can return to that later with Ctrl-p, then Ctrl-a again and Ctrl-d to remove that comment. To edit complex commands you might want to use Alt-e to enter $EDITOR.
- startup_zombie_ 17d ago[dead]
- alentred 17d agoI remember when I was using JetBrains IDE they had this feature that would list all shortcuts and IDE features and how frequently I use them. This was excellent for feature discovery. I would regularly check it out and scroll to the list of features I never used and try them. I always wanted the same for Vim, zsh, etc.
- sassbadger 17d agoDo they still do this? I'm using PyCharm daily but have never seen it. Would indeed be pretty cool!
- kwbr3000 17d agoIt is probably this plugin https://github.com/halirutan/IntelliJ-Key-Promoter-X https://github.com/halirutan/IntelliJ-Key-Promoter-X
- deleted 17d ago[deleted]
- alentred 17d agoHa! I just checked it out (had to install IntelliJ for this!) and it is still there!!! "Help" -> "My productivity".
- elboru 17d agoThere’s a nice feature that will tell you when you could have used a shortcut instead of the manual thing.
- mitxela 16d agoIn Win95 this worked by writing the shortcut next to the menu item
- customguy 17d agoI am so proud of this (I'm sure others came up with it way before me, but I still came up with it all by myself!) //* normal path /*/ debug path //*/ take away the the first slash to toggle the debug zone ON!
- normie3000 17d agoIt's awesome in both senses! How readable has it become for you over time? Because on first glance and without syntax highlighting it's a head-scratcher.
- customguy 17d agoWith syntax highlighting I instantly know what it is :) But to be honest it's just for when I find myself toggling something a lot during development.. but still am too lazy to make a variable.
- penguin_booze 17d ago#if 0 // Normal path #else // Debug path #endif Only works with C and C++, though.
- elboru 17d agoC#: #if DEBUG Console.WriteLine("This only compiles and runs in Debug mode."); #else Console.WriteLine("This only compiles and runs in Release mode."); #endif
- pillmillipedes 17d agoI once took the time to figure these out for all the languages I use here's python: #''' normal path ''' debug path #''' when I comment out python code I do it with ''' ... #''' so I can uncomment it with 1 keystroke
- elboru 17d agoPretty cool, I love when I catch a coworker doing small tricks like this during pairing sessions.
- bitwize 17d agoProgramming? You mean that clever trick people do to make progress on a code base slowly while Claude is down?
- hiAndrewQuinn 17d agoA lot of these tricks come down to knowing there is a better alternative program somewhere out there in the universe, and then installing it. I happen to keep a shell script handy for these situations, which automatically installs most of the options listed here: https://github.com/hiAndrewQuinn/shell-bling-ubuntu https://github.com/hiAndrewQuinn/shell-bling-ubuntu More readable presentation: https://hiandrewquinn.github.io/shell-bling-ubuntu/ https://hiandrewquinn.github.io/shell-bling-ubuntu/ Among other things, fzf gets installed with all the proper key bindings, ripgrep, fdfind... basically every papercut I could find between going from a vanilla Ubuntu or Debian box to a configured one is handled in this shell script.
- utopiah 17d agoMy bash terminal starts with my own shortcuts and ^a ^e \ <------- --------> } Moving alt-b alt-f / <---- ---> / ^b ^f / <- ->z $ cp monfi[c]hier dir/ <---- ---> ^w alt-d \ <------- --------> } Erasing ^u ^k / precisely because combinatorial mindset and efficient navigation are so important to my workflow. PS: visual adapted from https://gist.github.com/tuxfight3r/60051ac67c5f0445efee https://gist.github.com/tuxfight3r/60051ac67c5f0445efee
- wyclif 17d agoI think it's wise to be a bit deliberate when turning on globstar in bash. The main cost is occasional slowness on big trees. It's OK to turn it on for general purpose things, but for scripts the bigger concerns are portability and the possibility of unexpectedly broad expansion.
- butterNaN 17d agoIn case you were confused about the logarithm trick, here's what I think it's trying to say. This hypothetical system has a bunch of users, belonging to groups. A possibility is that most groups have a only handful of users, but a few famous group might have disproportionate amount of users say 500,000. If you wanted to put these groups in buckets, you can create linear buckets of fixed size based on number of users like bucket 1: 0 to 100 users bucket 2: 101 to 200 users bucket 3: 201 to 300 users ... bucket 600000: 599001 to 600000 users Now the problem is you have way too many buckets, and most of them are probably empty. In situations these "buckets" actually cost you money, you might want to optimise the number of buckets. So the code converts the user distribution to logarithmic scale: const bucket = Math.floor(Math.log10(userInGroupCount)) This essentially creates buckets as number of digits: bucket 1: 0 to 9 users bucket 2: 10 to 99 users bucket 3: 100 to 999 users bucket 4: 1000 to 9999 users bucket 5: 10000 to 99999 users bucket 6: 100000 to 999999 users With this, you have needed only 6 buckets. Moreover, this probably maps to the real life distribution, so your charts read cleanly.
- butterNaN 17d ago(you'll have to handle the case where `userInGroupCount == 0` in the code given)
- GreenLightGo 17d agoHonestly, a lot of programming is just knowing the right little trick at the right moment. You don't need to know everything, you just need to know where to look.
- alexpotato 17d agoFor people asking "do these small tricks/trivia really matter??" I have an example of when they do: - having strange networking issues on the blue side of a blue/green deployment - networking engineers are involved - nobody seems to be able to figure out what's going on despite LOTS of tcpdump/wireshark etc - I suggest tcpflow[0] (which I used for protocol analysis of chat services etc) - (there is some skepticism as I was SRE and not networking) - Turns out that the TCP messages were getting truncated on the problem side - Networking guys realize the config issue and fix it I have other examples but this is why it's always good to learn new commands/tools etc. This, in turn, reminds me of a quote from an army jungle survival expert: "People ask me if it's a good idea to read survival books. I say: 100%. You would be surprised how many people survive an emergency situation because their brain pops out some critical piece of information from a book or article they read 10 years ago." 0 - https://linux.die.net/man/1/tcpflow https://linux.die.net/man/1/tcpflow
- js2 17d agoI debugged terrible git clone performance over the VPN at my last company. It turned out our firewall was stripping TCP window scaling by default, which included both our internal GitHub Enterprise instance hosted on AWS and github.com. I collected a bunch of packet traces (tcpdump was sufficient) and eventually got the networking folks to fix the firewall config. This was a company of a few thousand people with programmers working from home who all must've assumed it was fine to get no more than ~1 Mbps git clone performance. After a few months of putting up with it I finally got tired of the issue and spent 30 minutes tracking down the cause. It still took a week or more of back and forth between me, and the networking and security teams. And it became an ongoing issue as they were allow-listing IP addresses, not fixing the root cause. Why are Cisco firewalls stripping TCP window scaling by default in 2026? I have no idea! So, yeah...
- xorcist 16d agoNo to belittle your find even the slightest, but it might be good to notice that tcpflow decodes tcp flows, which is exactly what Wireshark does, only the latter in a GUI and with a plethora of other protocol decoders. Just right click any tcp packet and select Follow. Both tools even use the same filtering language, coming from tcpdump itself. Wireshark's protocol decoder is more advanced than tcpflow. It does understand fragmented packets. So given a choice, Wireshark is often the preferred tool.
- sellcukyilldiri 17d ago[flagged]
- fitsumbelay 17d agoGood post. +1 for Julia Evans mention. Her work and vibes are worth anyone's time
- quietbritishjim 17d agoThis will probably seem to obvious to mention to many, but it took me a few years to realise that you could replicate the "BREAK XYZ" from languages of yesteryear: FOR I = 1 TO 10 FOR J = 1 TO 10 FOR K = 1 TO 10 DOSOMETHING I, J, K REM Breaks out of the middle loop, continues next I iteration IF SOMECONDITION(I, J, K) THEN BREAK J NEXT K NEXT J NEXT I in modern languages by refactoring the loop you want to break out of into a function and using return instead: def inner_loops(i): for j in range(10): for k in range(10): do_something(i, j, k) if some_condition(i, j, k): return def fn(): for i in range(10): inner_loops(i)
- dhosek 17d agoUgh, TIL that Python doesn’t have labeled breaks. Now I’m wondering what other languages in current use don’t have this functionality.
- dude_ilands 17d ago[dead]
- waynesonfire 17d agoWhat a silly observation.. of course they matter. This, among other things called experience, seperates senior engineers from bright young green minds. Good thing those same green minds have all this extra time to throw at the problem to catch up and appear senior.