다음을 통해 공유


Petzold and new IDEs

With the proximity of VS 2005 launch everybody is talking about IDEs. I know it's not a new discussion, IDE vs Editors, VS vs Notepad, Eclipse vs VIM ...

Charles Petzold has written a piece https://charlespetzold.com/etc/DoesVisualStudioRotTheMind.html that has been popular see https://it.slashdot.org/article.pl?sid=05/10/26/1935250&tid=156&tid=166&tid=8  and https://lambda-the-ultimate.org/node/view/1084. He talks about VS tools like Intellisense, form editors and other kind of code generators inside the IDE.

I think every programmer has the same feelings about VS, sometimes you love it, and some times you hate the editors.

If VS is generating code that is far from readable, we must know that, and try to separate VS generated code, from "our code", and partial classes are going to help too much here. But we need more support to differenciate both.

I like to use Static Analysis Tools like FxCop (now integrated with the IDE), you will see how IDEGeneratedCode does not the default Rules. I also use VIL or NDepend to look for common not recommended practices like, Methods longer than 100 lines, or classes with more than 50 fields, obviously the InitializeComponent method never satisfy  this simple rules.

The other big problem with this kind of IDE tools is the Bottom-Up design. I have felt comfortable with Intellisense until I tried (and got inlove ) with TDD, Why I have to write the same things twice? (the first in the test, and the second in the implementation). I need a smart IDE that could infere the method signatures and class interfaces from my test definitions, and I know I would be writing without Intellisense. But maybe another coding tools like CodeSnippets or AutoCode templates can help.

From the testing point of view, you should think "Who cares if  IDEGeneratedCode has unit tests while It Works?". However if you write real programs you know that "ItWorks" it's not enough, you will have to change your code, and Unit tests can help you a lot with that, but the code generated by the IDE does not include unit tests. But the new VS (only some versions) include a wizard to generate unit tests for your classes, and sincerely I have tried to use it and I think it does not help too much, just creating the unit test skeleton.

There is no simple advice about code generation and IDEs, when, where and how much should we use these tools?

Like everything is a matter of balance, try to figure the future changes in your code, how can you test the main interfaces of the generated code, and how hard is change it.

My best recommendation is taken from the old (but still great) book "The Pragmatic Programmer". https://www.pragmaticprogrammer.com/ppbook/extracts/wizards.html

Don't Use Wizard Code You Don't Understand

Comments

  • Anonymous
    November 05, 2005
    Effective use of abstraction in programming encourages us to just learn whatever lower layers are necessary to get the job done, and this is really just the same thing as "blindly" using wizard generated code.

    There are really two separate decisions, whether to use wizard-generated code, and whether to invest time to understand wizard-generated code.

    Deciding whether to use wizard-generated code is based on things like, does it meet the requirements, does it work correctly and pass testing, and whether your past experience leads you to trust a particular code generator.

    Deciding on whether to invest the time to understand wizard-generated code is based on things like, is there a problem in the code, does it not meet all the requirements, do I not trust it for some reason, do I just like to have a deeper understanding in a particular area?

    Mindlessly following a rule like "don't use wizard code you don't understand" short-circuits the above reasoning and wastes time and effort by forcing unnecessary analysis of generated code. The only benefit I could see to following this rule always is to give me a "warm fuzzy feeling" of confidence, but this doesn't really meet any engineering/business objectives. It is fine, however, for learning and hobby work.

    I think the best practice is to approach code wizards based on each individual situation, and not follow a hard-and-fast rule.
  • Anonymous
    November 05, 2005
    I prefer to re use this kind of abstractions in a binary, or at least, source distribution.

    The problem with wizards is that they are difficutl to automate, so difficult to reproduce, and usually to maintain.

    I think VS, and family of tools should improve the way they handle generated code




  • Anonymous
    November 05, 2005
    I should mention, that if you press Esc when IntelliSense comes up, it won't autocomplete for you and just go away. Although, it would be nice to have this option configurable, but you can make IntelliSense not autocomplete everything.