|
1 | | -# Hints |
2 | | -According to [this terminology](http://chimera.labs.oreilly.com/books/1230000000929/ch01.html#sec_terminology) you should write a *parallel* and *deterministic* |
3 | | -program and (by all means!) let Scala deal with the *concurrency* aspect. |
4 | | -Or else your code could quickly get messy and error-prone with all kinds of nasty |
5 | | -concurrency bugs. In particular your program could become indeterministic |
6 | | -which spells in practice: very (in fact, VERY) hard to debug, test and reason about. |
7 | | - |
8 | | -Having said that it might be a good idea to first write a sequential solution (and |
9 | | -use the test suite to verify it). |
10 | | -Only then should you try to parallelize it while keeping the sequential and parallel |
11 | | -portions of your code as separate as possible. |
12 | | - |
13 | | -A first iteration could be using Scala's [parallel collections](http://docs.scala-lang.org/overviews/parallel-collections/overview.html). You might find |
14 | | -that this is almost too simple (especially if you have followed our advice and |
15 | | -already have a sequential solution). |
16 | | - |
17 | | -For the second iteration we recommend you try a solution with [scala.concurrent.Future](http://www.scala-lang.org/api/current/scala/concurrent/Future$.html). |
18 | | -You can consult [this tutorial](http://danielwestheide.com/blog/2013/01/09/the-neophytes-guide-to-scala-part-8-welcome-to-the-future.html) and [its sequel](http://danielwestheide.com/blog/2013/01/16/the-neophytes-guide-to-scala-part-9-promises-and-futures-in-practice.html) for some help. |
| 1 | +# Instructions append |
| 2 | + |
| 3 | +## Hints |
| 4 | + |
| 5 | +According to [this terminology][terminology] you should write a *parallel* and *deterministic* program and (by all means!) let Scala deal with the *concurrency* aspect. |
| 6 | +Or else your code could quickly get messy and error-prone with all kinds of nasty concurrency bugs. |
| 7 | +In particular your program could become indeterministic which spells in practice: very (in fact, VERY) hard to debug, test and reason about. |
| 8 | + |
| 9 | +Having said that it might be a good idea to first write a sequential solution (and use the test suite to verify it). |
| 10 | +Only then should you try to parallelize it while keeping the sequential and parallel portions of your code as separate as possible. |
| 11 | + |
| 12 | +A first iteration could be using Scala's [parallel collections]. |
| 13 | +You might find that this is almost too simple (especially if you have followed our advice and already have a sequential solution). |
| 14 | + |
| 15 | +For the second iteration we recommend you try a solution with [`scala.concurrent.Future`][Future]. |
| 16 | +You can consult [this tutorial][tutorial] and [its sequel][sequel] for some help. |
19 | 17 | Make sure that you |
| 18 | + |
20 | 19 | - have only one single blocking call to wait for the result |
21 | 20 | - that it is at the very end of your program, and |
22 | 21 | - that it has a timeout. |
23 | 22 |
|
24 | | -`scala.concurrent.Future` is used in many libraries and the doctor's advice for |
25 | | -parallel and asynchronous programming in Scala. So it is essential for mastering |
26 | | -the language and it should become part of your Scala armory. |
| 23 | +`scala.concurrent.Future` is used in many libraries and the doctor's advice for parallel and asynchronous programming in Scala. |
| 24 | +So it is essential for mastering the language and it should become part of your Scala armory. |
| 25 | + |
| 26 | +[terminology]: http://chimera.labs.oreilly.com/books/1230000000929/ch01.html#sec_terminology |
| 27 | +[parallel collections]: http://docs.scala-lang.org/overviews/parallel-collections/overview.html |
| 28 | +[Future]: http://www.scala-lang.org/api/current/scala/concurrent/Future$.html |
| 29 | +[tutorial]: http://danielwestheide.com/blog/2013/01/09/the-neophytes-guide-to-scala-part-8-welcome-to-the-future.html |
| 30 | +[sequel]: http://danielwestheide.com/blog/2013/01/16/the-neophytes-guide-to-scala-part-9-promises-and-futures-in-practice.html |
0 commit comments