Code Monkey home page Code Monkey logo

creative-scala's People

Contributors

ceedubs avatar d43 avatar dependabot[bot] avatar domnantas avatar eli-hu avatar mattkohl avatar mbren avatar michaeljosephpurdy avatar mmynsted avatar noelhwelsh avatar noelwelsh avatar tkfu avatar zg avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

creative-scala's Issues

question: operator style

https://www.creativescala.org/creative-scala.html#values-are-objects 2.2.2 Operators says:

1 + 2
// res4: Int = 3

1.+(2)
// res5: Int = 3

This second way of calling a method is known an operator style.

I've never heard of this name before. Is this "operator style" term used somewhere else? I am not sure if I'd associate dot-and-paren style more with "operator" than the infix notation, since operator precedence etc would affect infix notation more.

Setup / Getting Started Process is Unclear

Creative Scala doesn't do a very good job explaining the setup process for people who are not already fairly proficient programmers:

  • get the JVM, if you don't have it already
  • get a text editor
  • get Doodle
  • run sbt

Include how to open the command line on Windows etc.

Pattern matching unclear

Feedback from teaching a course is that the chapter on Lists, which introduces more pattern matching forms, is unclear. All the students struggled with the syntax for pattern matching. Clarify this.

Dependencies on Xcode?

$ npm install
npm WARN package.json [email protected] No repository field.
npm WARN package.json [email protected] No repository field.
[email protected] node_modules/underscore-ebook-template
└── [email protected] ([email protected], [email protected])
$ grunt pdf
Running "pandoc:pdf" (pandoc) task
Running shell command: pandoc --smart --output=dist/creative-scala.pdf --template=node_modules/underscore-ebook-template/lib/templates/template.tex --from=markdown+grid_tables+multiline_tables+fenced_code_blocks+fenced_code_attributes+yaml_metadata_block+implicit_figures+header_attributes+definition_lists --latex-engine=xelatex --variable=lib-dir:node_modules/underscore-ebook-template/lib --filter=node_modules/underscore-ebook-template/lib/filters/pdf/callout.coffee --filter=node_modules/underscore-ebook-template/lib/filters/pdf/columns.coffee --filter=node_modules/underscore-ebook-template/lib/filters/pdf/solutions.coffee --filter=node_modules/underscore-ebook-template/lib/filters/pdf/vector-images.coffee --chapters --number-sections --table-of-contents --highlight-style tango --standalone --self-contained --include-before-body=node_modules/underscore-ebook-template/lib/templates/cover-notes.tex src/meta/metadata.yaml src/meta/pdf.yaml src/pages/intro/index.md src/pages/expressions/index.md src/pages/expressions/simple.md src/pages/expressions/images.md src/pages/expressions/take-home-points.md src/pages/declarations/index.md src/pages/declarations/value-declarations.md src/pages/declarations/method-declarations.md src/pages/declarations/color-palette.md src/pages/declarations/take-home-points.md src/pages/fp/index.md src/pages/fp/recursion.md src/pages/fp/functions.md src/pages/fp/take-home-points.md src/pages/collections/index.md src/pages/collections/create.md src/pages/collections/transform.md src/pages/collections/take-home-points.md src/pages/summary/index.md src/pages/quickreference/index.md src/pages/solutions.md src/pages/links.md
>> p
>> andoc: Error running filter node_modules/underscore-ebook-template/lib/filters/pdf/callout.coffee
>> fd:4: hClose: resource vanished (Broken pipe)
>> Shell command exited with code 83
Warning: Task "pandoc:pdf" failed. Use --force to continue.

Aborted due to warnings.

Some issues I ran into following the installation portion of README.md.

Define syntax

We use the term syntax in Creative Scala but do not define it. We should, given it is a fairly technical term.

question: should infix notation be used for non-symbolic method names?

I have mixed feelings (leaning towards negative) about the extensive use of infix notation in the book for code like:

circle(10) beside square(20) beside square(30)

my impression is that the Scala community experimented with this style pretty heavily for a long time, but in recent years almost everyone has retreated from it and it's not really a mainstream style anymore for ordinary, alphanumerically-named methods like beside

but my concern isn't only about what the dominant style is in the community, it's also about what an appropriate style for getting started with the language is. for years now, I've seen (on Gitter and IRC, primarily) beginners tripping themselves up with what this syntax means and how it is parsed. beginners end up using a mishmash of spaces and dots and parens and not really knowing what's going on and where infix is permitted and when it isn't and when you need parens to make it work and when you don't. it seems like a distraction to me. by sticking with a.b(c) style you bypass all these issues, freeing up mental energy to focus on more important things

would a PR changing the code to consistently use this style instead:

circle(10).beside(square(20)).beside(square(30))

