. .


ST 4U 263: Undeclared Variables in VA Smalltalk

July 27, 2012 9:26:23.693

Today's Smalltalk 4 You looks at what happens in VA Smalltalk when you leave a variable (in this case, an instance variable) undefined. The scenario being sketched is a bit artificial; you couldn't package an application in the state being shown, and ENVY does warn you about the situation. Having said that, most developers cheerfully ignore warnings, so we'll have a look. If you have trouble viewing it here in the browser, you can also navigate directly to YouTube. To watch now, click on the image below:


If you have trouble viewing that directly, you can click here to download the video directly. If you need the video in a Windows Media format, then download that here.

You can also watch it on YouTube:

When you work on a number of classes at once, you can sometimes leave a variable undeclared - i.e., you have methods that use the variable, but you've deleted it from the class definition. When you do that, you'll get a warning in the Transcript - but if you miss/ignore that warning, very bad things can happen. Let's take a small example.

We've defined a class with one instance variable, and then created an instance and set that variable in a workspace:

Small class

Having created the instance in the workspace, it'll live until we leave VA or close the workspace. Now, let's delete the variable in the browser. Notice the warnings in the Transcript, but for now, we'll ignore them. Now try sending the accessing method for the variable that's been deleted:


What you see above is an inspector on a class - which one you get will vary, but it indicates that you are poking where you should not be poking. To demonstrate how dangerous that can be, let's use the setter and set the variable's value.

If you inspect the results of sending the getter, you'll get back the value you tried to set. However, things are now in an odd state. Depending on where you poked, VA will likely crash after you try to do something. In development, that's annoying. In production, it could mean some pretty hard to diagnose errors.

Need more help? There's a screencast for other topics like this which you may want to watch. Questions? Try the "Chat with James" Google gadget over in the sidebar.

Technorati Tags: , ,

[st4u263-iPhone.m4v ( Size: 4138705 )]

posted by James Robertson

 Share Tweet This