News for hackers. Stuff that matters.
Re:Ask HN: What made you change your mind about a programmin... by 8bitsrule on Sunday March 03, 2019 @09:10PM (#19298275)
When I looked at Python, it looked interesting. Then I found out that -white space is important-. I thought about what it might be like to worry about that, and decided -not for me-.

When CPUs ran at 1 MHz, I wasn't so sure about FORTH with its RPN. But it ran a lot faster than interpreted BASIC, and was a lot faster to write than assembler. Once the world discovers the source of all its woes and goes back to wide-open, 8-bit systems, I'll go back to FORTH.

Re:Ask HN: What made you change your mind about a programmin... by baobrain on Sunday March 03, 2019 @10:24PM (#19298547)
> Then I found out that -white space is important-.

I hear this a lot and I think it's a misunderstood statement. Python does not care if you do not have a space in assignments or arithmetic or between commas or parentheses.

What Python does care about is the indentation of the source code. The indentation is what guides the structure - which is already what we are doing with most languages that don't care about indentation!

What I really mean to say is there are plenty of valid complaints with Python, but white space just is not one of them. If you are writing good code in a language with C-syntax you are doing just as much indentation.

Re:Ask HN: What made you change your mind about a programmin... by Grue3 on Monday March 04, 2019 @04:09AM (#19299845)
>which is already what we are doing with most languages that don't care about indentation!

No that's not what the other languages are doing. They have explicit structure defined in the code (with Lisps being at the extreme end), which allows the development environment to automatically present the code in a way that's easy to read. This frees the developer from the job of manually formatting their code like some sort of caveman.

As someone with 8+ years of experience of programming in Python for a job, I've seen countless of bugs spawned by incorrectly indented code, which is incredibly difficult to spot. I've seen people far more experienced than me make these bugs because they didn't notice something being misindented. To me, the fact that we have to deal with this is laughable. Especially considering it's so easy to fix Python the language so that indentation becomes unambiguous: add an "end" statement for each deindent (aka closing brace).

Re:Ask HN: What made you change your mind about a programmin... by baobrain on Monday March 04, 2019 @09:27AM (#19301462)
> No that's not what the other languages are doing.

Is this a claim that people do not indent in other languages and leave it to the dev environment? Yes, those languages don't rely on indentation but people do still manually indent or rely on their environment to indent it for them to make the code remotely readable. I for one cannot read Java without it also being indented correctly.

> This frees the developer from the job of manually formatting their code like some sort of caveman.

I honestly don't understand this part. What tools are you using that don't do indentation for you? Emacs and vim extensions, vscode, Pycharm, atom...all of them have very intuitive indentation for when you type. The most you have to do is hit backspace after finishing a block.

> Especially considering it's so easy to fix Python the language so that indentation becomes unambiguous: add an "end" statement for each deindent (aka closing brace).

As someone with a lot of Ruby experience, the "end" is absolutely not more clear than indentation. There's a reason environments highlight do-end pairs together: because it's hard to know which ones match which.

Re:Ask HN: What made you change your mind about a programmin... by Grue3 on Monday March 04, 2019 @02:53PM (#19304682)
>people do still manually indent or rely on their environment to indent it for them

Nobody manually indents their code. Almost any language other than Python is unambiguous to indent, so the computer does it for you.

>I for one cannot read Java without it also being indented correctly.

That's easy, just copy paste Java code into an editor and press a button to indent everything. Voila! Good luck if you're dealing with Python code which got misindented somehow (e.g. copying from some social network website which uses markup that doesn't preserve whitespace, which is most of them).

>What tools are you using that don't do indentation for you?

Python code cannot be re-indented unambiguously. So if you copy paste a chunk of Python code from one place to another, you can't just press a button to reindent everything. You have to painstakingly move it to the right level and hope that it still works. In Common Lisp I just press Ctrl-Alt-\ and everything becomes indented correctly.

>The most you have to do is hit backspace after finishing a block.

That works if you only write new code and never have to change existing code.

>There's a reason environments highlight do-end pairs together: because it's hard to know which ones match which.

No, the open/close brackets allow the IDE to highlight them so that the programmer can clearly see the scope of the code block. This is a useful feature of the language. In Python it's almost impossible to see which deindent matches what if the function is long enough/deep enough.

Re:Ask HN: What made you change your mind about a programmin... by hackinthebochs on Sunday March 03, 2019 @11:58PM (#19298893)
>but white space just is not one of them.

This position is hard to maintain after you've spent an hour trying to debug a nonsensical error just to realize you opened the python file in an editor that used a different tab/space setting than the file was created in. Significant whitespace is one of the biggest misfeatures in programming history.

Re:Ask HN: What made you change your mind about a programmin... by JimDabell on Monday March 04, 2019 @04:03AM (#19299821)
I've been writing Python for over 20 years, and I don't think this has happened to me one single time. I'm not some kind of super programmer; I make as many mistakes as anybody else and spend too long debugging stupid mistakes occasionally.

I've mixed spaces and tabs before on a handful of occasions, and it's always told me straight away what the problem is.

Here is an example of mixed spaces and tabs for indentation:

https://repl.it/repls/NegativeExemplaryBackups

You'll see that it raises an error:

    TabError: inconsistent use of tabs and spaces in indentation
…and points you to the exact line with a problem.
Re:Ask HN: What made you change your mind about a programmin... by hackinthebochs on Monday March 04, 2019 @11:27PM (#19308105)
Here's an example of an incomprehensible error related to mixing whitespace, where its not obvious its a mixed whitespace issue:

https://repl.it/repls/MotionlessLustrousScan

Re:Ask HN: What made you change your mind about a programmin... by JimDabell on Wednesday March 06, 2019 @04:59PM (#19323318)
Are we seeing the same thing?

    IndentationError: unindent does not match any outer indentation level
The very first thing I would look at is the indentation if I got an error like that. You hardly need to "spend an hour trying to debug a nonsensical error" when you see an error like that.
Re:Ask HN: What made you change your mind about a programmin... by hackinthebochs on Wednesday March 06, 2019 @07:08PM (#19324331)
Does "indentation error" immediately scream check for a whitespace mismatch to you? Because it doesn't to me.
Re:Ask HN: What made you change your mind about a programmin... by JimDabell on Thursday March 07, 2019 @02:36AM (#19326233)
"Indentation error" screams "fix the indentation", and code is indented with whitespace, so yeah.

When something tells you "indentation error", where's the first place you would look, if not the indentation? When you know you have a problem with the indentation, what do you think you have to change, if not the whitespace? There isn't a lot of opportunity to go in the wrong direction here.

Don't get me wrong, Python definitely has unexpected, difficult to debug behaviour for newbies (e.g. mutable default arguments). But this in particular isn't one of them. This is 2+2=4 level stuff.

Re:Ask HN: What made you change your mind about a programmin... by hackinthebochs on Thursday March 07, 2019 @06:26AM (#19327212)
This is a strange response. The only thing I can say is that "indentation issues" does not imply "mixed whitespace issues". Your responses are implicitly conflating the two.

>what do you think you have to change, if not the whitespace?

Note that the same error shows up when you have an inconsistent number of spaces to indent a block.

Re:Ask HN: What made you change your mind about a programmin... by JimDabell on Thursday March 07, 2019 @03:30PM (#19332028)
> > What do you think you have to change, if not the whitespace?

> Note that the same error shows up when you have an inconsistent number of spaces to indent a block.

And what would the solution to that be, if not changing the whitespace?

Every single piece of information available is strongly pointing in the same direction here.

Re:Ask HN: What made you change your mind about a programmin... by hackinthebochs on Thursday March 07, 2019 @03:57PM (#19332326)
I swear its like we're speaking two different languages. I really don't see the utility in further effort trying to find common ground.
Re:Ask HN: What made you change your mind about a programmin... by hackinthebochs on Monday March 04, 2019 @10:05AM (#19301784)
It's nice when it does offer that specific error, but I've burned many hours over the years when it fails to recognize that as the issue.
Re:Ask HN: What made you change your mind about a programmin... by randomsearch on Monday March 04, 2019 @03:28AM (#19299661)
Anecdotally, from several sources teaching in tech, it’s the significant white space that makes python much more approachable to non-nerds. For some reason matching nested braces isn’t palatable to them. I attribute Python’s wide adoption in the non-nerd world in part to this (the other part being the ecosystem).
Re:Ask HN: What made you change your mind about a programmin... by goto11 on Monday March 04, 2019 @02:45AM (#19299512)
Surly that could only happen if you used a mixture of tabs and spaces for indentation.
Re:Ask HN: What made you change your mind about a programmin... by hackinthebochs on Monday March 04, 2019 @10:06AM (#19301797)
The point is that if you open a file with a different editor it was created with, its very easy to mix tabs and spaces without any kind of indication that that's what is going on.
Re:Ask HN: What made you change your mind about a programmin... by ryl00 on Sunday March 03, 2019 @11:19PM (#19298746)
But doesn't the whitespace issue gimp Python's lambda syntax? AFAIK you're limited to one expression or function call, to get around the fact that you can't just inline a completely new function (with its associated control flow structure).

And what about one-liners, a la Perl? Stack Overflow answers seem to imply either embedding newlines in your string, or using semi-colons (as a Python newbie... you can use semi-colons?!)

Re:Ask HN: What made you change your mind about a programmin... by cauthon on Monday March 04, 2019 @01:13AM (#19299176)
> AFAIK you're limited to one expression or function call, to get around the fact that you can't just inline a completely new function (with its associated control flow structure)

On the other hand, if your function needs a flow structure that's more complicated than a single line, should you really be inlining it?

And I think any such use case that you really want to inline can probably be accomplished with list comprehensions

Re:Ask HN: What made you change your mind about a programmin... by AlotOfReading on Sunday March 03, 2019 @11:03PM (#19298681)
Why should code in a REPL be indented correctly? What if you copy from your own terminal (which may only support spaces) to your codebase, which may be in tabs? It doesn't make sense for a language exclaiming the principle of we're all adults here to not allow you to schedule irrelevant formatting fixes yourself.
Re:Ask HN: What made you change your mind about a programmin... by JimDabell on Monday March 04, 2019 @03:57AM (#19299790)
> When I looked at Python, it looked interesting. Then I found out that -white space is important-. I thought about what it might be like to worry about that, and decided -not for me-.

I did the same thing. In fact, this is why I came to comment on this thread: my initial reaction was to turn my nose up at the significant indentation. Then I gave it a try, and I got over it in about five minutes. It just wasn't the big deal I thought it was. I've heard a lot of other people say the same thing.

Re:Ask HN: What made you change your mind about a programmin... by Sohcahtoa82 on Monday March 04, 2019 @03:40PM (#19305182)
> Then I found out that -white space is important-.

The only time this should ever be an issue is when you're copy/pasting code from a web page or other source that doesn't preserve white space when you copy.

Otherwise, I'll never understand why this is so hard for people. No matter what language you're using, you should be properly indenting code blocks 100% of the time, and if you're doing that, Python's white-space-as-syntax will never be a problem.