Hacker News new | ask | show | jobs
by saagarjha 622 days ago
Never commented out a loop or a condition, have you?
1 comments

...yes? Sorry, I'm not sure I understand what you're getting at. :)

(funny enough, that particular scenario is actually harder to miss in Python since it often produces an error that prevents the program from running at all)

Ok, let's say I have some code. C:

  some_function();
Python:

  some_function()
I am debugging how this function works so I actually only want it to run when some condition is true. C:

  if (some_condition) {
  some_function();
  }
Python:

  if some_condition:
  some_function()
Oops. That's not indented correctly, so it won't run. To be fair neither actually looks good but that's 1. fine because this is for debugging and 2. for the C code I just format the file and it is instantly fixed. What if I have a loop? C:

  for (int i = 0; i < 5; ++i) {
      iteratively_optimize();
  }
Python:

  for i in range(5):
      iteratively_optimize()
Unfortunately this breaks something so I want to step it through. In C I comment out the loop as follows:

  // for (int i = 0; i < 5; ++i) {
      iteratively_optimize();
  //}
In Python:

  // for i in range(5):
      iteratively_optimize()
Nope, that's broken too. I can't just autoformat this code either because the formatter can't look at scope using anything else. I have to manually go and fix the indentation on that line too.

These are actually very small cases. I can even imagine you saying, in C you have to fix two places if you want to comment out a loop or if: the opening brace and the closing one. In Python you need to comment out the control statement and the second thing is fixing the indentation, so what's the big deal? Well, as the number of lines in the block grows larger in C it's still just commenting out the two braces, while in Python you have to select the whole region line-perfectly and fix the indentation. As someone who writes both I always find this to be a lot more fiddly and annoying.