Flotsam and Jetsam #104

  • Stefan chastises me for making another one of my pronouncements on “evil” programming techniques.  I admit to a bit of hyperbole, but it’s not without a point.  The argument against my pronouncements is that the wise and judicious use of these so-called “evil” features or techniques is good.  I don’t agree.  I think that if a “feature” has the ability to be *easily* abused, then it should be avoided.  For instance, some make the argument that there places where the with statement makes sense.  Well, my counter argument to that is if you allow the with statement in a few places, it’s very easy to use it in just a few more places, and then the next thing you know, your code is full of with statements.  It’s a slippery slope that you should never start down.  The same is true for nested procedures.  Sure, there might be places where they “make sense”, but if you allow them in one place, what is to stop a junior programmer from getting the wrong idea and go crazy with them?  This is especially true for features that simply need not be used at all – such as with and nested procedures.  You can write beautiful code without them, so why risk sliding down the slope?  Better to ban their use altogether.  (Cue the “Then why don’t we all just use assembler” comments in 3..2…1….)
  • I’m a big user and proponent of the Spring for Delphi framework. If you are, too, then you might consider donating to the project.  The website now has a PayPal donate button.
  • I recommend that you give a very careful read to Marco’s post about what was going on at the Microsoft BUILD conference last week.  Lots of interesting stuff there for us Delphi developers, both in the Windows and cross-platform realms.
  • Torry.net is for sale.  Hat tip to Olaf Hess in the non-tech group for this piece of information.
  • Wouter van Nifterick

    Nested functions are very useful to keep the rest of your code clean.

    Instead of polluting the global space with a giant mess of countless tiny useless classes, you can contain all stuff within a single routine, right next to the place where you need it.

    You can do handy stuff like having a ValidateArguments() nested procedure, and you don’t have to pass the arguments of the outer routine. If you need temporary variables to do these checks, you can create them right next to where you use them.

    Where other languages allow variables to be declared in the body of routines, Delphi has this pretty elegant solution.

    Yes, you can abuse or overdo this, but it’s like alcohol. It’s can be awesome when it’s used responsibly, but it can do damage if you’re that dumb guy who doesn’t know when to stop.

    By removing nested routines, you’ll throw out the baby with the bath water.

  • David Heffernan

    Every single feature can be abused. Your argument is thus utterly without merit.

  • Frank Lauter

    I think “with” is very useful if you use ist the right way.

    Eg: I have many autogenerated Interfaces to create XML files. This files have nodenames like:

    Fachdaten.Eintragungsanordnung.Anordnungsbehoerde_Eintragungsgrund.Anordnung_Gerichtsvollzieher_Vollstreckungsbehoerde.Gerichtsvollzieher.Amtsgericht.Wl_fassung := 1.0;
    Fachdaten.Eintragungsanordnung.Anordnungsbehoerde_Eintragungsgrund.Anordnung_Gerichtsvollzieher_Vollstreckungsbehoerde.Gerichtsvollzieher.Amtsgericht.Wl_version := 1;
    Fachdaten.Eintragungsanordnung.Anordnungsbehoerde_Eintragungsgrund.Anordnung_Gerichtsvollzieher_Vollstreckungsbehoerde.Gerichtsvollzieher.Amtsgericht.Content := ‘AG Bonn’;

    I don’t want this in my code… So I use With, but only from the final nodename -1 step!


    • Bruce McGee

      @Frank: I would use an explaining variable. Short and clean and more maintainable, imho.

    • Frank Lauter

      Using a Variable is one of the common replacements of the With, but this is only a small snipit out of 200 nodes. If I use a variable for all of this I’m unable to maintain this… The definition changes from time to time so using the original nodename is the only thing I can do…

  • Bruce McGee

    @Nick: I’m not wild about absolutes, but with with, I’m with you.

    If someone writes a fully functional refactoring tool that removes with statements from code, they should call it “without”.

  • Stefan Glienke

    The quote on the left side just made me laugh: “They condemn what they do not understand.”

  • Gerry Coll

    With comes from Pascal, not COM – it was always part of the language, used with records. The “mistake” Delphi made was to allow it for objects. It may be fine if not abused, but I have to deal with a leagcy codebase with multiple nested ifs that sometimes override each other (of the same class)