Experiment: Duby

OK, local variables, neat trick…but maybe you’re wondering, “What’s the point?” Legitimate question, but it’s kind of hard to see the point without considering what it would be like without local variables. It’s like if you’d never seen a seatbelt, and I’m here telling you all about the different tension mechanisms, how it connects to the car, and the different kinds of latches, and you’re all, “And the point is…?” Well, imagine a world without seatbelts. You get in a wreck. You fly out the window. You die.

The negative consequences of programming without local variables are certainly not as dramatic, but neither are they as easily explained. To get a feel for life without locals, let’s imagine a fake language called Duby ...

Get Learn to Program, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.