be welcome...?

All sorts of little issues

Hi,

I was working through the material myself to prepare for teaching it, and I found a lot of little mistakes.
I got until chapter 9, here's everything I found.

2.4.0.4

  • The question is full of exception output which confuses the question
  • The solution starts with scala mdoc 1 + 2 which doesn't belong there
  • I am a bit surprised by String.indexOf being introduced here without any explanation of what indexOf does. It will be used as an example later in the book so it might help to clarify this.

3.1

  • The example code Image.circle(10) is shown twice.

3.2

  • The example code (Image.circle(10).beside(rectangle(10, 20))).draw() does not compile. It should be (Image.circle(10).beside(Image.rectangle(10, 20))).draw()
  • It says Doodle contains several layout methods for combining images, described in tbl. ¿tbl:pictures:layout?. That table reference is broken and so is the table shown under it doesn't render correctly. (This looks slightly different in the pdf view vs the html view but there's a problem in both)
  • All examples in the (broken) table fail to compile, because of the same reason noted above: below(circle(20)) won't work, it should be below(Image.circle(20)), unless you import Image._ first but it doesn't say anywhere to do so.

3.3

  • Another broken table, this time ¿tbl:pictures:color?

3.4

  • The title of the section is part of the example code.

3.5

  • Around this time I started running into an annoyance with trying out the example code in the console: when you paste multiline code into the REPL console (not with :paste but with the OS paste function) in some cases it seems to attempt to evaluate each line as its own expression. I am not entirely sure what causes this or what to do about this though.

3.5.3

  • I don't know if something changed in Doodle but I keep getting different pictures if I run the examples than shown in Creative Scala. The difference appears to be that the example code uses Image.circle() as if the param is the radius, while actually it is the diameter. Note that I did clone the template from github listed in the installation instructions. See attached images.
    This happens throughout the entire book.
    image1
    image2

3.6.1

  • Figure 15 does not show "Archery target with a stand" as both the description and the following exercises implies. It shows a coloured in target instead. So the picture is wrong.

4.1

  • The example with :paste is a bit strange for using Example.scala since if you put pastable code in Example.scala then on (accidental) reload of sbt you'll get a compiler error on starting the console (as explained in 4.2). Using a file that won't get compiled (e.g. something with a filename without the .scala extension) would be much clearer here.

4.2

  • At some point it might be good to mention an sbt reload is needed every time Example.scala is changed if you want to use it from the console.

5

  • The chapter intro has the wrong styling, making it so words are cut off at weird places.

5.2

  • It feels like the "Madness to our methods" exercise doesn't really explain what it expects the student to do, the solution link kinda comes out of nowhere.

6.2

  • The exercise 'halve' has a visible scala mdoc in the solution.

7.1

  • The exercise 'stacked boxes' does not show stacked boxes in the image (fig 22). Instead it shows a line of boxes. Also, while the solution says to change beside to above, the code example still says beside.

7.6

  • We could also make the fill color a function n should probably be a function OF n.
  • The concentric circles exercisse makes the problem I wrote about in 3.5.3 really obvious. To fix this case, not only the circle size should be doubled but also the amount by which the circle gets increased each recursive call.

8.2

  • Literally says "insert picture here" but you probably already knew that. :)
  • Another broken table view.

8.6

  • The exercise "Function literals" has another scala mdoc in the solution.

8.8.3

  • The link to Flowers.scala is broken.

9.1.1

  • Broken figure link in the text: ¿fig:pictures:open-closed-paths?.
  • Broken table link ¿tbl:sequences:path-element?. and also broken table.

9.3.2

  • Annoyingly, the Scala REPL doesn't show the contents of a range (anymore), 1 until 3 is not shown as (1, 2) but as Range 1 until 3. You have to convert it to see it as a list.

9.3.3

  • "If we try to create a Range over Double we get an error." No, not really. Not in the Scala version in your template project at least.
scala> 0.0 to 10.0 by 1.0
warning: there was one deprecation warning (since 2.12.6); for details, enable `:setting -deprecation' or `:replay -deprecation'
res2: scala.collection.immutable.NumericRange[Double] = NumericRange 0.0 to 10.0
  • Also, you introduce the 'to' method here without explaining it, it was 'until' until now. 'to' is finally introduced later on in 9.3.4.

9.4

  • The solution at the bottom has a broken image reference.

Complete installation instructions

Add detailed installation instructions for both pathways (IntelliJ and Atom) and all platforms. Consider taking screenshots. Look at the ScalaBridge screenshots for example. Consider creating installation screencasts.

  • Atom / Command line

    • Linux
    • OS X
    • Windows
  • IntelliJ

    • Linux
    • OS X
    • Windows

