What you learn today
- Short names, short comments
- Game version
- Keep it readable
The greenhouse script from week 37 has grown: a header comment with all device names, settings, failures and a version history. All useful – and together over 4096 characters. The chip no longer accepts it.
Short names, short comments
Most characters are not in the code but in names and comments. Three levers, sorted by effect:
| Lever | saves | costs |
|---|---|---|
| moving long header comments out | a lot | nothing if the docs live elsewhere |
| deleting comments behind obvious instructions | much | almost nothing |
shortening names (temperature → temp) | medium | readability, if overdone |
A comment like # switch heater on behind sbn HEATER … On 1 says nothing the code does not already say. A comment like # 20 C, heater on below behind a define, on the other hand, does – that one stays.
The game version
The IC10 coder on this site has a Game version button: it removes all comments and blank lines, adjusts jumps to line numbers and opens the result as a new file. Your detailed version stays unchanged.
That way you get both: the file with all explanations stays with you or in the library, the short version goes into the chip.
The game version also lacks the comments that would help you when changing things in the game. Whoever wants to adjust something there later has to recognise the settings – that is why meaningful define names like HEAT_ON matter more than any comment.
Keeping it readable
Shortening has a limit. HEAT_ON does not become H1, ripe does not become r. The rule: a name must stay understandable in the code without a comment. What gets shortened first is what is duplicated – explanations that are already in the name.
Put the long documentation where there is room: in the script's description in the library, in a file next to the code or as a one-line summary at the top of the chip.
A good short header fits into one line: name, version and where the rest lives. Everything else can stay outside.
Diagram
Exercise
Task
The starter code is the greenhouse from week 37 with a long header comment – together over 4096 characters. Shorten the comments until the chip gets below the limit. The code itself stays unchanged and must keep passing all tests.
Hints
Hint 1
The code after the header comment is already done – the problem is only the comment lines at the top.
Hint 2
Replace the header comment with one line with name, version and a pointer to the docs.
Hint 3
The IC10 coder shows you the character count while you write.
Quiz
3 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