lunduniversity / introprog

Teaching material for "Introduction to Programming using Scala" at Lund University, LTH. http://cs.lth.se/pgk/
142 stars 171 forks source link

[w05] confusion over not being able to access class methods through class name #678

Closed snctfd closed 1 year ago

snctfd commented 1 year ago

I've noticed that students tend to make one common mistake in the exercises for w05; after implementing the Pos class, students tend to be "primed" to use the Pos.moved function when working on the implementation for KeyControl.direction, despite the fact that this function returns (Int, Int). As a result, it's common for students to make the mistake of attempting to return e.g. Pos.moved(-1, 0) for the "left" case, likely because they don't actually have an instance of Pos to call moved on. This, of course, doesn't work. In previous years, I've also seen equivalent mistakes show up even later in the course.

What I would recommend to fix this is to add a small part in 6a) that encourages the student to try writing Pos.moved(1,2) in the REPL, and to reflect over why it doesn't work.

snctfd commented 1 year ago

willing to provide PR if my suggested change seems good :)

Sabewey commented 1 year ago

I have also seen several students trying to use Pos.moved(...) method to implement the KeyControl.direction. I would agree that perhaps a small exercise encouraging the students to try and make a method call to Pos.moved() without an instance of the class could help them question why this doesn't work and subsequently have a better understanding on how to approach the following question: KeyControl.direction.

However, this might prompt the students to create a Pos instance in the KeyControl class instead...

bjornregnell commented 1 year ago

Great! I agree that there is need for exercises that highlight how to use immutable and mutable structures here and the difference between the companion object and a class instance. Good if you can come up with a small but efficient exercise sub-task that tries to maximize understanding, but does not deplete too much of the student's energy to take on yet another exercise... PR Welcome! @snctfd

snctfd commented 1 year ago

PR created, feedback welcome! ^

bjornregnell commented 1 year ago

merged! thnx!