Chapter 9.8; Fig 9.12: Wrong order of method arguments for Image.star

In the PDF on page 105 in Chapter 9.8 the following code snipped is supposed to generate the stars shown in Fig. 9.12:

val star = Image
    .star(100, 50, 5, 0.degrees)
   [...]

however the order in which the arguments are given seems to be wrong when looking at the source code: https://github.com/creativescala/doodle/blob/79e41e13637592519cf809b0e2b34c5f4958b418/image/shared/src/main/scala/doodle/image/Image.scala#L203

I fixed it thus using the following order to create something like shown in the Fig. 9.12:

val star = Image
    .star(5, 100, 50, 0.degrees)
   [...]

Exercise 4.3.5 Scope: questionable "circular dependency"

https://github.com/underscoreio/creative-scala/blob/develop/src/pages/programs/names.md#exercises--

original

object One {
  val a = b - 1
  val b = a + 1

  val answer = a + b
}

Trick question! This code doesn't work. Here a and b are defined in terms of each other which leads to a circular dependency that can't be resolved.

problem

I think the reason because this code doesn't work is actually two folds.

  1. Circular declaration itself is not forbidden with Scala. It just requires a type annotation on b as val b: Int = a + 1.
  2. The reason it doesn't "work", as in it will actually return incorrect value is because val a = b - 1 is referencing b before it is initialized, which seems to be treated as 0. Making answer into (0 - 1) + (0 - 1 + 1), which is -1.
scala> object One {
     |   val a = b - 1
     |   val b: Int = a + 1
     |
     |   val answer = a + b
     | }
<console>:12: warning: Reference to uninitialized value b
         val a = b - 1
                 ^
defined object One

scala> One.answer
res1: Int = -1

expectation

If we want to expose the readers to val initialization order issue, it might be worth changing the exercise to:

object One {
  val a = b - 1
  val b = 10

  val answer = a + b
}

and note that fact that without -Xfatal-warnings one could end up with incorrect answer?

Recommend AdoptOpenJDK OpenJDK 8 + HotSpot

