Live data from Hacker News

Small programming tricks

will-keleher.com

271–280 of 280 posts

Re: Small programming tricks

#271
post #270

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.

I was about to mention C#, but I just checked and it’s coming to C# 15 in a couple of months.

Re: Small programming tricks

#272

I 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.

C#:

#if DEBUG

    Console.WriteLine("This only compiles and runs in Debug mode.");
#else

    Console.WriteLine("This only compiles and runs in Release mode.");
#endif

Re: Small programming tricks

#273
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…

on fish shell i never felt the need for any of this, since pressing up does a history search on what you have typed

Re: Small programming tricks

#274

I 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 !

Pretty cool, I love when I catch a coworker doing small tricks like this during pairing sessions.

Re: Small programming tricks

#276

I 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!

There’s a nice feature that will tell you when you could have used a shortcut instead of the manual thing.

Re: Small programming tricks

#277
post #270

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.

C added it to the C2y draft about a year ago (so not in any actual released version of C). C++ is still working on adding it to the C++ draft.

Re: Small programming tricks

#278
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 probably knew and then forgot the Ctrl+r trick at some point because 99.9% of the time, the up arrow and grepping history is sufficient for my needs. Then again, I don't do that much on the command line anymore

Re: Small programming tricks

#279
post #227

Earlier 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'…

I remember the ole flow control :(rts/cts | xon xoff) from hyperterminal on windows :)

Re: Small programming tricks

#280

For 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 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...

Post reply on HN