stationeers.de Mod workshop · Dominik1199
DE Sign in
  1. Home
  2. IC10 academy
  3. Day 178

Day 178 of 365 · Advanced · Month 6: Atmosphere and control

Code review

Reviewing other people's code like a pro: a fixed order, an issue list with line, consequence and suggestion – and improvements you can justify.

Lesson 20 min Week 26

What you learn today

  • Assess other people's code
  • Make a list of issues
  • Justify improvements

A fellow player sends you his script: “The lab heating is acting up, can you take a look?” Twelve lines, looks tidy. A good review still finds four bugs – because it follows a fixed list instead of gut feeling.

Assessing other people's code

Always go through in the same order:

CheckQuestion
1. Does it run permanently?endless loop, yield in every loop, no program end
2. Does it read correctly?fitting batch mode (Average for temperatures, Sum only for real sums)
3. Does it calculate correctly?comparisons in the right direction, units (kelvin, share instead of percent)
4. Does it fail safely?what happens on NaN, on a missing device?
5. Does it keep the limits?128 lines, 90 characters, 4096 characters
6. Is it readable?defines, aliases, sections, labels instead of line numbers

The first four points decide whether the plant works. The last two whether anyone still understands it in three weeks.

Making an issue list

Write down every finding with line, problem, consequence and suggestion:

LineProblemConsequenceSuggestion
9Sum for temperaturetwo sensors report 580 K, heater never onAverage
9no yield128 passes with the same valueyield after start:

That way the other person can follow every point instead of just hearing “it is wrong”.

Justifying improvements

“Do it differently” convinces nobody. “With Sum the chip adds up the temperatures as soon as a second sensor is built – hence Average” does. Every change needs a reason from the game: which situation, which damage.

lbn temp SENSOR HASH("Labor") Temperature Average   # not Sum
slt tmp temp OFF_AT    # heater: slt, not sgt
Warning

A wrong Sum only shows up when a second sensor with the same name is built. With one sensor Sum and Average are the same. So in a review never ask “does it run right now?” but “does it still run after the next rebuild?”.

Tip

Also check what is not in the code. A missing NaN guard shows up on no line – only in the question “what happens when the sensor is gone?”.

Exercise

Task

The starter code is the fellow player's script. It has four bugs: wrong batch mode, swapped hysteresis, missing yield and – depending on the bug – no safe reaction to a missing sensor. Find and fix them.

  • Heater “Labor” on below 18 °C, off from 22 °C (average of all sensors “Labor”)
  • Sensor gone: heater off

Hints

Hint 1

Two sensors with Sum give double – Average.

Hint 2

A heater switches on when it is colder: slt instead of sgt.

Hint 3

yield right after start:. With slt NaN switches the heater off by itself.

Quiz

4 questions. You pass from 60 % – the server does the grading.

Complete the day

  • Passed the simulator exercise
  • Passed the quiz with at least 60 %

Without an account progress is saved in this browser only.

Report a mistake in this lesson

Please sign in to report. Sign in

Esc
↑ ↓ selectEnter open/ opens search anywhere