News for hackers. Stuff that matters.
Re:Reasons Python Sucks by Hello71 on Tuesday December 18, 2018 @11:32AM (#18707873)
> And I pity anyone who miscounts spaces and accidentally puts in three spaces instead of four somewhere -- this can take hours to debug and track down.

this is so hilariously wrong that it is clear that the author has never actually tried any of the things he complains about.

  Python 3.7.1 (default, Oct 22 2018, 10:41:28)
  [GCC 8.2.1 20180831] on linux
  Type "help", "copyright", "credits" or "license" for more information.
  >>> if True:
  ...     if True:
  ...         pass
  ...    pass
    File "<stdin>", line 4
      pass
         ^
  IndentationError: unindent does not match any outer indentation level
same error in Python 2.7.15. the caret is at the wrong place, but the error message is perfectly fine on its own.

edit: I checked the CPython source, and this message actually dates back to 2000. so unless the author was using python 1.x back in the 90s, or is dumb enough to use single spaces for indentation, the story is a complete fabrication.

Re:Reasons Python Sucks by compiler-guy on Tuesday December 18, 2018 @12:49PM (#18708691)
I think the problem he is describing--somewhat poorly--is when the "third space" just happens to match some other scope above, and therefore is syntactically valid, but not nested the way one initially thought.

Those kinds of problems can be hard to track down.

Re:Reasons Python Sucks by jjrh on Tuesday December 18, 2018 @04:31PM (#18710774)
Never searched for 'hours' but it's been a annoyance before, usually related to copy/pasting. I certainly have run into the indent issue where my editor doesn't know what block it should be in but that's more emacs fault.

That said, I sure with python offered a totally optional end block thing. In many situations it would make things far more clear.

Re:Reasons Python Sucks by Izkata on Tuesday December 18, 2018 @06:15PM (#18711498)
Exactly this. I've spent many hours on multiple hard-to-replicate bugs that turned out to be from a couple of lines at the end of a loop body that were indented to the wrong level after a refactor.
Re:Reasons Python Sucks by mixmastamyk on Tuesday December 18, 2018 @02:40PM (#18709792)
A third space can never align with another line since it will be an odd number of characters while indents are always even (or vice versa). If you are two chars off, well at some point you need to be responsible for your broken blocks.

I agree with the other person that says this doesn't really happen in the real world with a baseline developer and editor.

Re:Reasons Python Sucks by compiler-guy on Tuesday December 18, 2018 @06:17PM (#18711514)
We now have three real-world counter examples just in this thread. And the hacker news crowd is relatively sophisticated technically--even for programmers in general.

"It isn't a problem for me, therefore it isn't a problem for anyone." just isn't a good way to reason about problems like this.

Re:Reasons Python Sucks by mixmastamyk on Tuesday December 18, 2018 @06:27PM (#18711564)
The important issue is which solution is the best given the trade offs. Acceptance of nothing less than a flawless one is not a path forward.
Re:Reasons Python Sucks by compiler-guy on Tuesday December 18, 2018 @06:36PM (#18711614)
Sold! As long as you admit that there is a problem and tradeoffs, then I'm fine with where this conversation is ending.
Re:Reasons Python Sucks by mixmastamyk on Tuesday December 18, 2018 @06:46PM (#18711684)
Sure, I'd never say a solution to a non-trivial issue was flawless. However, "a problem" is not very granular. I'd rather count this one in terms of centiproblems or milliproblems.
Re:Reasons Python Sucks by drewrv on Tuesday December 18, 2018 @01:42PM (#18709265)
These kind of problems can be solved or avoided altogether by a decent editor.
Re:Reasons Python Sucks by compiler-guy on Tuesday December 18, 2018 @01:52PM (#18709358)
I don't see how. An editor can help you get indentations that are syntactically valid, but can't possibly know if the programmer intends the program below to print plain "foo" or both "foo" and "bar".

  print("foo")
  # x is false for the problem
  if x:
    do_something()

    print("bar")

And to the parent who has written a lot of code but never had this problem, well, some people do.
Re:Reasons Python Sucks by mixmastamyk on Tuesday December 18, 2018 @02:45PM (#18709837)
That's a two space error and easy to see.

> never had this problem, well, some people do.

Neophytes also have a lot of problems with matching braces, neither is a panacea to those folks. But one is easier to read and type for everyone else, for years to come.

Re:Reasons Python Sucks by compiler-guy on Tuesday December 18, 2018 @02:51PM (#18709898)
It's a two space error in a trivial example that no editor can help with.

If the function is longer or their are a couple of additional levels of indentation, and it isn't a print statement, but some additional logic, it is a hard problem to spot.

Re:Reasons Python Sucks by mixmastamyk on Tuesday December 18, 2018 @02:56PM (#18709944)
Not true, look up indentation guides and whitespace visibility. Even my barebones editor has them and squashes ambiguity.

Still at some point one needs to be responsible for the code they write, braces or not. Braces are not a guaranteed solution either, if the author gives up complete responsibility.

Basically, this is a theoretical non-problem. The lack of braces pays back in readability every single day. Like +100 + -2, then complaining about the -2.

Re:Reasons Python Sucks by compiler-guy on Tuesday December 18, 2018 @03:51PM (#18710425)
I write python all the time, with editors that support this. People do encounter this problem.

You'll also note that I've never claimed braces were better, I'm just trying to explain OP's pont.

You may not encounter it, but "Hey it works for me" is not a legitimate answer.

Re:Reasons Python Sucks by blattimwind on Tuesday December 18, 2018 @01:43PM (#18709277)
> Those kinds of problems can be hard to track down.

In many years of writing Python I have not once encountered this issue. And I didn't always use four spaces...

Re:Reasons Python Sucks by fhood on Tuesday December 18, 2018 @11:49AM (#18708017)
Not to mention, who hits the spacebar four times for their indentation? Actually. Do people do that?
Re:Reasons Python Sucks by wycy on Tuesday December 18, 2018 @12:46PM (#18708657)
I frequently have to when copy/pasting code in VS Code and it assumes the wrong indentation level.
Re:Reasons Python Sucks by shawnz on Tuesday December 18, 2018 @04:17PM (#18710662)
You could select the whole pasted part and press tab or shift+tab to change its indentation level.
Re:Reasons Python Sucks by mikestew on Tuesday December 18, 2018 @12:07PM (#18708212)
To back this up, I was at a place where vim on my Mac and the Windows editor on the machine of one of the people consuming my code would somehow munge the spacing (tabs-to-spaces, or summat).

Point is, I'd see this problem constantly until I figured it out. And not once did it take more than a few minutes to fix it because, as you point out, it shows you where the problem is. And if you use PyCharm, or VS Code with Python extension, or a raft of any other editors, it'll bark at you long before you try and run the code, with circles and arrows, and a paragraph on the back of each one explaining the problem.

So, yeah, the author is making shit up. And needs to learn about what the Tab key does.

Re:Reasons Python Sucks by mixmastamyk on Tuesday December 18, 2018 @03:12PM (#18710107)
Doesn't even need to be a big heavy editor. I use the lightweight Geany and even it has indentation guides and whitespace visibility. Even so, I could probably fix such a problem without it.
Re:Reasons Python Sucks by paulie_a on Tuesday December 18, 2018 @01:06PM (#18708879)
Do you mean using spaces or using the space bar? 4 spaces is standard but the editor should take care of that with tab that results in 4 spaces. An actual tab is just plain wrong. It is allowed of course, but those developers are wrong for doing so.