This 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…
Ugh, TIL that Python doesn’t have labeled breaks. Now I’m wondering what other languages in current use don’t have this functionality.
Small programming tricks
271–280 of 280 posts
Re: Small programming tricks
#272I 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 !
#if 0 // Normal path #else // Debug path #endif Only works with C and C++, though.
#if DEBUG
Console.WriteLine("This only compiles and runs in Debug mode.");
#else Console.WriteLine("This only compiles and runs in Release mode.");
#endifRe: Small programming tricks
#273The 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…
Re: Small programming tricks
#274I 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 !
Re: Small programming tricks
#275Re: Small programming tricks
#276I 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.
Do they still do this? I'm using PyCharm daily but have never seen it. Would indeed be pretty cool!
Re: Small programming tricks
#277This 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…
Ugh, TIL that Python doesn’t have labeled breaks. Now I’m wondering what other languages in current use don’t have this functionality.
Re: Small programming tricks
#278The 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…
Re: Small programming tricks
#279Earlier quoted context omitted.
Oh so that is what this is for. I thought ctrl-q / ctrl-s are there as a nasty way to screw with users, who every now and then accidentally press one of these, and find their terminal frozen and no longer visibly reacting to input, for no apparent reason.
That's actually XON/XOFF - in the old days when computers could send serial data to your VT100 or whatever faster than it could handle it (and we're talking 9600 baud here), the terminal would send XOFF (ctrl-S) telling the computer to stop sending - then, when the terminal caught up, it would send XON (ctrl-Q) to let the system know it could resume sending. The advantage of doing it this way ('software flow control'…
Re: Small programming tricks
#280For 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…
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...