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

Day 320 of 365 · Expert · Month 11: Optimisation and debugging

Staying maintainable

Staying maintainable: collect settings at the top, clear names instead of a, b, c and record changes so that you still know in half a year what is running.

Lesson 18 min Week 46

What you learn today

  • Settings at the top
  • Clear names
  • Document changes

A script that works has been running in the cold store for weeks. Now the switch-off limit should move from 2 to 4 °C. You open the chip and find sge c a 275.15. Which register was the temperature again? Is 275.15 the limit or a conversion value? Maintainable code answers these questions before you ask them.

Settings at the top

Everything a person might ever want to adjust sits as a define at the very top, with unit and meaning in the comment. Limits, times, bands, fault values. The body does not contain a single number anyone might want to change. Whoever changes the limit changes one line and does not need to understand the rest.

Clear names

alias a r0 saves four characters and costs thinking every single time. alias tStore r0 says what is in it. The same goes for devices: a device is called “Kuehllager”, not “Sensor3”. If everything that belongs to the cold store has that name, you find it in the game and in the code straight away.

Documenting changes

A short header is enough: what the script does, which version, who. Add a define VERSION that the chip writes onto the housing at start. Then you can see at a glance in the game which revision is running.

# --- Cold store ---
# Version 2, Dominik1199
# v2: off limit 4 C instead of 2 C (vegetables froze)
define VERSION 2 # revision of this script
define EIN 281.15 # 8 C, cool above
define AUS 277.15 # 4 C, stop below

The chip is the wrong place for the list of all changes – every comment line costs characters from the 4096. Only note the latest change and its reason in the script. The old revisions live in your library.

Warning

Tidying up means: behaviour unchanged. After renaming and rearranging, run the same test cases as before. A mistyped alias name shows up immediately, a swapped limit does not.

Diagram

Program layout in the proven style # --- Heat warning --- define LIMIT 303.15 # 30 C define SENSOR HASH("…") alias temp r0 alias hot r1 start: yield … j start 1 · define everything tunable 2 · alias names for registers 3 · main loop with yield, endless
Settings block on top, devices and registers below, then the loop in numbered sections. Anyone who only wants to change a value only has to look at the top.

Exercise

Task

The script in the starter code cools the cold store correctly but is unmaintainable. Tidy it up: all numbers and hashes as defines with a comment (no raw number left in the body), meaningful alias names, sections. Add define VERSION 2 and write the version onto the housing at start with s db Setting. The behaviour stays exactly the same.

Hints

Hint 1

The three raw hashes are gas sensor, wall cooler and LED display – write them as HASH("Structure…") in defines.

Hint 2

281.15, 277.15, 273.15 and -999 also get a define.

Hint 3

s db Setting VERSION belongs before the loop label.

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