Skip to content

Commit 7d7edae

Browse files
committed
Reviewed the Getting Started file
1 parent 39af244 commit 7d7edae

File tree

1 file changed

+40
-39
lines changed

1 file changed

+40
-39
lines changed

website/docs/getting_started.md

Lines changed: 40 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ sidebar_position: 2
66
import {ChainedSnippets, GiflikeVideo} from "../src/components/MarkdownComponents.js";
77

88
:::info
9-
This article requires knowledge of Scala language (how to define class or method) as well as Scala tooling (repl, basics of dependency management and unit tests).
9+
This article requires knowledge of the Scala language (how to define a class or method) as well as Scala tooling (the REPL, and basics of dependency management and unit tests).
1010
:::
1111

12-
In this article we will show how to use Scala CLI to create basic script followed by small project with things like dependencies, tests and IDE support. We aime to provide you with a knowledge how to create and develop your first projects using Scala CLI.
12+
In this article we show how to use Scala CLI to create a basic script, followed by small project with features like dependencies, tests, and IDE support. We aim to provide you with a knowledge of how to create and develop your first projects using Scala CLI.
1313

14-
Firstly, lets verify if Scala CLI is properly [installed](/install) with a simple hello world command:
14+
First, let's verify if Scala CLI is properly [installed](/install) with a simple "hello world" test:
1515

1616
<ChainedSnippets>
1717

@@ -29,11 +29,11 @@ Hello
2929

3030
</ChainedSnippets>
3131

32-
Running the command for the first time may take a bit longer then usual and print a bit logs because Scala CLI needs to download all artifacts needed to compile and run the code.
32+
Running this command the first time may take a bit longer then usual and print a fair number of logging output because Scala CLI needs to download all the artifacts it needs to compile and run the code.
3333

3434
## Scripting
3535

36-
In fact, we have just created a Scala Script, so let's create a script in a hello.sc file, that will actually greet properly.
36+
In that example we actually just created a Scala Script. To demonstrate this more fully, let's create a script in a `hello.sc` file that greets more properly:
3737

3838
```scala title=hello.sc
3939
def helloMessage(names: Seq[String]) = names match
@@ -45,8 +45,7 @@ def helloMessage(names: Seq[String]) = names match
4545
println(helloMessage(args.toSeq))
4646
```
4747

48-
Now let run it with:
49-
48+
When that script is given no names, it prints `"Hello!"`, and when it’s given one or more names it prints the string that's created in the second `case` statement. With Scala CLI we run the script like this:
5049

5150
<ChainedSnippets>
5251

