Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optional Python-like formatting option in compiler #9512

Closed
scabug opened this issue Oct 10, 2015 · 12 comments
Closed

Optional Python-like formatting option in compiler #9512

scabug opened this issue Oct 10, 2015 · 12 comments

Comments

@scabug
Copy link

scabug commented Oct 10, 2015

As a novice programmer, I noticed that from a distance, Python code is easier to read than Scala code, even when they contain similar content. I would like to have the option to compile Scala code with Python formatting using a compile option that specifies the number of white spaces to use for indentation.

Example: "scalac -nobrace 2 Main.scala"
^ For compiling scala code with no curly braces and 2 space indent ^

If it were possible to implement such a feature in the compiler I would appreciate the improvement in legibility.

@scabug
Copy link
Author

scabug commented Oct 10, 2015

Imported From: https://issues.scala-lang.org/browse/SI-9512?orig=1
Reporter: John Reed (JohnReedlol)

@scabug
Copy link
Author

scabug commented Oct 10, 2015

@SethTisue said:
check out https://github.com/lihaoyi/Scalite

@scabug
Copy link
Author

scabug commented Oct 10, 2015

John Reed (JohnReedlol) said:
ScalaLite only works for Scala 11 and it is not backwards compatible with the curly braces formatting style. Scala is backwards compatible with the ";" semicolon line ending and the optional "return" statement, so it would be very Scala-esque if Scala were also backwards compatible with the curly braces.

@scabug
Copy link
Author

scabug commented Oct 10, 2015

@soc said (edited on Oct 10, 2015 8:35:49 PM UTC):
I'm not quite sure what you are trying to argue. From the last time I tried it, I think I remember that a valid Scala file was also a valid Scalite file. Which issues did you find?

From the docs:

bq. Notably, the fact that Scalite only special-cases lines which do not end in a { means that old-fashioned curly-brace Scala continues to function perfectly fine, and can be mixed together with Scalite code in the same source files and still compile without issue.

@scabug
Copy link
Author

scabug commented Oct 10, 2015

@SethTisue said:
as for "only works for Scala 2.11", I can't think of any reason why adding 2.12 support would be a big undertaking (the 2.11 and 2.12 compiler codebases are not that different, especially not in the parsing parts), and 2.10 is on its last legs anyway (sbt and Spark notwithstanding, sigh).

does Scalite have users? I'm not sure how much demand there is for something like this.

Haskell is an example of a language that supports both an indentation-based and curly-braces-based syntax. the former is defined in terms of the latter, but everyone uses the former, so the curly-braces syntax is more akin to an implementation detail.

in Scala-land, the chances of getting the entire community, or even a significant portion of it, to switch to an indentation-based syntax seems slight, so it seems fine to me to let Scalite continue to exist as a third-party project, and then we can wait and see how much support and momentum builds behind it. (so far, not very much.)

@scabug
Copy link
Author

scabug commented Oct 10, 2015

@SethTisue said:
(P.S. you'd probably reach a broader audience by starting a thread on scala-debate than by opening tickets here; we don't normally use JIRA for this kind of thing.)

@scabug
Copy link
Author

scabug commented Oct 11, 2015

@soc said:
I think the syntax is extremely nice for slides, but the lack of IDE support makes it hard to use in practice. Plus, having another way to do the same things is problematic. :-/

@scabug
Copy link
Author

scabug commented Oct 13, 2015

John Reed (JohnReedlol) said:
@simon Ochsenreither - I think that the implementer of Scala Lite agrees with you. He also says "Unfortunately, you won't have much chance of getting Scalite to work in IntelliJ... IntelliJ ships its own parsers which don't have any clue what to do with Scalite files ;)
As much as I love the lightweight syntax of Scalite, for you as a Scala novice I would very much recommend you to stick with ordinary Scala syntax otherwise you won't have any IDE support." [https://github.com/lihaoyi/Scalite/issues/9#issuecomment-147626945]

So basically this implementation of Python/Haskell whitespace formatting is not ready for use with the IDE that has the best Scala support, which is why I will never use it. That being said, the no-braces look of Python/Haskell is generally considered to be better than that of curly braces and paren heavy languages. I don't think that having the option to either leave in or omit the curly braces would be a big inconvenience to coders. Sure there might be a transition period in which there are some .scala files with curly braces around classes/methods and some without it, but that does not undermine the fact that the white space formatted code is more legible.

My hunch is that the main reason that white space formatted code is so much less common than curly braces is just because curly braces are easier to implement and have legacy in C. But I will start a debate over to whitespace format or not to whitespace on some other website and hopefully enough people will like the idea that someone will implement it officially (with a release announcement and support from/on major IDE's and what not).

Thank you.

@scabug
Copy link
Author

scabug commented Oct 13, 2015

@SethTisue said:
just a small correction, the comment you quote is from Martin Mauch, not from the implementer of Scalite (Haoyi Li). regardless, Martin's remarks seem accurate to me.

@scabug
Copy link
Author

scabug commented Oct 13, 2015

Martin Mauch (martin.mauch) said:
Hi John, I'm not the author of Scalite although I would love to steal the praise ;)
I have worked a lot with both curly-braces (Java, Scala, Javascript, HTML, JSON) and indentation-based (Python, Coffeescript, Haskell, HAML, YAML) languages and I prefer indentation-based syntax as well due to:

  • fewer discussions about formatting
  • fewer lines of code/noise
  • easier visual tracking of nesting
  • less noise in Git commits (e.g. trailing commas in list definitions)

I don't think that taking the number of Scalite users as an indicator for desirability of this is a fair assessment, because as I mentioned currently your choice is "ordinary Scala syntax + IDE and many tools" vs. "Scalite syntax - IDE and many tools".

So IMO, it would be great to track how many users share the same opinion/desire (given tooling support were given for the indentation syntax) somewhere.

@scabug
Copy link
Author

scabug commented Oct 14, 2015

@eed3si9n
Copy link
Member

Now that Dotty gave scala/scala3#2491 a shot and closed, I vote to close this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants