Last updated on
Week 12 Debrief: Futures, and the last step towards complete webapps
Congrats on completing your 12th week of CS-214! Here is a round-up of interesting questions, tips for exercises and labs, and general notes about the course.
Administrivia
-
We have automatically assigned everyone a checkoff slot for unguided lab. If you cannot attend yours, you can change it by following the link on Moodle. Make sure that everyone in your team agrees before changing your assigned slot, and don’t move other teams!
-
The unguided lab is due Friday 12th at 23:00, but we will grant an automatic 48-hour extension (to Sunday, 11PM).
- The Moodle submission page will open soon. Submit ahead of the deadline to rule out last-minute issues.
- Remember that your code should be in a package called
apps.<yourAppId>. Using custom names will fail the auto-grader. - If you have registered for an early checkoff (Friday 12th December), you must turn in the lab before your checkoff.
-
We will have a dry-run of the final exam on Wednesday, December 17th. Attendance is mandatory; we will announce the seating plans soon.
-
Do not use copyrighted materials in your webapps. See below for more details.
Interesting Ed questions
-
Unguided labs
-
Futures
-
Safe effects
How does ScalaCheck know how to generate values?
ScalaCheck uses the Gen[T] trait to generate instances of T, using the .sample method. For example, Gen.choose(1, 18) returns a Gen[Int] instance whose sample method picks arbitrary elements in the range 1 .. 18.
But how does ScalaCheck know which Gen[T] instance to use to generate values when checking a property? It uses the Arbitrary[T] typeclass! Arbitrary[T] has just one field: def arbitrary: Gen[T], from which ScalaCheck gets the Gen instance.
This lets us define custom generators and connect them to ScalaCheck’s infrastructure. For example:
enum Direction:
case North, East, South, West
def rotate: Direction = this match
case North => East
case East => South
case South => West
case West => North
2025-12-08/gen.sc
import org.scalacheck.{Gen, Arbitrary}
given Arbitrary[Direction] = Arbitrary:
import Direction.*
Gen.oneOf(North, South, East, West)
2025-12-08/gen.sc
// Sample one direction
summon[Arbitrary[Direction]].arbitrary.sample
2025-12-08/gen.sc
// Test one property
import org.scalacheck.Prop.forAll
forAll { (d: Direction) =>
d.rotate.rotate.rotate.rotate == d
}.check()
2025-12-08/gen.sc
Unguided lab updates
Our advice for this week
At this point, you should have a second prototype with almost all functionality complete. In the last few days, we recommend:
- Polishing the implementation, making sure that existing features work before implementing new ones.
- Testing on mobile. We won’t grade you on that, but your app will be much more usable if it works on mobile too.
- Adding (more) tests, to reveal corner cases.
- Reviewing the unguided lab policies to avoid losing easy points. This is very important! Last year multiple groups lost points on simple things like documentation for no good reason…
- Preparing the demo.