The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My badges

  • Twitter Updates

  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 1,879 other followers

Archive for the ‘With statement’ Category

The dreaded with… Debugging today, I found another gotcha (: – via: Lars Fosdal

Posted by jpluimers on 2014/08/12

In the With Statement series:

Lars Fosdal – Code Rants

The dreaded with…

Debugging today, I found another gotcha.

In this case, both Self and DisconnectedClient has a property named ClientIdentifier.

Note the difference for the mouse-over and the evaluation.

–jeroen

Read the rest of this entry »

Posted in Appmethod, Borland Pascal, Delphi, Delphi 1, Delphi 2, Delphi 2005, Delphi 2006, Delphi 2007, Delphi 2009, Delphi 2010, Delphi 3, Delphi 4, Delphi 5, Delphi 6, Delphi 7, Delphi 8, Delphi x64, Delphi XE, Delphi XE2, Delphi XE3, Delphi XE4, Delphi XE5, Delphi XE6, Delphi XE7, Development, Pascal, Software Development, Turbo Pascal, With statement | Leave a Comment »

Delphi `with` post and discussion revisited (via: wiert.me and LinkedIn)

Posted by jpluimers on 2014/06/11

A bit more than a year ago, I wrote about Delphi: you should avoid the with statement as it makes your code less future proof. That caused some nice comments on the blog, and some more on LinkedIn where Paul Foster mentioned it in a thread ‘Jeroen Pluimers makes a case against “with” statements.‘ Both interesting reads, especially the reasons that people use or avoid with, or keep its use in balance. There is one set of comments I want to emphasize: refactoring multiple with statements into a one function and a call per former with. Read the rest of this entry »

Posted in Borland Pascal, Delphi, Delphi 1, Delphi 2, Delphi 2005, Delphi 2006, Delphi 2007, Delphi 2009, Delphi 2010, Delphi 3, Delphi 4, Delphi 5, Delphi 6, Delphi 7, Delphi 8, Delphi XE, Delphi XE2, Delphi XE3, Delphi XE4, Development, Pascal, Software Development, Turbo Pascal, With statement | 19 Comments »

WITH IS EVIL! (via: Paul Foster – Google+)

Posted by jpluimers on 2014/03/13

Yet another example of somehow who got bitten hard by using the with statement (I decided to give with its own category on my blog).

This time it got shared by Paul Foster on G+ and comes down to this:

Even in unsuspiciously looking code, the wit statement can bite you, especially if you need to do refactoring and (because of that) introduce two names in the same scope.

Or in Paul‘s words:

Whilst upgrading the code to remove the Containers unit (its not supported on NextGen platforms, so I have to make things work with Generics.Collections instead, (bye bye D7 support for this code) and refactor a couple stupidities in my original design (they always creep in, don’t they) I ended up with two class members of the same name.  The with block then looked OK but I was in fact not access the member I thought I was. 

–jeroen

via: Paul Foster – Google+ – WITH IS EVIL! God damn it, I know it makes code easier to….

Posted in Borland Pascal, Delphi, Delphi 1, Delphi 2, Delphi 2005, Delphi 2006, Delphi 2007, Delphi 2009, Delphi 2010, Delphi 3, Delphi 4, Delphi 5, Delphi 6, Delphi 7, Delphi 8, Delphi x64, Delphi XE, Delphi XE2, Delphi XE3, Delphi XE4, Delphi XE5, Development, Pascal, Software Development, Turbo Pascal, With statement | 18 Comments »

Delphi: `with` dos and dont’s (more of the latter though).

Posted by jpluimers on 2014/02/18

About a year ago, I wrote about Delphi: you should avoid the with statement as it makes your code less future proof. Then I already tweeted I would follow up. Time to do it now (:

Besides my first post, these links inspired me most:

Posts about the with statement usually cause a stir: people either like or dislike it with passion.

Starting with some history and examples, this posts lists a few DOs and DON’Ts when using the with statement, shows advantages and drawbacks, and shows you tools to eliminate with statements. Read the rest of this entry »

Posted in Borland Pascal, Delphi, Delphi 1, Delphi 2005, Delphi 2006, Delphi 2007, Delphi 2009, Delphi 2010, Delphi 3, Delphi 4, Delphi 5, Delphi 6, Delphi 7, Delphi 8, Delphi x64, Delphi XE, Delphi XE2, Delphi XE3, Delphi XE4, Development, Pascal, Software Development, Turbo Pascal, With statement | 9 Comments »

Delphi: you should avoid the `with` statement as it makes your code less future proof

Posted by jpluimers on 2013/03/27

As I wrote before, I’m with the [WayBack] Delphi with haters camp, and this is why:

Using the [WayBackwith statement in Delphi makes your code less future proof.

Originally, the with statement in Pascal was argumented in part of allowing compiler optimisations:

PASCAL User Manual and Report – Kathleen Jensen, Niklaus Wirth – Google Books

The with clause effectively opens the scope containing field identifiers of the specified record variable, so that the field identifiers may occur as variable identifiers. (Thereby providing an opportunity for the compiler to optimize the qualified statement.)

Screenshots of this 1975 book are below the fold.

The Delphi (actually even before that Turbo Pascal compiler) has no measurable difference between with and non-with code.

The debugger however, still does not support with, and there are other drawbacks of which one is below.

The below code example is just one of many. I show it because I recently bumped into doing some long overdue code porting to Delphi XE3.

Since I’ve been bitten by using with a couple of times before, it didn’t take me long to find the cause.

Example code where FIConData is of type NOTIFYICONDATAW that used to compile fine:

    with FIconData do
    begin
      cbSize := SizeOf(FIconData);
      Wnd := Self.Handle;
      uID := $DEDB;
      uFlags := NIF_MESSAGE or NIF_ICON or NIF_TIP;
      hIcon := Application.Icon.Handle;
      uCallbackMessage := WM_CAS400NTIcon;
      StrCopy(szTip, PChar(Caption));
    end;

Well, as of Compiler Version 20, it doesn’t compile any more. Read the rest of this entry »

Posted in Borland Pascal, Conference Topics, Conferences, Delphi, Delphi 1, Delphi 2005, Delphi 2006, Delphi 2007, Delphi 2009, Delphi 2010, Delphi 3, Delphi 4, Delphi 5, Delphi 6, Delphi 7, Delphi XE, Delphi XE2, Delphi XE3, Development, Event, Pascal, Software Development, Turbo Pascal, With statement | 32 Comments »

 
%d bloggers like this: