TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Scala: Consider syntax with significant indentation

84 pointsby rolodatoabout 8 years ago

21 comments

FLGMwtabout 8 years ago
Having just moved to my first Scala team, I would really really not like this to be in the language. Given 5 ways to do something, a large organization is going do something all 5 ways.<p>Scala is a fun language, but consistency is <i>not</i> one of its ecosystem&#x27;s strengths.<p>Grain of salt: again, I&#x27;m new to Scala, but I&#x27;d hate to think of it as a language that can only be good once you&#x27;re Stockholm&#x27;d.
评论 #14389521 未加载
评论 #14388942 未加载
akkartikabout 8 years ago
In a previous project I spent a lot of time thinking about significant indentation (<a href="http:&#x2F;&#x2F;akkartik.name&#x2F;post&#x2F;wart" rel="nofollow">http:&#x2F;&#x2F;akkartik.name&#x2F;post&#x2F;wart</a>), so I&#x27;m glad to see it getting more mind-share. However, the end comments are absolutely insane. Here&#x27;s a counter-proposal: if you want optional end delimiters, <i>make them not look like comments</i>. Then the relevant examples in OP would look like this:<p><pre><code> def f = def g = ... (long code sequence) ... end f &#x2F;&#x2F; optional while println(&quot;z&quot;) true do println(&quot;x&quot;) println(&quot;y&quot;) end while &#x2F;&#x2F; optional package p with object o with class C extends Object with Serializable with val x = new C with def y = 3 val result = if x == x then println(&quot;yes&quot;) true else println(&quot;no&quot;) false end C &#x2F;&#x2F; optional end o &#x2F;&#x2F; you guessed it: optional </code></pre> <i>Edit</i>: somebody already brought this up in the comments on Github: <a href="https:&#x2F;&#x2F;github.com&#x2F;lampepfl&#x2F;dotty&#x2F;issues&#x2F;2491#issuecomment-302930123" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;lampepfl&#x2F;dotty&#x2F;issues&#x2F;2491#issuecomment-3...</a>
tekacsabout 8 years ago
Folks commenting on the willingness to make breaking changes in &#x27;Scala&#x27; should note that this is Dotty, an upcoming very eventual breaking replacement for Scala (think Python 3 or perhaps even Perl 6 but less radical than the latter).<p>For now, to quote the authors, it&#x27;s a: &#x27;Research platform for new language concepts and compiler technologies for Scala&#x27;<p>So this is exactly the right place to test this sort of concept.
评论 #14388885 未加载
atemerevalmost 8 years ago
I use Scala as my primary development language since 2010. My first reaction to this change was &quot;well, this is the end of it&quot; -- as I can&#x27;t read or write anything in Python because of that.<p>But I looked more carefully and the proposal is more balanced. It looks more like Haskell than Python -- and Haskell&#x27;s syntax is one of the best ever invented, in my opinion (too bad I am not yet that smart to casually emit production-grade Haskell code).<p>So, I&#x27;m fine with that.
sscarduzioabout 8 years ago
Lovely thread to read, these guys are so analytical, well mannered and mutually respectful. Each comment is well thought, constructive, detailed, clear and down to the point. But most of all they are proof reading before submitting. I don&#x27;t do it all the times.
eroppleabout 8 years ago
I spent two or three years heavily using Scala. During that time, I more than once got to the point where I literally couldn&#x27;t casually read code I&#x27;d written less than a week before.<p>This seems like yet another great way to make that worse.
Animatsabout 8 years ago
1. If you&#x27;re going to make indentation significant, implement it in a way that makes tab&#x2F;space confusion impossible. Python 2.7 does this. The check for indent ambiguity between two strings is:<p>- Remove the common leading whitespace of both strings.<p>- The remaining parts of both strings must be all tabs, all spaces, or empty.<p>This is the least restrictive rule which catches all indent ambiguities.<p>2. Indent-based syntax is great for imperative languages, but not so good for functional languages with very long expressions. It&#x27;s not clear how to indent stuff like &quot;a.b(x).c(y).d.e(z)&quot;, where a-e x-z may be long expressions. In LISP, the all-parenthesis syntax was so simple, and so hard for humans to parse without help, that indentation was nailed into EMACS and everybody did it that way. The indentation wasn&#x27;t significant, but it was standardized.<p>Here&#x27;s word wrap in Rust:<p><pre><code> s.lines() .map(|bline| UnicodeSegmentation::graphemes(bline, true) &#x2F;&#x2F; yields vec of graphemes (&amp;str) .collect::&lt;Vec&lt;&amp;str&gt;&gt;()) .map(|line| wordwrapline(&amp;line, maxline, maxword)) .collect::&lt;Vec&lt;String&gt;&gt;() .join(&quot;\n&quot;) </code></pre> Note that the first &quot;collect&quot; is one level deeper in parentheses than the second one. How would you do that with indentation only?
评论 #14390046 未加载
virtualwhysabout 8 years ago
One advantage of significant whitespace is that it may enable a very concise (G)ADT notation:<p><pre><code> enum Tree[T] Branch(t: Tree[T]) Leaf(t: T) </code></pre> Compare that with preset day Scala:<p><pre><code> sealed trait Tree[T] case class Branch(t: Tree[T]) extends Tree[T] case class Leaf(t: T) extends Tree[T] </code></pre> In general with this proposal the `case` keyword could be implied in <i>any</i> pattern matching block. That alone would be a big win wrt to reducing keyword noise, something the MLs have enjoyed for decades.
评论 #14388754 未加载
smitherfieldabout 8 years ago
I have to say I don&#x27;t know of any other language where the maintainers have such a cavalier attitude towards making breaking changes. It makes the common analogy between Scala and C++ a bit ironic.<p>Not that that&#x27;s necessarily a <i>bad</i> thing; it&#x27;s good to have some popular languages that follow a less conservative approach, if only to get some real-world experience with different strategies for dealing with the tradeoffs between keeping a language modern and maintaining backwards compatibility with legacy code.
royjacobsabout 8 years ago
I thought Scala was supposed to be following a route where the amount of &quot;stuff&quot; they include is getting reduced?<p>The language is idiosyncratic and multiparadigm enough as it is, I&#x27;d say.
partycoderabout 8 years ago
Reminds me of the difference between JavaScript and CoffeeScript.<p>CoffeeScript attempts to become more concise by removing delimiters and making things more implicit. I don&#x27;t think that actually adds much value.<p>In a sense, it was the equivalent of trying to simplify traffic by removing lane delimiters and street signaling. You could somehow imagine they&#x27;re there, but it&#x27;s better if you can see them.
评论 #14389357 未加载
mamonabout 8 years ago
The one significant effect of indentation-based syntax is that it makes copy-pasting code from places like books or Stack Overflow somewhat harder and error prone. I&#x27;ve been hit by this few times when learning Python, I can imagine it would cause some frustration for Scala users too.
评论 #14389326 未加载
评论 #14392023 未加载
评论 #14389509 未加载
z3t4about 8 years ago
I&#x27;m working on a text editor that automatically formats the code, it will have trouble with significant whitespace if the code is valid both with and without white-space, and even compiles, and even runs with or without, although with a possible hidden bug. I&#x27;ve never worked with a language with significant whitespace so I&#x27;m wondering, does it create bugs!? In my experience, bad formatting can cause bugs, or is annoying, eg. syntax errors like &quot;missing bracket&quot; and you got no idea where it&#x27;s missing, which is why my editor does the indentation automatically and enforce it (you can&#x27;t change it).
评论 #14389133 未加载
AheadOfTime295about 8 years ago
A non-backwards compatible syntax would lower the barrier to all breaking changes.<p>Language spec [1], replacing the standard library [2], etc.<p>[1] Disallow implicit conversions between unrelated types <a href="https:&#x2F;&#x2F;github.com&#x2F;lampepfl&#x2F;dotty&#x2F;pull&#x2F;2060" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;lampepfl&#x2F;dotty&#x2F;pull&#x2F;2060</a><p>[2] Remove parallel collections from scala-library <a href="https:&#x2F;&#x2F;github.com&#x2F;scala&#x2F;scala&#x2F;pull&#x2F;5603" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;scala&#x2F;scala&#x2F;pull&#x2F;5603</a>
richdoughertyalmost 8 years ago
This is a big change to make to an existing language. Even if you really, really, really like indentation-based syntax, I doubt that the benefit of the new syntax would match the cost of change.
tanilamaalmost 8 years ago
The benefit being...? Making it more complex?
placeybordeauxabout 8 years ago
I love scala, but scala already has some of the more confusing syntactic decisions, not sure if this is gonna help.
sgt101about 8 years ago
What does the literature say?<p>Is it known (as in quantitatively) if significant indentation is a good thing, or a bad thing?
评论 #14388991 未加载
评论 #14389293 未加载
评论 #14389446 未加载
dalyalmost 8 years ago
The key flaw with indentation comes when you try to use it with printing. If your function extends across a page-break, such as in a book or a printout, it is not possible to resolve the indentation by eye.
评论 #14389498 未加载
mnd999almost 8 years ago
Just no.
exabrialabout 8 years ago
Sigh. Why are the people with the worst ideas most vocal about it?<p>If you like significant invisible characters, use Python. No need to introduce this into other languages.
评论 #14389112 未加载
评论 #14389037 未加载