Using directives syntax #266
Replies: 21 comments 41 replies
-
Can/could I point to another of my scala programs, like or is ther some other mechanism that I havent found in the doc pages on how to include script code in script code? |
Beta Was this translation helpful? Give feedback.
-
BTW: I like very much the idea of having all config in the code and no separate config files! |
Beta Was this translation helpful? Give feedback.
-
@keynmol makes a great point. If the developer experience is to be flawless, we need to have something that will work with all IDE, editors, and different Scala versions.
in my opinion, they very much should stay valid Scala syntax, excellent tooling support is a requirement if For me, the design choices for directives form the following hierarchy:
Now, a gotcha! The Ammonite magic imports are (unfortunately!) NOT a valid Scala ProposalLet's use the old, boring annotations, which would do quite a good job in this context, actually. One would be them on either:
Example (for Scala 3): @using(@lib("com.lihaoyi::upickle:1.4.0"))
@main
def hello(name: String) = println(s"Hello ${name}!") Example (for Scala 2, App): @using(@lib("com.lihaoyi::upickle:1.4.0"))
object Hello extends App {
println("Hello!")
} Example (for a @using(@lib("com.lihaoyi::upickle:1.4.0"))
println("Hello!") Q1 - How could the compiler and IDEs not break on these annotations?!The library with the annotations could place them in the Q2 - How do you ensure, that the annotations cross-compile to all versions of Scala?We'd write them in Java. Q3 - if we are going to use a language construct, why not macros?Although it would be compelling to be able to write: runWith(lib("com.lihaoyi::upickle:1.4.0")) {
println("Hello!")
} the system would become overly complicated (cross-version support issues, etc.) in my opinion. ConclusionDeveloper experience would be best when:
All of the above would be provided by |
Beta Was this translation helpful? Give feedback.
-
Personally I found the original configuration syntax (HOCON) to work best. Example: scala = {
version = "2.13.6"
options = [
"-encoding",
"utf8",
"-explaintypes",
"-feature",
"-language:existentials",
"-language:experimental.macros",
"-language:higherKinds",
"-language:implicitConversions",
"-unchecked",
"-Xcheckinit",
"-Xlint:adapted-args",
"-Xlint:constant",
"-Xlint:delayedinit-select",
"-Xlint:deprecation",
"-Xlint:doc-detached",
"-Xlint:inaccessible",
"-Xlint:infer-any",
"-Xlint:missing-interpolator",
"-Xlint:nullary-unit",
"-Xlint:option-implicit",
"-Xlint:package-object-classes",
"-Xlint:poly-implicit-overload",
"-Xlint:private-shadow",
"-Xlint:stars-align",
"-Xlint:strict-unsealed-patmat",
"-Xlint:type-parameter-shadow",
"-Xlint:-byname-implicit",
"-Wunused:nowarn",
"-Wdead-code",
"-Wextra-implicit",
"-Wnumeric-widen",
"-Wunused:implicits",
"-Wunused:explicits",
"-Wunused:imports",
"-Wunused:locals",
"-Wunused:params",
"-Wunused:patvars",
"-Wunused:privates",
"-Wvalue-discard",
"-Vimplicits",
"-Vtype-diffs",
"-Xsource:3.0"
]
}
extra-jars = [
./src/main/resources
]
dependencies = [
"io.circe::circe-generic:0.14.1",
"io.circe::circe-parser:0.14.1",
"io.circe::circe-literal:0.14.1",
"org.typelevel::cats-effect:3.2.2",
"org.http4s::http4s-ember-client:0.23.0-RC1",
"org.http4s::http4s-circe:0.23.0-RC1",
"ch.qos.logback:logback-classic:1.2.3",
"org.systemfw::dynosaur-core:0.3.0",
"com.github.cb372::cats-retry:3.0.0",
"io.chrisdavenport::cormorant-fs2:0.5.0-M1",
"io.chrisdavenport::cormorant-generic:0.5.0-M1",
"io.github.timwspence::cats-stm:0.11.0"
] HOCON:
-- Some general thoughts, removed of HOCON...
I understand that one of the goals of scala-cli is to support prototyping with a single Scala file, but is it really worth the cost of increased complexity for anything larger than that? We could support the simple case while maintaining a nice experience beyond that:
We already have the duality of command line options and directives/$ivy syntax, so this doesn't introduce any more confusion. I know As much as I see a point of having one-file scripts, I think it would be a waste of a great tool if you optimize for that one specific purpose. scala-cli could very well be the standard build tool for microlibraries and command-line applications in Scala, and I feel like that space is being ignored with the current approach to configuration. Finally, supporting directives natively in Scala - I would love to know how you'd like to do that and keep support for existing versions which can't parse that. Say, 2.13.6 or 3.1.0. |
Beta Was this translation helpful? Give feedback.
-
Thanks for food for thought @keynmol . I'll think about this some more. Spontaneous reaction:
|
Beta Was this translation helpful? Give feedback.
-
It seems to me, that we are converging onto a view, that it is best to have:
And the language-level construct (both I'd like to point out that HOCON and comment-embedded directives are not mutually exclusive, because one can easily have an overriding scheme, which is very frequently found in many systems:
|
Beta Was this translation helpful? Give feedback.
-
Generally, full HOCON is a big no for us since it contains variable substitution, includes etc. All too complicated, we want just a configuration without any magic :) Why do we need a HOCON when we can have e.g. It is actually a bug in current implementation that single using directive cannot be multi-line. To @kubukoz 's config will be placed in using scala 2.13.6
using options
"-encoding"
"utf8"
"-explaintypes"
"-feature"
"-language:existentials"
"-language:experimental.macros"
"-language:higherKinds"
"-language:implicitConversions"
"-unchecked"
"-Xcheckinit"
"-Xlint:adapted-args"
"-Xlint:constant"
"-Xlint:delayedinit-select"
"-Xlint:deprecation"
"-Xlint:doc-detached"
"-Xlint:inaccessible"
"-Xlint:infer-any"
"-Xlint:missing-interpolator"
"-Xlint:nullary-unit"
"-Xlint:option-implicit"
"-Xlint:package-object-classes"
"-Xlint:poly-implicit-overload"
"-Xlint:private-shadow"
"-Xlint:stars-align"
"-Xlint:strict-unsealed-patmat"
"-Xlint:type-parameter-shadow"
"-Xlint:-byname-implicit"
"-Wunused:nowarn"
"-Wdead-code"
"-Wextra-implicit"
"-Wnumeric-widen"
"-Wunused:implicits"
"-Wunused:explicits"
"-Wunused:imports"
"-Wunused:locals"
"-Wunused:params"
"-Wunused:patvars"
"-Wunused:privates"
"-Wvalue-discard"
"-Vimplicits"
"-Vtype-diffs"
"-Xsource:3.0"
using resources "./src/main/resources"
using libs
"io.circe::circe-generic:0.14.1"
"io.circe::circe-parser:0.14.1"
"io.circe::circe-literal:0.14.1"
"org.typelevel::cats-effect:3.2.2"
"org.http4s::http4s-ember-client:0.23.0-RC1"
"org.http4s::http4s-circe:0.23.0-RC1"
"ch.qos.logback:logback-classic:1.2.3"
"org.systemfw::dynosaur-core:0.3.0"
"com.github.cb372::cats-retry:3.0.0"
"io.chrisdavenport::cormorant-fs2:0.5.0-M1"
"io.chrisdavenport::cormorant-generic:0.5.0-M1"
"io.github.timwspence::cats-stm:0.11.0"
|
Beta Was this translation helpful? Give feedback.
-
I like the idea of keeping it simple -- then people does not need to learn HCON just to put it in a file. It is indeed much more uniform to have the same syntax and semantics in the simple comment based `// using ...``and in the config file. The potential strengths of HCON does not compensate for the added complexity IMHO. |
Beta Was this translation helpful? Give feedback.
-
I guess I believe the word I don't mean parsing ambiguity; I mean ambiguity in speech, in casual references to Two possible alternatives:
|
Beta Was this translation helpful? Give feedback.
-
When now the scala-cli == the new scala is accepted by the SIP committee as an official thing in stage experimental, I think we should set up an official thread at https://contributors.scala-lang.org/ to gather feedback and link to that from the official download page from scala-lang.org when an installer is ready that makes the new |
Beta Was this translation helpful? Give feedback.
-
ok great (sorry for trying to land that potato in your knee :) ) I can start a thread myself at contributors if not someone from Virtuslabs rather prefer to do it, e.g. @romanowski |
Beta Was this translation helpful? Give feedback.
-
@bjornregnell we will set up a feedback thread within the next few days. I wonder maybe we should now have a general thread for Scala CLI = Scala and one specialized for using directives? |
Beta Was this translation helpful? Give feedback.
-
@romanowski I think I prefer one thread where you 1) explain that it was accepted by the SIP committee as experimental an 2) outline a couple of areas where we want feedback in particular including the using syntax. I prefer one thread so that contributors that want to give feedback knows where to go (although a downside could be that the thread might get too long, but we could always spawn sub-threads later). I also think that there should be ready, when the feedback thread goes live, a link to an installer on the scala-lang.org Install page where visitors can choose between the old and new |
Beta Was this translation helpful? Give feedback.
-
I would like to re-raise the issue of the choice of the word It was initially chosen exactly because it is a Scala 3 keyword, and the idea was to allow it at the top level: Since then, we have settled on the It seems to me that the original reason for choosing I thought this might be resolvable here on this thread, but since there hasn't been much discussion, I'm inclined to push to bring it up at the next SIP meeting (cc @lrytz). I don't have a strong feeling whether it's better to choose a different word, or omit the word and simply have |
Beta Was this translation helpful? Give feedback.
-
Thanks @SethTisue for reminding us of this relaxed constraint opportunity on directives. Yes if it should be changed, the sooner the better. I'm happy to bring this up on the next SIP meeting @julienrf if we can prepare the agenda item before the meeting by discussing this here, in particular focus on peoples' views on:
In regards to number 2 I propose
I have actually more than once by accident written |
Beta Was this translation helpful? Give feedback.
-
If there's any chance we're going to modify the syntax of using directives I think it would be good to take into account the fact that currently there are actually two kinds of directives, with very different semantics, and clear separation of them would be beneficial:
So while in most cases it doesn't really matter in which file a directive is added, it does matter if this file also contains any target directives because then the "setting" directive will be applied only in this build scope. Even though |
Beta Was this translation helpful? Give feedback.
-
I have now pinged the community for specific input here: https://contributors.scala-lang.org/t/pre-sip-scala-cli-as-new-scala-command/5628/28?u=bjornregnell @SethTisue @tgodzik @julienrf @prolativ @som-snytt @keynmol Let me know if I can improve something in the above post on contributors to better solicit good feedback. |
Beta Was this translation helpful? Give feedback.
-
I also just noted that there is a big red warning on that |
Beta Was this translation helpful? Give feedback.
-
I have just written a summary of the discussions by contributors and a sketch of my recommendation here: https://contributors.scala-lang.org/t/pre-sip-scala-cli-as-new-scala-command/5628/79?u=bjornregnell |
Beta Was this translation helpful? Give feedback.
-
My current thinking, informed by the engaging debate at contributors, including arguments and counter-arguments for using
and then encourage a new SIP with a proposal base on more analysis of different use cases and requirements on a possible configuration syntax including the potential of alignment across runner and other tools, in dialog with maintainers of such tools. If it should be based on some subset of JSON, TOML, YAML, ..., is part of that investigation, in conjunction with a new SIP. If such a future SIP proposal is successful, then the current |
Beta Was this translation helpful? Give feedback.
-
I just realized I don't know how Currently, partest's I haven't experimented yet, but might guess that |
Beta Was this translation helpful? Give feedback.
-
Inevitable bikeshedding is about to happen :) I think the directives syntax not being valid Scala code is the most controversial aspect surrounding this amazing tool, so I was hoping we can discuss it.
This discussion is foreshadowed and linked to from the https://scala-cli.virtuslab.org/docs/guides/using-directives#most-important-using-directives-supported-by-scala-cli page - but the discussion link just doesn't exist.
Currently, there are 3 documented ways of using directives:
using ...
//using ...
@using ...
The only one that immediately works with any tooling (scalameta, Metals, regular Scala compiler CLI, what have you) is the
// using
one.The documentation states that
But I foresee the following issues with this:
using
is a soft keyword in Scala 3, so if it's not part of the comment, it will confuse both the users and the highlightersusing
directives when used with naked compiler (not scala-cli)? Is the expectation to just not expose the nakedscala
REPL anymore?mdoc
do with directives, given that they interact directly with the compiler? Will the compiler interface handle artifact resolution and classpath?This is a long lead up to the main question:
Why shouldn't
using
directives stay comments or valid Scala syntax like (import $ivy....
) if it enables existing tooling to work seamlessly?Update: to set the tone a little bit, I understand the experimental nature of directives and as such want to offer feedback and discussion, not treat it as a done deal I disagree with :)
Beta Was this translation helpful? Give feedback.
All reactions