Given the complicated license and update situation (https://www.aspera.com/en/blog/oracle-will-charge-for-java-starting-in-2019/, https://www.oracle.com/technetwork/java/java-se-support-roadmap.html) and ever changing JDKs and Scala's varying degree of support for it, I think Creative Scala should instruct new users explicitly to use Java 8. If someone has an Oracle JDK already that's ok, but for new installs I recommend AdoptOpenJDK OpenJDK 8 + HotSpot.

It's a binary distribution created from OpenJDK project source. Hopefully it should provide patches long after January, 2019.

Recursion examples do not handle negative number input

For example, calling chessboard(-1) will lead to endless recursion and eventually stack overflow.

def chessboard(count: Int): Image = {
  val blackSquare = Image.rectangle(30, 30) fillColor Color.black
  val redSquare   = Image.rectangle(30, 30) fillColor Color.red
  val base = (redSquare beside blackSquare) above (blackSquare beside redSquare)
  count match {
    case 0 => base
    case n =>
      val unit = chessboard(n-1)
      (unit beside unit) above (unit beside unit)
  }
}

The solution could be just adding additional case on top:

case n if n<0 => Image.Empty

However, Dave suggested to turn it into a learning opportunity by adding:

  • Exercise: What would happen if we called chessboard() with a negative number? Why? How could we prevent this happening?
  • Solution: Explain that we fail to terminate. Explain underflow. Show your code using a guard clause to protect against this.

I like his approach better.

Project: Twitter Bot

A larger project to tie together concepts would be good. Perhaps a Twitter bot that tweets generative artworks?

Missing xmlns value breaks inline SVG images

The SVG image rendering is broken in the web version because the base64-encoded inline images don't contain the xmlns value.

This can be fixed manually, but the real problem is in the doodle library. I've opened a PR to fix it there so the images are generated correctly in future, as well as one fixing the existing SVGs here.

This fix should also fix #72.

Using coursier for faster artefact resolution

I was wondering if you think that using cousier for faster artefact resolution could be helpful, I have tested a branch and it is working. Since the docker is usually a cold resolution cache, this can help a lot (pity it does not work for the sbt and plugin artefacts)

Happy to create a PR from that branch (it is a one-liner anyway)

Thanks for all the hard work!

NullPointerException on running Example.image.draw

On a fresh clone of the project, the log looks like this:

scala> Example.image.draw
java.lang.NullPointerException
  at java.util.concurrent.ConcurrentLinkedQueue.checkNotNull(ConcurrentLinkedQueue.java:920)
  at java.util.concurrent.ConcurrentLinkedQueue.offer(ConcurrentLinkedQueue.java:327)
  at java.util.concurrent.ConcurrentLinkedQueue.add(ConcurrentLinkedQueue.java:297)
  at doodle.jvm.Java2DFrame.interpret(Java2DFrame.scala:19)
  at doodle.jvm.Java2DFrame.interpret(Java2DFrame.scala:8)
  at doodle.syntax.ImageSyntax$ToImageOps.draw(ImageSyntax.scala:9)
  ... 39 elided

P.S.: happens only through sbt console. On IntelliJ Idea the error is not reproduced.

Clarify what is meant by `allOn` method in Chapter eleven.

A reference to an allOn method is made in three places in chapter eleven. This method does not seem to exist, in the current version. The following is an example of where it is mentioned.

This is the equivalent of the allOn method we’ve developed previously,

One solution would be to create or restore an exercise, to create such a method.

Clarify motivation for pure vs impure

Impure code depends on all the prior code --> clarify we mean the meaning of impure code, as it depends on state, and the state depends on all prior code that has run.

Basic Axis Support

The goal here is to add the easy bits of creating axes. Anything that feels like large enough that it isn't easy should be a separate ticket.

  • An axis can be horizontal or vertical.
  • A horizontal axis can be positioned on the top or the bottom (default is bottom)
  • A vertical axis can be positioned on the left or the right (default is left)
  • An axis has a title

A few notes:

  • Not worrying about tick marks, because they big enough for their own issue
  • Layout constraints (e.g. adding padding) should be part of the plot, not the axis

Proof-reading All Chapters

All chapters need proof-reading. Any errors found should be fixed. Proof reading only needs to focus on grammatical errors, typos, and the like. The structure of the book doesn't need to be reviewed.

  • Chapter 1
  • Chapter 2
  • Chapter 3
  • Chapter 4
  • Chapter 5
  • Chapter 6
  • Chapter 7
  • Chapter 8
  • Chapter 9
  • Chapter 10

IntelliJ getting-started instructions are poor

there are a lot of missing or glossed-over steps and choices to make.

I've used IntelliJ and Scala before, but regardless, I found these instructions difficult to follow and I felt very uncertain whether I was doing it right.

I'm skeptical that a new user could follow these instructions without a lot of guesswork and/or outside assistance

Error in import code at start of chapter 3

There's a box at the start of chapter 3 saying:

If you run the examples from the SBT console within Doodle they will just work. If not, you will need to start your code with the following imports to make Doodle available.

mdoc scala import doodle.core._ import doodle.core.Image._ import doodle.syntax._ import doodle.jvm.Java2DFrame._ import doodle.backend.StandardInterpreter._

That mdoc scala at the beginning shouldn't be there.

Reorder installation chapter to put instructions first

Most students are keen to get started and are skipping over the background. Put the instructions---the important stuff---first and then follow with background.

Also clean up the instructions to some extent, and don't suggest forking from Github unless they're taking the course with an instructor.

Could Not Find Implicit Error when Starting Project

Following the instructions the first step run from the sbt console is

Example.image.draw

However with the latest version this triggers the following error:

<console>:27: error: could not find implicit value for parameter renderer: doodle.effect.DefaultRenderer[[x[_]]doodle.language.Basic[x],Nothing,Nothing,Nothing] Example.image.draw

However, using parens when calling draw properly resolves the implicit and draws the doodle

Example.image.draw()

Update to Doodle 0.8.0

Doodle 0.8.0 has been released, and it breaks a few things. Update the book accordingly.

Missing image rendering in EPUB format

Hi there! I'm trying to teach my sister Scala with this book and I've realized that the epub book version doesn't render images. I attach a screenshot of page 67, at the beginning of the section of "Computing with Pictures", to illustrate what I mean:

Screen Shot 2020-03-25 at 11 39 55

I'm using macOS Catalina 10.15, I'm on the latest version. My sister has tried on her iPad and it doesn't work there either, so this might be a general platform on the iOS and OSX platforms. For now, I've referred my sister to the PDF version, so this is not a blocker but my sister had a preference for the EPUB format.

Update Sequences Chapter

  • tutify the code.
  • Update to new APIs as required.
  • Update images from screenshots

Content is not a concern at this point.

Chapter 11.1: Left over TODOs for render animations

The following TODO was left at two places in the text (page 134 in the PDF):

This generates the anima on shown in TODO: render animation

Could a temporary fix, until the new build for the book is finished, simply be a QR code as a pointer?

Project: Flame Fractals

Flame fractals are simple to implement and look impressive. Consider adding them as a project. This will require changes to Doodle to support bitmap images.

Edit Generative Chapter

Go through "Generative" chapter and fix typos, edit as necessary, etc. In practice I've found students struggled with Applicative, so consider replacing with further discussion of Monad.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.