Indent & case
Verbs that change the shape, not the words: >> and << shift, = tidies by the braces, and gU gu g~ change case with any noun.
Wednesday, 8:55 a.m. Somebody switched the Formatter back on yesterday, "just for one file". It ran at 3 a.m. over every file, and it had opinions. Half of kitchen.ts lost its indentation, and a few names are now in CAPITAL LETTERS, as if the file were shouting at you.
The letters are all still there; they're just the wrong shape. In code, shape still matters: ENQUEUE and enqueue are different names, and only one of them is called anywhere.
Warm-up from earlier chapters
Two from earlier chapters, from memory, before the new idea. Two wrong tries show the answer.
Verbs that change the shape
Some verbs change how text looks, not what it says. > shifts lines one indent to the right and < shifts them left. Say them twice for the line you're on: >> indents it, << takes an indent off. With a count, 3>> shifts three lines.
export class Kitchen {private busy = false;}export class Kitchen { private busy = false;}Shift it back
Each marked line has one indent too few or too many. >> or << from anywhere on it.
This exercise needs a keyboard. Read on, and play it at your computer.
= tidies up
= is the verb tidy: it re-indents lines to match the code's structure, so you don't have to count indents. == fixes the line you're on, and 3== three lines from here. Inside a function, a flattened line goes back in one level per brace.
Shift or tidy?
The Formatter flattened this whole function. From the if, you press 4>>. Is it fixed?
Tidy the function
Same function, still flat. One sentence with = from the if: every line goes to the depth its braces ask for.
The first exercise of every lesson is free. Pro unlocks the rest, every track, for good.
See ProThis exercise needs a keyboard. Read on, and play it at your computer.
Case is a verb too
gU is uppercase, gu is lowercase and g~ flips the case. They take any noun: gUiw shouts the word under the cursor, guiw calms it down. ~ on its own flips just the character under the cursor and moves on, so ~~~ walks along flipping.
ENQUEUE(order: Order) { enqueue(order: Order) {Which part changes?
The cursor is on the q of max_qty. You press gUiw. What does the line say?
Stop shouting
Some names were shouted, some constants whispered. guiw or gUiw from anywhere in the word.
The first exercise of every lesson is free. Pro unlocks the rest, every track, for good.
See ProThis exercise needs a keyboard. Read on, and play it at your computer.
Shape verbs
From memory.
Formatter cleanup II
Lost indents and shouted names across the codebase. The letters are right; their case and indent are wrong. Shape verbs only.
The first exercise of every lesson is free. Pro unlocks the rest, every track, for good.
See ProThis exercise needs a keyboard. Read on, and play it at your computer.
Calm the class
The top of kitchen.ts. max_rush is a constant and should be in capitals; the two fields go back in one level, where class members belong; and ENQUEUE should be the method name the rest of the code calls, enqueue. Then open the Formatter's own config and stop this happening again: indent by 2, and no more shouting (shout: false).
Stuck? Show a hint
The first exercise of every lesson is free. Pro unlocks the rest, every track, for good.
See ProThis exercise needs a keyboard. Read on, and play it at your computer.
Extra practice optional
The chapter is done. These rounds keep going as long as you like: stop whenever it stops being useful.
Formatter aftershocks
Endless indents and case to put right.
The first exercise of every lesson is free. Pro unlocks the rest, every track, for good.
See ProThis exercise needs a keyboard. Read on, and play it at your computer.