@@ -59,7 +58,7 @@ Hello
5958
```
6059
</ChainedSnippets>
6160

62-
To provide arguments to the script we need to add them after `--`:
61+
To provide arguments to the script we add them after `--`:
6362

6463
<ChainedSnippets>
6564

@@ -73,19 +72,21 @@ Hello Jenny, Jake!
7372

7473
</ChainedSnippets>
7574

76-
You may wonder what kind of Scala version was used under the hood. The answer is the latest stable one. If we want to specify the Scala version we can use `-S` or `--scala` option. More about setting Scala version in a dedicated [cookbook](./cookbooks/scala-versions.md).
75+
You may wonder, what kind of Scala version was used under the hood in that example? The answer is the latest stable one. If we want to specify the Scala version, we can use the `-S` (or `--scala`) option. You can read more about setting the Scala version in our dedicated [Scala Versions cookbook](./cookbooks/scala-versions.md).
7776

78-
Scala CLI offers much more features dedicated for scripting described in the [dedicated guide](./guides/scripts.md)
77+
Scala CLI offers many more features dedicated for scripting, as described in the [dedicated guide](./guides/scripts.md).
7978

8079
## Dependencies
8180

82-
Let's build something more serious. Best start is prototyping inside REPL. We can start a repl by simply running `scala-cli repl` and here we can also set a Scala version with `-S` or `--scala`.
81+
Now let's build something more serious. For this example, it's best to start with some prototyping inside the REPL. We can start a REPL session by running `scala-cli repl`. (If desired, you can also set the Scala version with `-S` or `--scala`.)
8382

84-
*Scala CLI reuses most of its options across all its comments.**
83+
:::note
84+
Scala CLI reuses most of its options across all its comments.
85+
:::
8586

86-
One of the main strengths of Scala is its ecosystem. Scala CLI is designed in a way to expose Scala Ecosystem to all usages of Scala and running REPL is no exception.
87+
One of the main strengths of Scala is its ecosystem. Scala CLI is designed in a way to expose the Scala ecosystem to all usages of Scala, and running the REPL is no exception.
8788

88-
Let's start prototyping with [os-lib](https://github.com/com-lihaoyi/os-lib) - a Scala interface to common OS filesystem and subprocess. To experiment with `os-lib` in repl we simply need to add a parameter `--dep com.lihaoyi::os-lib:0.7.8`
89+
To demonstrate this, let's start prototyping with [os-lib](https://github.com/com-lihaoyi/os-lib) a Scala interface to common OS filesystem and subprocess methods. To experiment with `os-lib` in the REPL, we simply need to add the parameter `--dep com.lihaoyi::os-lib:0.7.8`, as shown here:
8990

9091
<ChainedSnippets>
9192

@@ -105,17 +106,17 @@ val res1: IndexedSeq[os.Path] = ArraySeq(...)
105106

106107
## A project
107108

108-
Now is time to write some logic, based on the prototyping we have just did: a filter function to display all files with given extension in current directory.
109+
Now it's time to write some logic, based on the prototyping we just did. We'll create a filter function to display all files with the given filename extension in the current directory.
109110

110-
For the consistency of our results let's create a new directory and `cd` to it:
111+
For the consistency of our results, let's create a new directory and `cd` to it:
111112

112113
```bash
113114
mkdir scala-cli-getting-started
114115
cd scala-cli-getting-started
115116
```
116117
<!-- clear -->
117118

118-
Now we can write our logic in `files.scala`:
119+
Now we can write our logic in a file named `files.scala`:
119120

120121
```scala title=files.scala
121122
// using lib com.lihaoyi::os-lib:0.7.8
@@ -128,32 +129,31 @@ def filesByExtension(
128129
}
129130
```
130131

131-
As you may have noticed we specified a dependency within the `.scala` using `// using lib com.lihaoyi::os-lib:0.7.8`. In Scala CLI configuration can be provided through so called using directives - a dedicated syntax that can be embedded in any `.scala` file. We have a dedicated [guide for using directives](./guides/using-directives.md).
132+
As you may have noticed, we specified a dependency within `files.scala` using the `// using lib com.lihaoyi::os-lib:0.7.8` syntax. With Scala CLI, you can provide configuration information with `using` directives a dedicated syntax that can be embedded in any `.scala` file. For more details, see our dedicated [guide for `using` directives](./guides/using-directives.md).
132133

133-
Let's check if our code compiles. We can do that by simply running:
134+
Now let's check if our code compiles. We do that by running:
134135

135136
```bash
136137
scala-cli compile .
137138
```
138139

139-
This time we did not provide path to single files but rather used a (current) directory. For project-like use-cases we recommend providing directories rather then individual files. More most cases a current directory (`.`) is best choice.
140+
Notice that this time we didn’t provide a path to single files, but rather used a directory; in this case, the current directory. For project-like use cases, we recommend providing directories rather than individual files. For most cases, specifying the current directory (`.`) is a best choice.
140141

141142
## IDE support
142143

143-
Some people are fine working using command line only, but most Scala Developers use an IDE. Let's open Metals with your favorite editor inside `scala-cli-getting-started` directory.
144-
144+
Some people are fine using the command line only, but most Scala developers use an IDE. To demonstrate this, let's open Metals with your favorite editor inside `scala-cli-getting-started` directory:
145145

146146
<GiflikeVideo url='/img/scala-cli-getting-started-1.mp4'/>
147147

