...And the debugging fun expands exponentially when the 'with' is nested.
Its one language feature I'd be happy to see go away.
I have been working on some "with" programmer's code and I just don't see
the attraction. I know retyping the same thing many times is a pain, but
with code insight it isn't half bad, and maintenance programmers could
actually read the code.
All I do when there is going to be a large block, say using a table in a
datamodule in a separate unit, is create a local variable with a short name
and assign it at the beginning of the procedure:
var
Table: TWhateverTable;
begin
Table := DataModuleName.TableInThatFarAwayDataModule;
Table.FieldByName('field').AsString := 'Yippee';
// more of the same
So very much more legible and comprehendable than
with DataModuleName.TableInThatFarAwayDataModule do
begin
// insert far too huge block of crap here so indenting is useless
end;
Maybe a compiler warning that cannot be disabled is warranted:
"Note: You are using "with". Maintenance programmers "with" torches and
clubs will hunt you down
Venting completed. (1% error - acceptable compilation)
-Johnnie
Brian
"Johnnie Norsworthy" <jln...@verizon.net> wrote in message
news:469546ce$1...@newsgroups.borland.com...
IMO, that's the biggest reason not to use "with".
I use "with" *very* sparingly and only when I'm doing something simple
like initializing a bunch of fields. I know this is controversial, but
I wish Delphi supported inline variable declarations or at the very
least a Chrome-like "with" statement.
--
Brian Moelk
Brain Endeavor LLC
bmo...@NObrainSPAMendeavorFOR.MEcom
Why don't you support an alias alternative?
Maybe like one of the following?
Report No: 38563 Status: Open (dup of 679)
with statement really should support aliases
http://qc.codegear.com/wc/qcmain.aspx?d=38563
QCWIN:Defect_No=38563
Report No: 803 Status: Reported
Proposal for another extension to 'with' statement
http://qc.codegear.com/wc/qcmain.aspx?d=803
QCWIN:Defect_No=803
Report No: 679 Status: Open (Opened a little over 5 years ago)
The infamous WITH resolution
http://qc.codegear.com/wc/qcmain.aspx?d=679
QCWIN:Defect_No=679
--JohnH
Report No: 6867 Status: Open
Extend 'with' statement to allow 'with <alias> := <expression> do'
http://qc.codegear.com/wc/qcmain.aspx?d=6867
QCWIN:Defect_No=6867
--JohnH
> Why oh why, must Delphi have a with statement?!
Because Pascal has one.
I guess, in the old TP days, someone at Borland found it would also be
nice to have multiple object with statements, to cut the writing even
more.
They should never have done that.
--
Rudy Velthuis [TeamB] http://rvelthuis.de
"I'd give my right arm to be ambidextrous." -- Brian Kernighan
The "with" gets even when it refers to multiple objects separated by commas!
With Abc, Xyz do
begin
Nightmare;
Nightmares;
end;
The "with" should be treated with the same honor of "goto".
Regards,
Sarah
> Its one language feature I'd be happy to see go away.
It would break old code, or course. I would love to see it deprecated
for a few versions before it disappeared.
--
Rudy Velthuis [TeamB] http://rvelthuis.de
"Devlin's First Law - Buyer beware: in the hands of a charlatan,
mathematics can be used to make a vacuous argument look
impressive.
Devlin's Second Law - So can PowerPoint." -- Keith Devlin
The best think to solve this problem is to create a tool for expanding with
blocks, when asked to do so. This would be much easier and convenient for
everyone.
It could be part of refactoring. Hmmm... would be a nice QC suggestion.
--
Rudy Velthuis [TeamB] http://rvelthuis.de
"If there is no God, who pops up the next Kleenex?"
-- Art Hoppe.
Turbo Pascal produced better code when using with statement. In those days,
when everything had to fit in a 360KB disk, 1KB less program space was
really big thing.
> It could be part of refactoring. Hmmm... would be a nice QC
> suggestion.
It already existed:
Report No: 30536 Status: Open
Add Remove With Statement Refactoring
http://qc.codegear.com/wc/qcmain.aspx?d=30536
--
Rudy Velthuis [TeamB] http://rvelthuis.de
"Mother-in-law = A woman who destroys her son-in-law's peace of
mind by giving him a piece of hers." -- Anonymous.
Works for me. What's the QC number?
Rick Carter
cart...@despammed.com
Chair, Delphi/Paradox SIG, Cincinnati PC Users Group
--- posted by geoForum on http://delphi.newswhat.com
>It already existed:
>
>Report No: 30536 Status: Open
>Add Remove With Statement Refactoring
>http://qc.codegear.com/wc/qcmain.aspx?d=30536
Thanks for finding that, Rudy. I've added my vote.
Hopefully others will do the same.
Break it; compiler switch it.
That is true, but they should still never have done it. If someone
really wanted to use multiple with objects, they could still nest them
manually. <g>
--
Rudy Velthuis [TeamB] http://rvelthuis.de
"I don't care to belong to a club that accepts people like me as
members." -- Groucho Marx
> Why oh why, must Delphi have a with statement?!
Preach it, brother!
> Maybe a compiler warning that cannot be disabled is warranted:
> "Note: You are using "with". Maintenance programmers "with" torches
> and clubs will hunt you down
Yes! Yes! Amen!
--
Nick Hodges
Delphi Product Manager - CodeGear
http://blogs.codegear.com/nickhodges
> The "with" should be treated with the same honor of "goto".
Indeed.
I'm going to take an apparently heretical position in this thread and
say that, on balance, I like "with." There. I've said it.
Can it be abused? Absolutely, and I've been bitten myself.
But frankly I'd miss being able to do this...
with System.Camera[i].ROI do
begin
Left := 0 ;
Right := 511 ;
Top := 10 ;
Bottom := 609 ;
end ;
Yeah, I know there are other ways of doing this, but I'd be sorry to see
it go.
Cheers,
Mark.
Ugh. I have worked on software that does this....
--
Robin.
Australian Bridal Accessories := http://www.bridalbuzz.com.au
Turbo for Noobs (a work in progress) := http://turbofornoobs.blogspot.com/
> Why oh why, must Delphi have a with statement?!
>
Evil! Evil I tells ya! If you use the with statement, you should take a
long hard look at yourself.
>
> > The "with" should be treated with the
> > same honor of "goto".
How many of us use the alias feature for
table names in SQL coding?
--JohnH
<Raises hand>
Not sure where you are going though...
Ditto. We seem to be in the minority. I agree with you 100%- it is
great if it used sparingly. The example you've used is the perfect
example where with is used correctly IMO. Too many people abuse it by
putting complex logic between the "begin" and "end" of the with block.
I agree with others here that there should be a compiler warning though
and it should be configurable. Companies can then set standards that
developers in their organization would have to adhere to because it will
be fairly obvious when they deviate from the standard.
Cheers,
Kevin.
> with System.Camera[i].ROI do
> begin
> Left := 0 ;
> Right := 511 ;
> Top := 10 ;
> Bottom := 609 ;
> end ;
AhhhhhhhHHHH!!!!
What if System.Camera[i].ROI changes its properties to
Left, Right, Height, and Width
for some reason? If that code were in a form, you'd never get a
compiler error, but you'd see some weird behavior that could take a
long time to figure out.
> Why oh why, must Delphi have a with statement?!
"With" would be OK if no statements other than property assignments (to the
argument object) were allowed inside the block. That also trivially exclused
nesting. That's really the only way I use it.
> > with System.Camera[i].ROI do
> > begin
> > Left := 0 ;
> > Right := 511 ;
> > Top := 10 ;
> > Bottom := 609 ;
> > end ;
>
> AhhhhhhhHHHH!!!!
>
> What if System.Camera[i].ROI changes its properties to
>
> Left, Right, Height, and Width
>
> for some reason? If that code were in a form, you'd never get a
> compiler error, but you'd see some weird behavior that could take a
> long time to figure out.
It's taking me a while to work out where the "Bottom" property is in a
form. I'm also wondering who would change the properties to those names
given what they were before. They're asking for trouble even before
"with" becomes an issue.
--
Dave Nottage [TeamB]
> The "with" should be treated with the same honor of "goto".
Goto can be useful for machine generated code, some looping situations and
as a way of using common exit or error handling. At least with a goto I can
look in the code and see the destination label.
But "with" is an invitation to the compiler to connect with anything
available. Like the C++ copy constructor.
Roger Lascelles
> I'm also wondering who would change the properties to those names
> given what they were before. They're asking for trouble even before
> "with" becomes an issue.
Right -- but you get the point.
> Why oh why, must Delphi have a with statement?!
Because it is handy in some situations.
Can it be easily abused? Sure. Does that mean the good coders should be
punished for bad coders abusing a feature? I think not. It is like
operator overloading. Easily abused, but very useful in some situations.
I would not mind if with statements with multiple arguments "with
SomeVariable, SomeOtherVariable do" would be abolished though. More
realistic I would love Delphi to throw a warning for those. One other
option for the with haters would be to add a "with statement considered
harmful" Delphi warning (switched off by default).
Jan Derk
Your main issue is actually here: for proper encapsulation, one
shouldn't use datamodule's components (this includes tables, queries...)
in *code* outside of said datamodule's events.
Also, use of TTable (and similar) is a far worse heresy in my book than
using "with" could ever be: abuse of "with" can mean that said code has
to be refactored, while abuse of TTable can mean the whole application
has to be reengineered.
Eric
Our blessing is given!... :-)
>> Maybe a compiler warning that cannot be disabled is warranted:
>> "Note: You are using "with". Maintenance programmers "with" torches
>> and clubs will hunt you down
>
> Yes! Yes! Amen!
>
Amen!
Also, (besides what others said about this), we must have an easy way to look at our
'with' code. Perhaps the tooltip window which appear can be expanded to have the full
description of the 'suspect'. For ex, having the following code:
with Form1, DataModule1.Table1 do
begin
Caption:='Processing data...';
if not Active then
Open;
DisableControls;
while not Eof do
begin
//arcane things here...
Next;
end;
EnableControls;
Caption:='This is one of my best code!';
end;
when the user hovers with the mouse over 'Active' now it writes
<quote>
Active property
----------------
Active - System.Boolean
</quote>
perhaps is better to show it up as:
<quote>
DataModule1.Table1.Active property <word wrap possibility here...>
----------------
Active - System.Boolean
</quote>
...and also something similar to show the corresponding pair of the begin/end keyword
on which user hovers with the mouse (with a tooltip - writing the 'begin' line if
Pos(AnsiUpperCase('begin'), Trim(AnsiUpperCase(cLine))<>1 and the first non-blank
line from above if the line starts with 'begin' ). Also, perhaps is good to highlight
the corresponding pair when the user is with the cursor in a 'begin/end' - something
similar with the engine from '['']' and '('')'.
Hth,
--
m. th.
Another solution is to limit the scope of the "with" to *record structures*
only as it was in old good Pascal.
> <quote>
>
> DataModule1.Table1.Active property <word wrap possibility here...>
> ----------------
> Active - System.Boolean
>
> </quote>
Seconded!. This is an excellent suggestion. (In any case. Regardless of your
opinions concerning "with".)
Good point...
When Wirth wrote Pascal he did not envisage anything like classes; the
language only had records.
So expanding the usage of "with" to encompass classes, and the properties
thereof, was not the fault of Wirth but of Borland...
AndrewFG
> So expanding the usage of "with" to encompass classes, and the
> properties thereof, was not the fault of Wirth but of Borland...
The same scoping problems would still happen. OTOH, scoping problems
are not confined to "with".
--
Dave Nottage [TeamB]
> Rudy Velthuis [TeamB] wrote:
> > It would break old code, or course. I would love to see it
> > deprecated for a few versions before it disappeared.
>
> Break it; compiler switch it.
I'm not sure there are enough letters in the alphabet left for yet
another compiler switch. <g>
--
Rudy Velthuis [TeamB] http://rvelthuis.de
"Show me a sane man and I will cure him for you."
-- Carl Gustav Jung (1875-1961)
> Rudy Velthuis [TeamB] wrote:
>
> > It already existed:
> >
> > Report No: 30536 Status: Open
> > Add Remove With Statement Refactoring
> > http://qc.codegear.com/wc/qcmain.aspx?d=30536
>
> Thanks for finding that, Rudy. I've added my vote.
> Hopefully others will do the same.
I hadn't added my vote yet, but I will do that now.
Hmmm... "Click bar to rate". What bar? I don't see one in Firefox. And
IE 6 only shows one possibility. Something must be wrong with the CSS.
So I voted using JED's QC client.
--
Rudy Velthuis [TeamB] http://rvelthuis.de
"The purpose of computing is not numbers but insight."
-- Richard Hamming
>> Another solution is to limit the scope of the "with" to *record
>> structures* only as it was in old good Pascal.
> So expanding the usage of "with" to encompass classes, and the properties
> thereof, was not the fault of Wirth but of Borland...
>
I'm another heretic who would miss this construct - for records and for
object references.
Yes it can cause problems, but used properly (and sparingly) it can make
the code much more readable (For those of us who do try to write "pretty"
code in the first place)
How could the construct be made "safer"?
1) IMO The VB method of always dotting the field/method/property makes the
construct much clearer
2) Since at least 2000, the StonyBrook compiler gave a warning of
ambiguous usage of a name within a WITH statement (that's "ambiguous" to a
human; the compiler was always certain which one it would take!)
3) And what about the implicit "self." references in the implementation of
each method?
--
Paul Scott
Information Management Systems
Macclesfield, UK.
I get it. But the problem you describe happens whenever you have nested
scopes, not just "with" statements.
In some sense we're always playing with fire.
Cheers,
Mark.
So please don't take "with" away (or make it bad), it simply needs some
fixing to make it safe since it was originally designed with Turbo Pascal
Records in minds, before the advent of objects, which ended up making "with"
unsafe, so it isn't "with"'s fault, it's objects that broke it :)
I still find "with" makes certain code that bit more readable when used
sparingly and wisely, as everything isn't prefixed with too many
sub-classes,
---
example: XObject.YObject.ZObject.Left := 10;
---
(It's difficult to see the "Left" in there (or another way, difficult to see
the tree in the forest :))
whereas:
---
with XObject.YObject.ZObject do
Left := 10;
---
(bit more readable and understandable to my eyes :)
Like someone else suggested, a fixed or enhanced "with" will be better,
something like (like suggested by someone else):
---
with XObject.YObject.ZObject as w do
w.Left := 10;
---
or maybe better:
---
with w : XObject.YObject.ZObject do
w.Left := 10;
---
(This way ambiguities are removed, and "with" is made safe again)
(NOTE: In-case people complain about the new syntax, remember we've actually
used it in another form since delphi began :)
---
on e : Exception do
ShowMessage(e.Message);
---
//Looks familiar :) - yes we've already used the ideal syntax for "with" in
"on" in exceptions since delphi began, so just need to extend it to "with"
also, so the above syntax for "with" i think is a natural extension, while
still being delphi/pascal like.
---
with e : XObject.YObject.ZObject do
ShowMessage(e.Message);
---
(Will love it when the above gets to compile also :)
My 0.02c
Steve
---
"Nick Hodges (CodeGear)" <nick....@codegear.com> wrote in message
news:469560cf$1...@newsgroups.borland.com...
> Johnnie Norsworthy wrote:
>
>> Why oh why, must Delphi have a with statement?!
>
> Preach it, brother!
>
>> Maybe a compiler warning that cannot be disabled is warranted:
>> "Note: You are using "with". Maintenance programmers "with" torches
>> and clubs will hunt you down
>
> Yes! Yes! Amen!
Yet another reason to support unicode. :)
--
Brian Moelk
Brain Endeavor LLC
bmo...@NObrainSPAMendeavorFOR.MEcom
> > Maybe a compiler warning that cannot be disabled
> > is warranted: "Note: You are using "with".
> > Maintenance programmers "with" torches and
> > clubs will hunt you down.
> Yes! Yes! Amen!
This appears like thoughtless mob rule to me!
--JohnH
> Sarah wrote:
>
> > The "with" should be treated with the same honor of "goto".
>
> Indeed.
You can always replace with with an expansion, You can't always replace
goto. So goto is not entirely useless, while with is, these days.
--
Rudy Velthuis [TeamB] http://rvelthuis.de
"In the End, we will remember not the words of our enemies, but
the silence of our friends."
-- Martin Luther King Jr. (1929-1968)
> > Maybe a compiler warning that cannot be disabled is warranted:
> > "Note: You are using "with". Maintenance programmers "with" torches
> > and clubs will hunt you down
>
> Yes! Yes! Amen!
You are closest to the source. Do it!
--
Rudy Velthuis [TeamB] http://rvelthuis.de
"Giving birth is like taking your lower lip and forcing it over
your head." - Carol Burnett.
> Rudy Velthuis [TeamB] wrote:
> > I'm not sure there are enough letters in the alphabet left for yet
> > another compiler switch. <g>
>
> Yet another reason to support unicode. :)
LOL! {$(some chinese character)+} would be hard to use, though. <g>
--
Rudy Velthuis [TeamB] http://rvelthuis.de
"USA Today has come out with a new survey: Apparently three out
of four people make up 75 percent of the population."
-- David Letterman.
uses
Graphics, Windows;
var b : TBitmap;
b:=TBitmap.Create; // <--- error
b:=Graphics.TBitmap.Create; // <--- ok
New items added to a unit in your "uses" can break existing code too, in the same way as "with".
"Johnnie Norsworthy" <jln...@verizon.net> wrote in message news:469546ce$1...@newsgroups.borland.com...
> Why oh why, must Delphi have a with statement?!
> I know retyping the same thing many times is a pain, but
I do strongly support the idea of a refactoring for with clauses!
Actually I do use WITH statements in special situations like that:
type
TVector = record
X, Y, Z: Double;
end;
function CrossProduct(const A, B: TVector): TVector; ...
...
with CrossProduct(V1, V2) do
Writeln(Format('X: %1.3f Y: %1.3f Z: %1.3f', [x, y, z]);
...
Without a WITH statement I would have to declare a local variable -
which sould have a short name - but also a descriptive one - and should
not be used for other purposes. Things get worse if you work with
reference counted interfaces...
Even if we had a compiler switch that allows or disallows WITH
statements, like we have for "assignable constants", it won't help that
much. If you want to remove WITH statemens you can do that by simple
search instead of making the compiler complain about it. Would also make
some existing code (own and third party) not compile anymore.
I cannot see the benefit of removing WITH from the language. If you
don't like it - don't use it!
There are still a lot of different ways to produce unreadable code
without using any WITH statements.
Uwe Raabe
> New items added to a unit in your "uses" can break
> existing code too, in the same way as "with".
Of course -- and it is sometimes hard to track down.
So let's eliminate the automatic "with" treatment
of the objects of a "use" declaration! <g>
This is why I fear decision making by mobs that
have not given sufficient thought to the situation.
--JohnH
with TSomeObject.Create do
try
<insert code here>
finally
free;
end;
Bill
I like my languages a bit more thought out than the "Yes! Yes! Amen!"
"You are closest to the source. Do it!" frenzy. Now GTYR.
--
>> with System.Camera[i].ROI do
>> begin
>> Left := 0 ;
>> Right := 511 ;
>> Top := 10 ;
>> Bottom := 609 ;
>> end ;
>
> AhhhhhhhHHHH!!!!
>
> What if System.Camera[i].ROI changes its properties to
>
> Left, Right, Height, and Width
Kill the person who changed the properties, because that will always break backwards compatibility ;-)
Another happy example of with:
class function TfrmSomeForm.ClassExecute(pAnObject: TObject): Boolean;
begin
with TfrmSomeForm.Create(nil) do
try
Result := Execute(pAnObject);
finally
Free;
end;
end;
Regards,
Arno
yes, especially with interface instances where u don't even need to free
them.
There are far worse things to be cleaned up in the language
(String/WideString "transparent" casting f.i.), in the RTL (TList and
the rest, etc.) and the VCL (design-time components being public by
default, etc.) which are much more commonly abused that "with" scoping.
Eric
So now the solution is to limit the scope of the "with" to *record
structures* only as it was in old good Pascal AND when using nameless
objects/interfaces????
It's an imperfect world. Fight one battle at a time. This is the "with"
battle. Others to follow as soon as the bodies are carried off....
Van Swofford
Tybee Jet Corp.
:)
Actually, it is better to leave it as it is today. It is reponsibility of
the coder to write readable code and avoid nested "with"s.
Indeed. Isn't GOTO still part of the language? Never used. Never saw a
need.
--
I use nested withs when reading XML files, when reading properties from
different nodes into one object, actually it's the only case when i use
with, but i admit that readability deffinitely suffers ;(
myobject = somthing
with Doc.ChildNodes['item'] do
begin
myobject.name = attributes['name']
with ChildNodes['details'] do
myobject.Description := attributes['description']
...
Regards,
Ondrej
> With Abc, Xyz do
Once I was evaluating a 3rd-party component (can't remember which) that had
a sample application included. Literally the sample code was litered with
statements like
With A, B, C, D, E, F, G, H, I, J Do Begin
Statements that might or might not need one
or more of the above but never all of them.
End;
That was enough for me not to buy the components.
Abraham
My point was that just a few short messages before, you stated,
"Another solution is to limit the scope of the "with" to *record
structures* only as it was in old good Pascal."
Now you say to leave it as is.
I think JohnH was correct in his statement that, "This appears like
thoughtless mob rule to me!"
I am not certain if Nick thinks "with" should completely go away or if
he thinks developers should use it sparingly and cautiously, but I am
certain that he will properly examine the issue before making any
decisions.
There are many battle to be fought, the important battles need to be
fought first, and "with" just isn't anywhere near one of them IMO.
Eric
Then only allow single object ...
with <obj> do --> OK
with <obj1,obj2...> do --> no longer OK
--
Ed.
Have you ever tried to read a really complex SQL statement with aliases
2 years later. Especially when the author decided A, B, C, D, E, F, and
G should be the alias names.
No aliases, no with. Make your code easier to read and debug by using
full names all the time!!!!!
John Herbster wrote:
> "Nick Hodges (CodeGear)" wrote
>
>>> The "with" should be treated with the
>>> same honor of "goto".
>
> How many of us use the alias feature for
> table names in SQL coding?
>
> --JohnH
--
Thomas Miller
Chrome Portal Project Manager
CPCUG Programmers SIG Chairperson (formally Delphi)
Delphi Client/Server Certified Developer
BSS Accounting & Distribution Software
BSS Enterprise Accounting FrameWork
http://www.bss-software.com
http://programmers.cpcug.org/
http://sourceforge.net/projects/chromeportal/
http://sourceforge.net/projects/uopl/
http://sourceforge.net/projects/dbexpressplus
"important" has to have a frame of reference. To whom are the other
problems important? Personally, I've been bitten a number of times by
"with" in code that I was maintaining, but I've never been bitten by the
problems that you mentioned. Therefore, the "with" issue is important to
me, but the other issues are not. I assume that "with" hasn't bitten you,
and that's why it isn't important to you.
Cheers,
uses a, b, c;
is logically similar to
with a, b, c do begin
so maybe "uses" Coders are Monsters too ;-)
AndrewFG
> No aliases, no with. Make your code easier to read and debug by using
> full names all the time!!!!!
You need aliases if you need to use same table twice, or for subqueries,
the fact that a feature can be abused is not enough to take it away. Blame
the one who abused it, not the one who invented the feature.
I wrote a utility to remove with statements.
I've mentioned it before, but thought I would mention it again, because they can be really painful to remove by hand. I had about 9000 of them to remove.
The code is at www.codewrench.org
The utility obeys rules of scope, can handle multiple members in the with statement, and can handle removing nested with statements.
There is a feature for declaring local variables for with statement members. For example,
procedure Test;
begin
with TForm.Create(nil) do
Release;
end;
can be automatically converted to...
procedure Test;
var
AForm: TForm;
begin
AForm := TForm.Create(nil);
AForm.Release;
end;
I don't know of anyone besides me that has used the utility.
If you've used it let me know :)
I probably could have removed them in less time manually, but it was more fun writing the utility to do it automatically :)
How about a compiler warning that says "Note: You are using boring code that
is not remotely challenging to to even a 1st year student."
I'm a proud abuser of WITH, and quite impressed when I can nest them to at
least 3 levels deep. Even I can't make sense of what I've written after the
event, but then that's why I paid good money for a compiler.
And get rid of GOTO?? OMG, where's the appreciation of history! If even the
simplest application doesn't have at least one GOTO, you aren't even trying.
Like what I've seen people do that could be done with a simple CONTINUE
statement is just laughable.
michael
Was already brought up by David Berneda in the "with" Coders are
Monsters thread, however, it will be interesting to see comments
specific to Uses.
More interesting, perhaps, would be the implicit "with self do" on every
OO method.
Heck, let's get rid of scope altogether!
> >Just to open up the discussion -- did it occur to anyone that
> > uses a, b, c;
> >is logically similar to
> > with a, b, c do begin
> Was already brought up by David Berneda ,,,
Hey! I thought that this was supposed to be a
write-only thread. Do you mean that there is
something to be gained by reading the other
posts? <g>
> > Why oh why, must Delphi have a with statement?!
> How about a compiler warning that says "Note: You
> are using boring code that is not remotely challenging
> to even a 1st year student."
> I'm a proud abuser of WITH, and quite impressed when
> I can nest them to at least 3 levels deep. Even I
> can't make sense of what I've written after the event,
I think that that may be the reason why some programmers
love to hate "with" statements so much so that they will
avoid fixing the code with automatic "refactoring".
--JohnH
Ditto. I use 'with' in a lot of initialization coding for objects, etc. and
would hate to see it go.
Shhh, I also use goto for complex operations where refactoring the code just
isn't apparent or optimal.
Woody (TMW)
Charles, Are you sure?
www.codewrench.org directs me to
http://codewrench.sourceforge.net/
which displays "You've found the new
CodeWrench homepage hosted by SourceForge"
When I click on that "SourceForge" I come to
http://sourceforge.net/projects/codewrench
Where clicking Download takes me to a zip containing
"WithStatementRefactoring" among other things.
Does WithStatementRefactoring stand alone?
How is it used? Rgds, JohnH
I like the VB.NET dot notation for using with, but still it has to be short
blocks of code. I might actually use this, but never with compound withs.
Voted today on the "with removal" refactoring as pointed out in QC.
And I agree that "uses" abuse is also bad. Even in Win32 Delphi I will
sometimes qualify where a method, variable, or constant is located by
preceeding the unit name.
-Johnnie
But you've left out some of the scope information in your example.
Suppose it is written like so...
procedure TForm1.ButtonClick(Sender: TObject);
begin
with System.Camera[i].ROI do
begin
Left := 0 ;
Right := 511 ;
Top := 10 ;
Bottom := 609 ;
end ;
end;
Now suppose I don't know anything about System.Camera[i].ROI
From the example above, its not clear if Top, Left, Bottom, Right all belong to ROI, or if only Top and Left belong to ROI. See how easy it is to leave a trap for someone?
Aren't we **really** discussing scope here? If so, then the other
thread is in scope and should be considered <g><g>
WithStatementRefactoring is a bpl that can be imported into CodeWrench.exe
You should find a 'doc' subfolder inside CodeWrench.0.4.0.2.zip
The help explains how to parse a project, and how to import refactorings into CodeWrench.
If you still need help, you can e-mail me personally (e-mail in header).
-- Charles
> Since you are the Delphi Product Manager I know you have the power to
> do something about the syntax, and especially since you agree with
> everyone that says "with" is bad or should be removed I'm a bit
> scared that you might remove it :)
Sadly, the with statement will never be removed.
If you like it and want to use it, that is totally up to you. I think
you're nuts, but it is totally up to you. ;-)
--
Nick Hodges
Delphi Product Manager - CodeGear
http://blogs.codegear.com/nickhodges
> Rudy Velthuis [TeamB] wrote:
> > > Yes! Yes! Amen!
> >
> > You are closest to the source. Do it!
>
> I like my languages a bit more thought out than the "Yes! Yes! Amen!"
> "You are closest to the source. Do it!" frenzy. Now GTYR.
IAIMRA. <g>
Not a frenzy, anyway. This is a problem since ages. <g>
--
Rudy Velthuis [TeamB] http://rvelthuis.de
"That is the saving grace of humor, if you fail no one is laughing
at you." -- A. Whitney Brown
> Steve wrote:
>
> > Since you are the Delphi Product Manager I know you have the power
> > to do something about the syntax, and especially since you agree
> > with everyone that says "with" is bad or should be removed I'm a bit
> > scared that you might remove it :)
>
> Sadly, the with statement will never be removed.
>
> If you like it and want to use it, that is totally up to you. I think
> you're nuts, but it is totally up to you. ;-)
But a refactoring to remove it from existing source would be very nice.
--
Rudy Velthuis [TeamB] http://rvelthuis.de
"The truth is more important than the facts."
-- Frank Lloyd Wright (1868-1959)
Then is there a chance that CodeInsight and the
debugger will be updated to handle this?
I wouldn't be nearly so bad if the computer would
tell us what it already knows.
I haven't had much hope since I assumed that
'with' would be deprecated, thus thinking that
there wouldn't be much incentive.
But adding these two features would make the
situation much more livable.
Thanks,
Brad.
Agreed, "Uses" abuse is just laziness and confusing. And relying on the
Uses order to determine which method is actually called when units contain
methods of the same name is a far worse sin in my books than nested WITHS.
I also agree that the VB dot notation for WITH is totally logical and would
presumably overcome your dislike of Delphi WITH. The refactoring idea to
expand WITHS is a good one, but I'd also like a way of refactoring code to
reduce If MyDataModule.MyLongTableName.FindKey([..]) etc, to WITH code
blocks.
Still, I don't think we should be writting software to account for the
lowest common demonitor of skill level required to maintain code at a later
date.
michael
Isn't that the "fun" of programming though, code that works even though to
look at, it doesn't immediately make sense what's going on? Where is the
personal satisfaction in writing code that a less experienced person can
immediately decode?
Whats that point of gaining knowledge at all if we limit ourselves to
expressing only what a less knowledgable person will understand. I'm not
suggesting making our code deliberately obtuse, but limiting our use of the
available technology purely to avoid confusing subsequent maintainers seems
totally bizarre to me.
michael
Oh, thats classic! :-)
I think the big problem with that approach is that the people who are
'impacted' by the use of 'with' are not necessarily the people who use it.
Its the folks who have to maintain code littered with 'withs' who have been
burned.
uh-oh, they're regrouping!
>
> There's no need to 'limit our use of technology', but if you ignore
> the fact that code maintenance is a major factor, you're mistaken --
> and asking for trouble.
Truer words...
Horsepuckey.
I consider myself to be a pretty competent coder. I consider myself to
be one of the best 'code documenters' around. That's not to say that
occasionally I don't do something 'quick and dirty', but in the main I
understand that code will have to be maintained down the road.
Even given that, there are times I'll go back to code I've written (my
OWN code) many years later, and either not understand what the heck I
did, or will ask myself WHY the heck I did it that way.
There's no need to 'limit our use of technology', but if you ignore the
fact that code maintenance is a major factor, you're mistaken -- and
asking for trouble.
David Erbas-White
If I'm not the one doing the maintaining, why am I asking for trouble?
Why should I care less about your issues maintaining my code? Presumably
I've been paid for a project delivered on time and on budget, or I've been
retrenched and you're left holding the can. Either way, I've produced the
most efficient code to the best of my ability. I don't see why I should
have anticipated someone else's lack of analytical skills while I was
writing the software.
michael
> If I'm not the one doing the maintaining, why am I asking for trouble?
>
Yes, truer words what? You should riddle your compiler with even more
pointless warnings than it produces now? I'm not sure I have the screen
space, maybe we need an option to output warnings on their own monitor.
I can't believe you agree with nobbling WITH and GOTO simply to make life a
bit easier for some unknown maintainer down the track. I want to produce a
solution in the here and now, something Delphi happens to be quite good at.
michael
> can't believe you agree with nobbling WITH and GOTO simply to make
> life a bit easier for some unknown maintainer down the track. I want
> to produce a solution in the here and now, something Delphi happens
> to be quite good at.
I'm gathering that you are taking this a little more seriously than the
rest of us.
I'm strongly against the use of with -- I think it is bad code and
creates many potential problems. You maybe don't think that.
I'm cool with our difference of opinion. Code as you see fit.
Not quite that seriously, I think its funny that such a minor thing is so
polarising.
But I do like my WITHs though.. and the occasional GOTO.
I just don't want to see those "helpful" little hints that with or goto are
deprecatiated. Seriously, compiler warnings have become excessive in D2007.
michael
I, too, think that it is a little funny (as in weird) that
such a minor thing is so polarizing;
and as such it is a little scary. --JohnH