4 ms·
If there is one single thing from F# I would like to have in OCaml it is the whitespace syntax. I can write nice OCaml, but I often need to exploit corners in t
by LeonidasXIV 10y ago
If there is one single thing from F# I would like to have in OCaml it is the whitespace syntax. I can write nice OCaml, but I often need to exploit corners in the grammar and cheating around with precedence and @@ to get my code to not be full of clumsy parens, anonymous functions etc.
- ngrilly 10y agoI loved so much significant whitespaces when I discovered them in Python! Since then, a few years have passed, and I've come to the conclusion that significant whitespaces are a mistake: they make automatic code formatting difficult or impossible (gofmt, refmt, etc.), they make sharing code snippets by chat or email error prone, they make automated code generation error prone too. Please don't add them.
- MichaelGG 10y agoThis is not correct. You can still auto format just fine. It won't change indentation obviously, since that would change the meaning of the program. What problems do you have in mind? I'm also very skeptical that they make sharing code difficult. Any indentation issues will be readily apparent in a compiled language.[1] Plus I doubt this is a serious issue in the first place. And certainly it doesn't outweigh the massive gain in the main activity: reading and writing code. 1: Sure there's always a few counter examples. But in general this isn't an issue. Just like inferring function types. It's rare to have a true mistake end up changing things but simultaneously compile fine.
- ngrilly 10y agoYou're right about auto-formatting being possible with significant whitespaces... but: When you copy-paste a block of code in another block of code, with significant whitespace you have to correctly reindenting everything very carefully, while with explicit blocks you can let an automatic formatter do the work. When you copy-paste a block of code in chat/email/comment, it is sometimes difficult to preserve significant whitespaces. For example, I've seen a lot of blog comments "eat" the white spaces at the beginning of each line (example: https://unspecified.wordpress.com/2011/10/18/why-pythons-whitespace-rule-is-right/#comment-432 https://unspecified.wordpress.com/2011/10/18/why-pythons-whi...) It can be difficult to fix code incorrectly mixing spaces and tabs (especially for beginners). Rob Pike wrote on this topic: > Some observers objected to Go's C-like block structure with braces, preferring the use of spaces for indentation, in the style of Python or Haskell. However, we have had extensive experience tracking down build and test failures caused by cross-language builds where a Python snippet embedded in another language, for instance through a SWIG invocation, is subtly and invisibly broken by a change in the indentation of the surrounding code. Our position is therefore that, although spaces for indentation is nice for small programs, it doesn't scale well, and the bigger and more heterogeneous the code base, the more trouble it can cause. It is better to forgo convenience for safety and dependability, so Go has brace-bounded blocks. Source: https://talks.golang.org/2012/splash.article https://talks.golang.org/2012/splash.article
- MichaelGG 10y agoWithout examples it's hard to say. Python isn't static, and it's type system isn't as capable as MLs. I'm entirely unconcerned about random formatting systems destroying whitespace. Some eat angle brackets. Maybe I'm not copy+pasting enough. I find "for beginners" to not be useful as a measure of anything - anything can be said to be confusing for beginners. But I can see how people might come to a different opinion.
- eru 10y agoHaskell doesn't nearly has as much of a problem with copy-and-pasting from websites as Python have. (But in Haskell the significant indentation is much more optional.)
- LeonidasXIV 10y ago> When you copy-paste a block of code in another block of code, with significant whitespace you have to correctly reindenting everything very carefully, while with explicit blocks you can let an automatic formatter do the work. I've heard this argument a lot, but how often does it happen to copy paste extensive parts from web sites? Some short bits, yes, but longer parts with blocks? Almost never, since I always have to rewrite them to fit my variable names etc, so might as well make sure the formatting is right.
- co_dh 10y agoI've been programming in Python for about 10 years and still love it.