Fog Creek Software
Discussion Board




Evil Wizards

In The Pragmatic Programmer, (from Joel’s reading list), the authors discuss "Evil Wizards" and state  "Don’t Use Wizard Code You Don’t Understand."

They write:

"Wizards generate code that becomes an integral part of Joes application. The wizard code is not factored out behind a tidy interface – it is interwoven line by line with functionality that Joe writes. Eventually, it stops being the wizard’s code, and starts being Joe’s. And no one should produce code they don’t understand." 

Is this considered true of GUI code generated by Visual Studio? Is the GUI code generated by Visual Studio considered to be part of the programmers code, to be understood (and maintained) by the programmer, or is it a black box only to tinkered with through VS?

What about a complex, rich interface, like MS Outlook? Is it possible to develop the interface from the top down in VS? Is it advisable? Or do good developers resort to writing GUI code for anything more complex than a dialog box?

Any thoughts or comments on this would be appreciated.

Paul Mansour
Tuesday, April 22, 2003

I would definitely consider wizard code to be the responsibility of the developer to maintain it.

From my point of view, wizard code exists to automate a tedious manual task. It shouldn't be used to throw together code that works but you don't understand why.

Why not? Well, one day you might need to change the wizard-generated code slightly, and not have the faintest idea where to start. Or you might introduce a bug that generates a compile error somewhere in the wizard code that makes no sense. (This is a common pitfall for anyone starting out with ATL programming).

It's not like you can just take the source code, mail it to Microsoft and say "here, your wizard wrote this, you fix it".

And don't get me started on the VB6 Wizard Wizard - it generates of the worst bits of code I have seen.

Better than being unemployed...
Tuesday, April 22, 2003

On the other hand, some wizards don’t write code.

However, the debate here seems not about using wizards, but understanding code from the wizard.

Hum, I find it quite hard to believe that a wizard can write some code that a good developer can’t understand. If that is the problem, then we are in real big trouble.

If you are  a green thumb programmer, then understanding wizard code is going to be the least of your problems. Just about all code will not be understandable! Since this is the case, then I see little, or no problem in using wizard code. What is the difference between a big application full of code that you don’t understand. It makes little difference where the code came from?

What we are really  saying has nothing to do with wizards!

Basically what is being said is don’t use code you don’t understand. When you are starting out, that turns out to be just about everything.

I simply can’t imagine a serious developer team not being able to understand wizard code? Is this really a common problem?  Gosh, the developer team is totally stumped, and blown away by the junior programmer who used some wizard code!  Lets shut down the company and all go home. I can just hear the alarms going off like when a submarine does a emergency dive. All those alarms going aaaWoooKaa…..aaa WoookKaa. Dive Dive Dive.!

Gosh, we have some code that needs understanding?

Fact is, reading anyone’s code is a hard job, wizard, or not!

Lets hope we never hire a star developer who can write some complex code above the team average.

I think this whole issue is a red herring. It kind of makes sense, but in real practice, it is not a real big problem.


This is a issue of understanding code, and how one can eventually get that understanding.

Just changing a developer on the team is a far greater damage to this kind of “loss” of understanding of code. So, we can probably make a rule to not change developers in the middle of a software project. We all agree on this, but really the solution is to have good software designs, and good people on the team. If they start using a wizards, then so be it.

We simply have to deal with this.  Of course some will point out that often the developers can avoid using a wizard and write their own code. So what! Again, those developers are going to know the trade off in savming some time.  If the wizard code is horrible, well then of course we simply arguing against poor code, and again not against using wizards.

What about understanding of code written by other developers on the team?

The same rule applies.

Thus, the REAL RULE here is:

    No developer shall write code that no one else on the team can’t understand!


Albert D. Kallal
Edmonton, Alberta Canada
Kallal@msn.com

Albert D. Kallal
Tuesday, April 22, 2003

I think that what the pragmatic programmers were getting at is to not use wizards to write code that you don't understand. But not in the sense of badly written code, rather in the sense of the programmer not knowning how certain things are done. But, if you already know how certain programming tasks are done, using a wizard to automate the repetative parts of the code is all right.

My general approach when working on some new software technique where there are wizards available is:
1. Do it by hand a few times.
2. After you're comfortable with the procedures, use the wizard and look at the code it generates and make sure you understand it.
3. Then, in the future, use the wizard and don't bother looking at the code (until you have a problem...).

The prohibition is against skipping steps 1 and 2.

Bill Tomlinson
Tuesday, April 22, 2003

I can see that Wizards are great for repetative tasks, once you can understand the code generated.

But another big question is  whether GUI code fits in that definition. I believe that both wizards and RAD-type IDEs are helpful in developing better user interfaces. Do you agree?

Not my real name.
Tuesday, April 22, 2003

It seems that no one actually read my post -- perhaps the title was not perfectly chosen.  My question remains: 

Is the GUI code generated by Visual Studio considered to be part of the programmers code, to be understood (and maintained) by the programmer, or is it a black box only to be tinkered with through VS?

Paul Mansour
Tuesday, April 22, 2003

All code generated on your behalf must be understood by you.

Brad Wilson (dotnetguy.techieswithcats.com)
Tuesday, April 22, 2003

I think wizards are only needed because our programming languages are too primative to easily create a library to do the task. Hence, we automate the code generation instead.

Even so, wizards are used a lot when the same job could be done by a decent library that the programmer could code to (the majority of code wizards in microsoft's products fall into this category).

And the horse you rode in on
Tuesday, April 22, 2003

I finished reading this book last weekend, and my interpretation was similar to Bill's.

Prakash S
Tuesday, April 22, 2003

The code generated by Visual Studio is evil wizard code. The ASP.NET UI code is particularly ugly - I've mentioned this here before. Hack hack hack! I'm not a fan of any RAD tools.

Walter Rumsby
Wednesday, April 23, 2003

I don't think you need to understand VB .NET GUI code to the same extent as you need to understand Java GUI code to create a UI in Java (even with an IDE).  Keep in mind that before this version of Visual Basic, all that GUI code was hidden from you anyway.  Mostly what's in the "form-generated" section of code is the declaration and instantiation of the form and its controls and assignment of their default properties, which is all readily accessible through the IDE.

If you want to know how to dynamically generate controls while your app is running, the code in the form-generated section is good to learn from.

Kyralessa
Wednesday, April 23, 2003

Paul - yes and no. Yes, because who the heck else would you expect to maintain it, Microsoft? No, because you can't expect anyone to, for example, ensure that the generated code matches the company style guidelines (unless you use some tool to do so). Maybe you could be a bit more specific about the question you really want to ask?

Not the droid you are looking for
Thursday, April 24, 2003

The VB/ASP.NET code supposedly changes on the fly depending on the browser being used, except... it doesn't work properly. If you just wrote your HTML to specification all would be good and lovely.

Walter Rumsby
Thursday, April 24, 2003

Thanks all for your comments.

Paul Mansour
Monday, April 28, 2003

*  Recent Topics

*  Fog Creek Home