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–278 of 278 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…