Rename a concept
Launch week, Monday: orders become tickets in the kitchen module. * and cgn where you choose each one (and pass by the one that must stay), a ranged :s inside one function, :%s with \<\> for whole words.
Monday of launch week, 9:10 a.m. Burrito 2.0 calls orders tickets, in the code at least: the kitchen module has to follow before Saturday's launch. The customer-facing text still says "order", so a blind rename is out.
Six jobs this week, one a day. Today's is a rename done properly.
Warm-up from earlier chapters
Two from earlier chapters, from memory, before the new idea. Two wrong tries show the answer.
order with ticket in the file.order with ticket in the file.Which tool for which rename
Pick by how many places and how picky: * on the name, then cgn once and . for each next match, when you want to see every one as it changes. A ranged slip, :.,+4s/\<total\>/amount/g, when the rename stays inside one function. :%s/\<Order\>/Ticket/g when the whole word goes everywhere. \< and \> keep it to whole words.
None of these knows what the code means: they match text. A string or a comment with the same name matches too, so before the first key, find what must stay.
export function orderTotal(order: Order) { return orderTotal(order.items) + "order";export function ticketTotal(order: Order) { return ticketTotal(order.items) + "order";Whole words, in quotes
The dashboard charts the metric by its name, "orderTotal", so it must stay. You send :%s/\<orderTotal\>/ticketTotal/g. What does the second line say now?
Stage 1 · The function name
9:15. orderTotal becomes ticketTotal in its three code places; the metric name in metrics.track("orderTotal", …) stays. The cursor is on the definition: * finds the next one, N comes back, cgn changes this one (type ticketTotal), and . changes the next: after cgn, the stamp finds the next match by itself. When the next match is the one that stays, n onto it, n past it, then ..
This exercise needs a keyboard. Read on, and play it at your computer.
Stage 2 · One function only
9:30. Inside printOrder only, the local total becomes amount; the other functions keep theirs. The function is this line and the four below it.
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.
Stage 3 · The type
9:40. The Order type becomes Ticket everywhere in the file. The function names printOrder and refundOrder stay for now, and so does the customer's "Your order: ".
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.
Rename tools, from memory
Press the keys.