SWEA 2025 Weekplan 4

The learning goals for Week 38 are:

Mon: Clean Code. Maintainability and Flexibility. (Screencasted only / No physical lectures). Wed: State Pattern. Mandatory hints.

Literature:

Slides:

Notes for this weekplan:

Monday lectures are cancelled as physical lectures, and replaced by screencasts (8 about clean code and a single about maintainability).

The Wednesday lecture will cover the State Pattern and next provide hints and advice for the mandatory project. Iff you cannot wait to start working on mandatory Iteration 3: Strategy Pattern and Refactoring, I have made a screencast of the W4-4 Hints as well that I strongly advice to checkout before coding a lot that needs to be refactored later!

The topic of Clean Code is a main topic of this week, but will purely be based upon screencasts. The theory and practices will be exemplified through my refactoring/cleaning up of the HotStone 'attackCard(...)' method. You may study the StandardGame.java yourself before watching the screencasts. The reason for not doing the clean code lectures live is that A) it is a complex code base so refactoring it live easily goes wrong and B) it allows you to skip repetitious tasks like session 'doing more bail out fast'.

The Clean Code presentations consist of

  1. Session 0 / Clean Code slides (52min) (same as the 'W4-1' screencast above)
  2. ... on to the actual live coding, presented in the following sessions:
  3. Session 1 / Do not repeat yourself (11.40)
  4. Session 2 / Bail out fast (6.30)
  5. Session 3 / Bail out fast (6.30)
  6. Session 4 / Do one thing (6.30)
  7. Session 5 / One level of abstraction (9.30)
  8. Session 6 / One level of abstraction (5.50)

Links to the Clean Code Classification Template

  1. Clean Code template (excel)
  2. Clean Code template (pdf)

Kata

Spend the first 15-20 minutes of the TØ/Lab class in plenum discussing...

AlphaStone and BetaStone vary with respect to determining who wins the game: In Alpha, Findus always wins after eight turns, while in Beta, the winner is the one whose opponent hero's health reaches zero or less. As a Strategy pattern dictates that the winner algorithm is in another object distinct from the Game object there obviously must be passed information back and forth between the Game and the Strategy.

Discuss benefits and liabilities of choosing each of these viable ways of passing parameters from Game to the Strategy algorithm:

  1. passing: turnCount, findus health, peddersen health (all integers)
  2. passing: game object (type: interface Game)
  3. passing: game object (type: class StandardGame/GameImpl)
  4. passing: a Record type containing a copy of all game state (turn count, player in turn, heroes' data (mana, health, power used), fields' contents (all cards and their values), etc.)

One of these options will be the lesser choice if case we invent future strategies for determining the winner based on other criterias. Which one?

Optional Exercises:

These are optional exercises. Be sure to solve the mandatory project first, and only if you have a lot of spare time, try having a look at the exercises below.

Find Dirty Code

Find some code from previous courses or projects, and analyze them according to the Uncle Bob+Henrik principles. If in the mood - clean them up.

Exam Rehearsal

Rehearse a clean code exam situation. Spend 20-25 minutes to prepare a 10 minute oral presentation of an exercise in the example exam question set: demo-question-final-2023.pdf.

Next, do a 10 minute presentation at the whiteboard in front of your team.

The team provides constructive feedback on the presentation: Is your presentation clear and understandable, do you discuss the concepts and terms correctly, is you Java example code correct, etc. Swap and ensure all in the team gets a chance to rehearse the situation.