Board index » delphi » Re: while we're at it (feature request)

Re: while we're at it (feature request)


2003-12-15 11:52:51 PM
delphi221
I personally would be against anything that encourages the use
of WITH. Your solution can be implimented right now just by
declaring a variable of the right type and doing an assignment
and eliminating the with altogether
Underling := Company[2].Staff.PersonNumber[23532];
Boss := Company[3].Management.PersonNumber[2342];
Boss.Headhunt(Underling);
Underling.pissedOffBy(Boss);
Underling.Rejects(Boss);
Boss.pissedOffBy(Underling);
If you add in the two declaration lines and subtract the extra
lines forh the begin and end it is the same amount of lines of
code. It adds no additional readability over the above example
that can be done today.
Also your suggestions reuses th AS keyword in such a way that
has no relation to the current definition of AS further hurting readability later down the road.
"Ben Hochstrasser [FF]" <bhoc@tiscali123^H^H^H.ch>writes:
Quote
It would be nice to have "with" aliases just like in SQL ("select name from
persons A, salary from cash B where A.ID = B.ID").

e.g.

with Underling as Company[2].Staff.PersonNumber[23532] do begin
with Boss as Company[3].Management.PersonNumber[2342] do begin
Boss.Headhunt(Underling);
Underling.pissedOffBy(Boss);
Underling.Rejects(Boss);
Boss.pissedOffBy(Underling);
end;
end;

would be useful. Especially when two or more of the nested with objects
share a property with the same name.

--
Ben
 
 

Re: while we're at it (feature request)

On 15-Dec-03, Keith Miller said:
Quote
I stopped using 'with' a couple of years back. IMHO it is the source
of too many problems.
No bullets from here! <g>I rarely use with, but I do occasionally find
it useful, and I disagree with the folks who feel it should be removed
from the language. Nothing prevents anyone from setting local policies
against its use.
--
Bill
--------
"You can not keep on doing things the old way and still get the benefits
of the new way." -- Thomas Sowell
 

Re: while we're at it (feature request)

It would be nice to have "with" aliases just like in SQL ("select name from
persons A, salary from cash B where A.ID = B.ID").
e.g.
with Underling as Company[2].Staff.PersonNumber[23532] do begin
with Boss as Company[3].Management.PersonNumber[2342] do begin
Boss.Headhunt(Underling);
Underling.pissedOffBy(Boss);
Underling.Rejects(Boss);
Boss.pissedOffBy(Underling);
end;
end;
would be useful. Especially when two or more of the nested with objects
share a property with the same name.
--
Ben
 

Re: while we're at it (feature request)

"Ben Hochstrasser [FF]" <bhoc@tiscali123^H^H^H.ch>writes
Quote
It would be nice to have "with" aliases just like in SQL ("select name
from
persons A, salary from cash B where A.ID = B.ID").

e.g.

with Underling as Company[2].Staff.PersonNumber[23532] do begin
with Boss as Company[3].Management.PersonNumber[2342] do begin
Boss.Headhunt(Underling);
Underling.pissedOffBy(Boss);
Underling.Rejects(Boss);
Boss.pissedOffBy(Underling);
end;
end;

would be useful. Especially when two or more of the nested with objects
share a property with the same name.

--
Ben
I stopped using 'with' a couple of years back. IMHO it is the source of too
many problems.
Keith
(Stands back and waits for the bullets to start flying...)
 

Re: while we're at it (feature request)

Ben Hochstrasser [FF] writes:
Quote
It would be nice to have "with" aliases just like in SQL ("select
name from persons A, salary from cash B where A.ID = B.ID").
I could be mistaken, but I think this is already a QC report.
qc.borland.com
 

Re: while we're at it (feature request)

Jeff Overcash (TeamB) writes:
Quote
If you add in the two declaration lines and subtract the extra
lines forh the begin and end it is the same amount of lines of
code.
I agree this works with classes. The assignment won't work with records -
you'd have to assign each member, right?
(although I assume records sooner or later are "deprecated" as well)
Quote
Also your suggestions reuses th AS keyword in such a way that
has no relation to the current definition of AS further hurting
readability later down the road.
Well, it was the only thing that immediately came to mind ;-)
--
Ben
 

Re: while we're at it (feature request)

On Mon, 15 Dec 2003 17:35:30 +0100, Ben Hochstrasser [FF]
<bhoc@tiscali123^H^H^H.ch>writes:
Quote
would be useful. Especially when two or more of the nested with objects
share a property with the same name.
Which is the very place to never use WITH as it make the code difficult to
read by others not familar with your type structure. Nothing beats local
variables for clarity.
Kevin
--
Using M2, Opera's revolutionary e-mail client: www.opera.com/m2/
 

Re: while we're at it (feature request)

On 15-Dec-03, Charles McAllister said:
Quote
Oh really? What if your boss insists on using with statements? I
submitted a feature request to the PascalAnalyzer folks to see if I
could get a report of ambiguous code caused by with statements.
Anyone know of a utility out there that can do this?
Yes, really. My boss insist on cutting and pasting, and is unwilling to
be retrained. In the end, you have to decide to stay or go, and railing
at the publisher of a software tool because you don't like the way your
boss wants you to code (or the way he codes) is pretty silly.
--
Bill
--------
"You can not keep on doing things the old way and still get the benefits
of the new way." -- Thomas Sowell
 

Re: while we're at it (feature request)

"
Which is the very place to never use WITH as it make the code difficult to
read by others not familar with your type structure. Nothing beats local
variables for clarity.
..and ease of debugging.
Rgds,
Martin
 

Re: while we're at it (feature request)

Keith Miller wrote on Mon, 15 Dec 2003 16:52:25 -0000 ...
Quote
I stopped using 'with' a couple of years back. IMHO it is the source of too
many problems.
Yes. But this syntax would solve the problems that with has in a neat
way. 'as' may not be the correct word to use but I for one support the
idea (and thenwe can deprecate the old syntax too)
Marc Rohloff
marc rohloff at bigfoot dot com
 

Re: while we're at it (feature request)

"William Meyer" <XXXX@XXXXX.COM>writes
Quote
On 15-Dec-03, Keith Miller said:
No bullets from here! <g>I rarely use with, but I do occasionally find
it useful, and I disagree with the folks who feel it should be removed
from the language. Nothing prevents anyone from setting local policies
against its use.

Oh really? What if your boss insists on using with statements? I submitted
a feature request to the PascalAnalyzer folks to see if I could get a report
of ambiguous code caused by with statements. Anyone know of a utility out
there that can do this?
Charles
 

Re: while we're at it (feature request)

Something like that existed in a Pascal like real-time programming language
(called Portal) developed jointly by the ETH of Zuerich and Landis & Gyr,
Inc in Zug, Switzerland.
They were 3 forms:
// read only alias
with x==aRecord do
n := x.Field;
end with;
// r/w alias
with x::aRecord do
x.Field := n;
end with;
// Temporary variable. This is nice since x is declared ''in the code'' and
has
// the same scope of the with statement.
with x := 1 do
while x <= 10 do
DoSometing;
inc(x);
end while;
end with;
of, course, you could write:
with identifier := expression...
The Pascal like 'with' statement (i.e witout alias) was not allowed! This
implementation removed most if not all the ''with-statement'' problems.
Christian
 

Re: while we're at it (feature request)

"Ben Hochstrasser [FF]" <bhoc@tiscali123^H^H^H.ch>writes:
Quote
Jeff Overcash (TeamB) writes:

>If you add in the two declaration lines and subtract the extra
>lines forh the begin and end it is the same amount of lines of
>code.

I agree this works with classes. The assignment won't work with records -
you'd have to assign each member, right?
No, Delphi copies the record just fine. A call to _CopyRecord
is made as part of the assignment (if you view the CPU view at
the time of the assignment you shold see this call).
 

Re: while we're at it (feature request)

William Meyer writes:
Quote
No bullets from here! <g>I rarely use with, but I do occasionally find
it useful, and I disagree with the folks who feel it should be removed
from the language. Nothing prevents anyone from setting local policies
against its use.
It is very useful for COM interfaces. The Matrox Imaging Library for
example has deeply nested elements.
Using with speeds up the program very much because the dereferencing
a.b.c.d is a costly operation.
 

Re: while we're at it (feature request)

Lee Grissom writes:
Quote
I could be mistaken, but I think this is already a QC report.
qc.borland.com
Since you mentioned QC- there are quite a few WITH related ones. My
favourites are below:
1. qc.borland.com/wc/wc.exe/details
It allows people to still use WITH and avoid the problems by making the
developer aware of ambiguities if they arise.
I'm against the removal of "WITH" from Delphi (as some people have
suggested). I am also against leaving the "WITH" statement in the
language as it is today- something has to be done to remove the
perceived problems with its use. Personally, I use WITH all the time
and I have never run into any problems associated with it. However, I
would really like other language enhancements to "WITH" (see below).
The CR mentioned above should stop people from whining and moaning about
"WITH". I hope!! ;-)
2. qc.borland.com/wc/wc.exe/details
<quote>
Although VB(Visual Basic) is inferior to Delphi in many ways
there is one particular feature that I like in the
language. If this were to be implemented in Delphi
the syntax would appear as follows:
with SomeObject do
begin
.SomeMethod;
.SomeProperty := 'abc';
end;
There are a few advantages to this including:
1. Code completion can more easily determine
which methods etc. can be displayed.
2. Developers reading the code won't be
confused by ambiguities when reviewing this
code.
</quote>
I would add to this to include the suggested change because I like it to:
with X := SomeObject do
begin
X.SomeMethod;
X.SomeProperty := 'abc';
end;
Cheers,
Kevin.