148-
At this moment support for IntelliJ is often problematic. We are working on making it as rock solid as Metals one.
148+
At the present moment, support for IntelliJ is often problematic. But know that we are working on making it as rock-solid as Metals.
149149

150-
Actually, we've cheated a bit by running compilation first. In order for Metals or IntelliJ to pick up Scala CLI project we need to generate a BSP connection detail file. Scala CLI generate such details by default every time `compile`, `run` or `test` are run. We expose a `setup-ide` command to manually control creation of connection details file. You can find more details in [IDE guide](./guides/ide.md).
150+
Actually, in this case, we cheated a bit by running the compilation first. In order for Metals or IntelliJ to pick up a Scala CLI project, we need to generate a BSP connection detail file. Scala CLI generates these details by default every time `compile`, `run`, or `test` are run. We also expose a `setup-ide` command to manually control creation of the connection details file. For more information on this, see our [IDE guide](./guides/ide.md).
151151

152152
## Tests
153153

154-
With IDE in place, how can we test if our code works correctly? Best way is to create unit test. The simplest way to add a test using scala-cli is by creating a file named that it ends with `.test.scala` like `files.test.scala`. There are also other ways to mark source a test described in [tests guide](./commands/test.md#test-sources).
154+
With our IDE in place, how can we test if our code works correctly? The best way is to create a unit test. The simplest way to add a test using scala-cli is by creating a file whose name ends with `.test.scala`, such as `files.test.scala`. (There are also other ways to mark source code files as containing a test, as described in [tests guide](./commands/test.md#test-sources).)
155155

156-
We also need to add a test framework. Scala CLI support most popular test frameworks and for this guide we will stick to [munit](https://scalameta.org/munit/). To add a test framework we just need an ordinary dependency that we will add with `using` directive again:
156+
We also need to add a test framework. Scala CLI support most popular test frameworks, and for this guide we will stick with [munit](https://scalameta.org/munit/). To add a test framework, we just need an ordinary dependency, and once again we'll add that with the `using` directive:
157157

158158
```scala title=files.test.scala
159159
// using lib org.scalameta::munit:1.0.0-M1
@@ -167,7 +167,7 @@ class TestSuite extends munit.FunSuite {
167167
}
168168
```
169169

170-
Now we can run our tests in command line:
170+
Now we can run our tests at the command line:
171171

172172
<ChainedSnippets>
173173

@@ -190,7 +190,7 @@ or directly within Metals:
190190

191191
## A project, vol 2
192192

193-
With our code ready and tested it is now time to turn it into a command-line tool to count files by extension. For that we can write a simple script. With Scala CLI, scripts and scala sources can be mixed.
193+
With our code ready and tested, now it's time to turn it into a command-line tool that counts files by their extension. For this we can write a simple script. A great feature of Scala CLI is that scripts and Scala sources can be mixed:
194194

195195
```scala title=countByExtension.sc
196196
val (ext, directory) = args.toSeq match
@@ -204,11 +204,11 @@ val files = filesByExtension(ext, directory)
204204
files.map(_.relativeTo(directory)).foreach(println)
205205
```
206206

207-
As you probably noticed, we are using `os-lib` in our script without any using directive, how is that possible? Actually, configuration provided by using directives are global and applies to all files. Since `files.scala` and `countByExtension.sc` are compiled together. Defining a library dependency in more then one file is an anti-pattern.
207+
As you probably noticed, we are using `os-lib` in our script without any `using` directive; how is that possible? The way this works is that configuration details provided by `using` directives are global, and apply to all files. Since `files.scala` and `countByExtension.sc` are compiled together, the `using` directives in `files.scala` are used when compiling both files. (Note that defining a library dependency in more than one file is an anti-pattern.)
208208

209-
<!-- TODO add pice about scala-cli warnings in such case -->
209+
<!-- TODO add piece about scala-cli warnings in such case -->
210210

211-
Let's try it:
211+
Now let's run our code, looking for all files that end with the `.scala` extension:
212212

213213
<ChainedSnippets>
214214

@@ -224,30 +224,31 @@ files.test.scala
224224

225225
</ChainedSnippets>
226226

227-
Why do we have an additional `.scala` file inside `.scala` dir? Actually, under the hood, Scala CLI needs sometimes to preprocess provided source file (e.g. for scripts) and we compile such file from within `.scala` directory.
227+
Seeing that output, you may wonder, why do we have an additional `.scala` file under the `.scala` dir? The way this works is that under the hood, Scala CLI sometimes needs to preprocess source code files — such as scripts. So these preprocessed files are created under the `.scala` directory, and then compiled from there.
228228

229229
## Packaging
230230

231-
We could stop here and call scala-cli on set of sources every time. Scala CLI uses caches aggressively so rollup runs are reasonable fast (less around 1500 milliseconds on my machine) but sometimes it is not fast enough or shipping sources and compiling them may be not convenient.
231+
We could stop here and call `scala-cli` on our set of sources every time. Scala CLI uses caches aggressively, so rollup runs are reasonably fast less than 1,500 milliseconds on my machinebut sometimes this isn't fast enough, or shipping sources and compiling them may be not convenient.
232232

233-
Scala CLI offers means to package your project. We can simply run:
233+
For these use cases, Scala CLI offers means to package your project. For example, we can run this command to generate a thin, executable jar file, with the compiled code inside:
234234

235235
```bash
236236
scala-cli package . -o countByExtension
237237
```
238238

239-
It will generate a thin, executable jar with the compiled code inside. We provided `-o` flag to customize the binary name (by default application is written as `app`). Now we can run our project with:
239+
The default binary name is `app`, so in this example we provide the `-o` flag to make the binary name `countByExtension`. Now we can run our project like this:
240240

241241
```bash
242242
./countByExtension scala
243243
```
244244

245-
This time it took 350 milliseconds so we have a big improvement. Created binary (a runnable jar) is self-contained and can be shipped to your colleagues or deployed.
245+
This time it only took 350 milliseconds, so this is a big improvement. When you create a binary file (a runnable jar) like this, it's self-contained, and can be shipped to your colleagues or deployed.
246+
247+
We can reduce the startup time even further using [Scala Native](./guides/scala-native.md), or by packaging our application to other formats like [Docker container](./commands/package.md#docker-container), [assembly](./commands/package.md#assemblies), or even [OS-specific packages](./commands/package.md#os-specific-packages) (.dep, .pkg, etc.). See those resources for more information.
246248

247-
We can reduce the start up time even further using [Scala Native](./guides/scala-native.md) or package our application to other formats like [Docker container](./commands/package.md#docker-container), [assembly](./commands/package.md#assemblies) or even [os-specific packages](./commands/package.md#os-specific-packages) (.dep, .pgk etc.) All of this is outside of the scope of this guide.
248249

249250
## Summary
250251

251-
We've only scratch the surface what Scala CLI can do with this guide. We prepare a set of [cookbooks](./cookbooks/intro.md) showcasing solutions to some common problems as well as detailed set of [guides](./guides/intro.md) for our [commands](./commands/basics.md).
252+
With this guide we've only scratched the surface of what Scala CLI can do. For many more details, we've prepared a set of [cookbooks](./cookbooks/intro.md) that showcase solutions to common problems, as well as a detailed set of [guides](./guides/intro.md) for our [commands](./commands/basics.md).
252253

253-
We have a dedicated [room on Scala discord](https://discord.gg/KzQdYkZZza) to ask for help or discuss anything that is Scala CLI related. For more in-depth discussion we are using [Github discussion in our repo](https://github.com/VirtusLab/scala-cli/discussions) and this is a best place to suggest a new feature or an improvements.
254+
We also have a dedicated [room on Scala discord](https://discord.gg/KzQdYkZZza) where you can ask for help or discuss anything that's related to Scala CLI. For more in-depth discussions, we're using [Github discussions in our repo](https://github.com/VirtusLab/scala-cli/discussions); this is the best place to suggest a new feature or any improvements.

0 commit comments

Comments
 (0)