Skip to content
Snippets Groups Projects
Commit c1844619 authored by Guillaume Martres's avatar Guillaume Martres
Browse files

Update example.md

parent 272db37f
No related branches found
No related tags found
No related merge requests found
......@@ -12,9 +12,6 @@ We'll starting by cloning the repository containing all our assignment (make
sure to replace `GASPAR` with your EPFL username (the one with letters, not the
one with number) in the following command).
**THE FOLLOWING WILL NOT WORK YET, CHECK BACK LATER**
```shell
git clone -b example git@gitlab.epfl.ch:lamp/student-repositories-f19/cs210-GASPAR.git cs210-example
```
......@@ -23,12 +20,6 @@ git clone -b example git@gitlab.epfl.ch:lamp/student-repositories-f19/cs210-GASP
cd cs210-example
```
**IMPORTANT:** The `example` branch you just cloned contains your assignment, but is read-only on our server, **you should not try to edit it**.
To be able to submit your assignment you need to **create your own branch** to work in:
```shell
git checkout -b my-example
```
Now that we've obtained the project, let's take a look at its structure:
```shell
......@@ -58,17 +49,24 @@ Start sbt by running:
sbt
```
Once it's finished starting (this may take a while), you'll be able to enter sbt commands. You can compile your project using `compile` and run the tests with `test`. Note that if compilation fails, no tests will be run. The first time you will run test in an assignment you should see many errors: that's normal, your job is to make the tests pass! To do this, it's useful to understand in details what the test output means, here's an example:
Once it's finished starting (this may take a while), you'll be able to enter sbt
commands. You can compile your project using `compile` and run the tests with
`test` (this automatically compiles your code if needed to). Note that if
compilation fails, no tests will be run. The first time you'll run `test` in an
assignment you should see many errors: that's normal, your job is to make the
tests pass! To do this, it's useful to understand in details what the test
output means, here's an example:
![](images/sbt-test-error.png)
This tells us several things:
- There's a test named `max of a few numbers` in the class `ListsSuite` in the package `example`
- There's a test named `max of a few numbers (10pts)` in the class `ListsSuite` in the package `example`
- The test failed with an exception: `scala.NotImplementedError: an implementation is missing`. This is followed by a stack trace showing where the exception happened.
- This exception was thrown from the method `scala.Predef$.$qmark$qmark$qmark` in the file `Predef.scala` at line 284.
- This method was called from `example.Lists$.max`
- ... which was itself called from the method `example.ListsSuite.max of a few numbers`
- This exception was thrown from the method `scala.Predef$.???` in the file `Predef.scala` at line 284.
- This method was called from `example.Lists$.max` in the file `Lists.scala` at line 41.
- ... which was itself called from the method `example.ListsSuite.max of a few
numbers` in the file `ListsSuite.scala` at line 83.
It's now time to look at some code: the next section will show you how to start and navigate using the IDE.
......@@ -132,19 +130,17 @@ This means that `max` is a method that takes a `List` of `Int` as argument and r
Now we know why the test failed: `max` calls `???`, which is a method defined in the Scala standard library that simply crashes your program: whenever you see it in an assignment it means that this is something you need to replace by your own implementation.
There's one mystery left, the first line of the stack trace was:
```scala
at scala.Predef$.$qmark$qmark$qmark(Predef.scala:284)
```
But what do all these dollars mean? It's not because we're mining crypto-currencies on your computer: it turns out that when Scala code is compiled to Java bytecode, some names need to be translated to be valid. In particular, `?` is translated to `$qmark`, and `object Predef` is translated to `Predef$`, so all this is saying is that the crash occurred when running the method `???` defined in the object `Predef` in the package `scala`, as expected.
You now know enough to be able to work with the IDE, here are some additional tips:
- When you press `Enter` to make a new line, the IDE will automatically indent the
line if needed (for example, if the last word on the previous line was
`then`), however it will never unindent code for you (for example, when
writing `else`). You can always indent code manually by pressing `Tab` and
unindent it by pressing `Shift + Tab`.
- When working on an assignment, you are free to create as many methods, classes and objects as you want. **But you shouldn't change the name of existing methods, classes and objects, because that may break the automated grading system, this is important!**.
- You can see a list of all warnings and errors reported by the compiler by clicking on ![](warnings-errors.png) at the bottom left of VSCode.
- You can see a list of all warnings and errors reported by the compiler by clicking on ![](images/warnings-errors.png) at the bottom left of VSCode.
- The IDE can show you on hover the documentation of classes, defs and vals defined in the current project but support for external project is currently missing. To compensate for this, you can consult the documentation online:
- The documentation for the Scala standard library is at [https://www.scala-lang.org/files/archive/api/2.12.8/](https://www.scala-lang.org/files/archive/api/2.12.8/)
- The documentation for the Scala standard library is at [https://www.scala-lang.org/files/archive/api/2.13.1/](https://www.scala-lang.org/files/archive/api/2.13.1/)
- The documentation for the Java standard library is at [https://docs.oracle.com/en/java/javase/11/docs/api/index.html](https://docs.oracle.com/en/java/javase/11/docs/api/index.html)
- You can customize Visual Studio Code as much as you want, including installing additional extensions, but please avoid installing other Scala-related extensions: they may conflict with the one we use for this course.
- While working on your assignment, you will regularly want to go back to the sbt console to run the tests. You could simply run the command `test` every time, but you can take advantage of the watch mode instead: if a command is prefixed by `~`, sbt will watch the source directory for changes and re-run the command every time a file is saved. So a possible workflow is:
......@@ -154,7 +150,9 @@ You now know enough to be able to work with the IDE, here are some additional ti
3. Once the IDE has started, go back to sbt and run `~test` (or run `~compile` if you don't want to look at the tests)
4. Work in the IDE, and check the output of the sbt console from time to time
- We're actively working on improving the IDE support using Visual Studio Code and interested in hearing your ideas and suggestions. Feel free to share your feedback (both good and bad) with us on Moodle!
- We're actively working on improving the IDE support using Visual Studio Code
and interested in hearing your ideas and suggestions. Feel free to share your
feedback (both good and bad) with us using Gitlab issues!
## Part 4: Running your code
......@@ -197,6 +195,15 @@ scala> max(List(1,3,2))
res1: Int = 3
```
You can enter a multiline expression in the REPL by using `Alt+Enter`
(`Option+Enter` on macOS) instead of `Enter`:
scala> if 1 == 1 then
| "a"
| else
| "b"
val res0: String = a
In order to exit the Scala REPL and go back to sbt, type `Ctrl+D`.
### The worksheet mode
......
week1/images/sbt-test-error.png

53.2 KiB | W: | H:

week1/images/sbt-test-error.png

59.7 KiB | W: | H:

week1/images/sbt-test-error.png
week1/images/sbt-test-error.png
week1/images/sbt-test-error.png
week1/images/sbt-test-error.png
  • 2-up
  • Swipe
  • Onion skin
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment