top | item 38747043

(no title)

BariumBlue | 2 years ago

Good point actually - when teaching absolute newbs, I found they'd often confuse the point of a while with a for with an if block.

GOTO is super unambiguous and probably a better introduction to program control flow while they get used to manipulating and juggling variables around

discuss

order

tialaramex|2 years ago

I would suggest that Rust's only actual loop, (using the keyword loop) is unambiguous while also being structured. You can (and during development I sometimes do) just write loop until it's apparent what you actually meant and then rewrite - also the Clippy linter will point out various obvious idioms e.g. for or while let loops if they are written as legal but unidiomatic loop constructs. So that aids pedagogy. Your loop works, but the linter explains how an experienced programmer would express the same loop more clearly.

Computed GOTO is often possible in BASICs. In one sense that's awesome, this is a very powerful technique, but in practice it's so unstructured that you shouldn't ever use it so why even offer it?

"That's how the machine works". Yes it is, which is why we don't write raw machine code when we can.

ddingus|2 years ago

I think it should be used when one needs a fast, deterministic field of branches.

When I used them, I would use boolean in the math to insure the input value was bounded properly.

X = (Y > 5) and Y (for systems setting true to -1 all bits set)

X = Y * (Y > 5) (for systems setting true to just the value 1)

Basically an in-line compare where the actual numeric value result of the comparison is used in a math expression rather than as an input to an if-then construct.

And these two ideas map directly to assembly language, which given the speed of the machines back in the day, made sense. People were going to be using assembly sooner or later.