If white space carries any function that the compiler/interpreter needs to know about like structure or scope, it’s probably not a very good programming language.
Genuine question: why? What makes, say a semicolon, so superior to the the newline or tab characters?
To be clear: I don’t think whitespace as a part of syntax is an awesome idea which should be more popular. It’s definitely a bit more error prone in some ways. It’s not perfect. But it’s okay.
I’ve written a lot of Python and I don’t think I have ever seen a syntax error caused by incorrect whitespace. I’m not exaggerating. I regularly forget semicolons in other languages but I never type out incorrectly indented code. Maybe that’s just me though…
From some one who used Python as it was the easiest solution to few of my problems, and having to experience languages with brackets and/or endif/fi/done as ways to limit scope, I find that having things like brackets and/or scope terminators easier to parse and less error-prone. I’m thinking about moving on to Ruby whenever I had a need where Python would be a good choice, but the time it takes for me to understand a new language is blocking me from that.
A vast majority of the code in question is the code I’ve written for my work projects with multiple active contributors and refactoring is very common too. We all like to shit on Python for various reasons but no one in my environment ever complained about whitespace.
Like I said, I don’t think whitespace is perfect as a part of syntax but I’m much more likely to forget a semicolon than a proper indentation and this applies to any language. I guess it’s not universal tough, because you can often see code with messed up indentation on online forums etc. TBH this is just unthinkable to me, indentation is absolutely necessary for me to be able to read code and reason about it. When I’m thinking about blocks and scopes it’s not because I counted semicolons and braces, it’s 100% indentation.
I honestly think the scripting languages like fish have got it right.
Newline by default completes a line and can optionally be escaped. Saves you most of the semicolons and even implicitly highlights multi-line statements.
Whitespace doesn’t matter except for separating names.
Blocks are explicitely ended without braces you can confuse with brackets or parentheses, no matter the coding style.
If Rust and fish had a baby, I think it would be the best language to have ever been created.
Nothing surprising there. Let’s replace that 3 with the call that returns 3.
$ cat f2.rb
puts "foo".length?"stuff":"empty"
$ ruby f2.rb
f2.rb:1:in `': undefined method `length?' for "foo":String (NoMethodError)
Did you mean? length
But that parsed as "foo".length? and was looking for a method call because ruby methods can end in ? but couldn’t find the method so returned an error.
Let’s put a space in there so that its the length method again without trying to become length?
And this returned what was expected… but this needed a lot more spaces in a lot more places than the puts 3?"stuff":"empty" that worked in the first call.
I agree! I don’t think 3?”stuff”:”empty” should work at all because I think it’s an insane way to type a ternary :) I’m also very open to admitting that it’s just my own strongly worded opinion.
I think that in most cases, syntactically significant whitespace is a horrible idea - the one exception being that you should have space between operators/identifiers/etc. I don’t care how much, and 4 spaces should have no more special meaning than 1, but I do think that using a space to indicate “this thing is a different thing than the thing before it” is important.
3?"bar":"qux" only has the ternary expression as a valid parsing of ?
foo?"bar":"qux" fails because foo may be a method and foo? is also a valid method identifier.
foo ?"bar":"qux" fails because ?" uses the ? unary operator that makes the next character a string. So ?"bar" becomes the string " followed by what looks to be an identifier.
And so…
? character is a valid part of an identifier (but only at the end of a method name)
?x unary operator to create a String from a character
Load-bearing whitespace is the fucking devil. This thread about hot takes is topped by a comment highlighting how people can’t even agree what kind of whitespace to use.
Python - you want code to fail if someone from one camp copy-pastes code from another camp, and the characters that make a difference are invisible?
Not who you asked but I think they’re important for humans, but syntactically I don’t think they should matter.
It should be ok to add a line break wherever it makes the code more readable, but I don’t think a compiler should care whether some code is all on one line or 10
If white space carries any function that the compiler/interpreter needs to know about like structure or scope, it’s probably not a very good programming language.
Genuine question: why? What makes, say a semicolon, so superior to the the newline or tab characters?
To be clear: I don’t think whitespace as a part of syntax is an awesome idea which should be more popular. It’s definitely a bit more error prone in some ways. It’s not perfect. But it’s okay.
I’ve written a lot of Python and I don’t think I have ever seen a syntax error caused by incorrect whitespace. I’m not exaggerating. I regularly forget semicolons in other languages but I never type out incorrectly indented code. Maybe that’s just me though…
From some one who used Python as it was the easiest solution to few of my problems, and having to experience languages with brackets and/or endif/fi/done as ways to limit scope, I find that having things like brackets and/or scope terminators easier to parse and less error-prone. I’m thinking about moving on to Ruby whenever I had a need where Python would be a good choice, but the time it takes for me to understand a new language is blocking me from that.
How much of that python is written in a shared codebase with multiple active contributors? When was the last time you refactored a module?
Tabs and spaces are invisible. Semicolons are not.
A vast majority of the code in question is the code I’ve written for my work projects with multiple active contributors and refactoring is very common too. We all like to shit on Python for various reasons but no one in my environment ever complained about whitespace.
Like I said, I don’t think whitespace is perfect as a part of syntax but I’m much more likely to forget a semicolon than a proper indentation and this applies to any language. I guess it’s not universal tough, because you can often see code with messed up indentation on online forums etc. TBH this is just unthinkable to me, indentation is absolutely necessary for me to be able to read code and reason about it. When I’m thinking about blocks and scopes it’s not because I counted semicolons and braces, it’s 100% indentation.
I honestly think the scripting languages like fish have got it right.
Newline by default completes a line and can optionally be escaped. Saves you most of the semicolons and even implicitly highlights multi-line statements.
Whitespace doesn’t matter except for separating names.
Blocks are explicitely ended without braces you can confuse with brackets or parentheses, no matter the coding style.
If Rust and fish had a baby, I think it would be the best language to have ever been created.
Intmain(intfoo){std::out<<“HelloWorld”;}
Is a great program and should totally be valid cpp. White space sucks.
/S
In Ruby,
foo?a:b
parses differently thanfoo ?a:b
and the first one isn’t parsed a ternary expression.Consider the following code snippets and execution:
Nothing surprising there. Let’s replace that
3
with the call that returns3
.But that parsed as
"foo".length?
and was looking for a method call because ruby methods can end in?
but couldn’t find the method so returned an error.Let’s put a space in there so that its the
length
method again without trying to becomelength?
It’s apparently expecting something with the
"stuff"
. Lets put in more spaces.And this returned what was expected… but this needed a lot more spaces in a lot more places than the
puts 3?"stuff":"empty"
that worked in the first call.Personally, I think that if you’d rather write
foo?a:b
thanfoo ? a : b
, you’re probably insaneBut why would
3?"stuff":"empty"
work andfoo?"stuff":"empty"
not work?Syntactically significant whitespace is a nightmare to deal with.
I agree! I don’t think
3?”stuff”:”empty”
should work at all because I think it’s an insane way to type a ternary :) I’m also very open to admitting that it’s just my own strongly worded opinion.I think that in most cases, syntactically significant whitespace is a horrible idea - the one exception being that you should have space between operators/identifiers/etc. I don’t care how much, and 4 spaces should have no more special meaning than 1, but I do think that using a space to indicate “this thing is a different thing than the thing before it” is important.
Talking with a rubyist:
3?"bar":"qux"
only has the ternary expression as a valid parsing of?
foo?"bar":"qux"
fails becausefoo
may be a method andfoo?
is also a valid method identifier.foo ?"bar":"qux"
fails because?"
uses the?
unary operator that makes the next character a string. So?"bar"
becomes the string"
followed by what looks to be an identifier.And so…
?
character is a valid part of an identifier (but only at the end of a method name)?x
unary operator to create a String from a characterexpr?expr:expr
ternary operatorAnd so…
puts "".empty? ? ?t:?f
Load-bearing whitespace is the fucking devil. This thread about hot takes is topped by a comment highlighting how people can’t even agree what kind of whitespace to use.
Python - you want code to fail if someone from one camp copy-pastes code from another camp, and the characters that make a difference are invisible?
Load bearing whitespace. Damn, I love that phrase.
Also, if you have to have agreement on the tabs or spaces argument in your codebase in order to get it to compile, you have already lost.
How do you feel about line breaks?
Not who you asked but I think they’re important for humans, but syntactically I don’t think they should matter.
It should be ok to add a line break wherever it makes the code more readable, but I don’t think a compiler should care whether some code is all on one line or 10