Article View: comp.std.c++
Article #1980Re: Pascal-like 'with' statement feasible in C++?
From: David Chase
Date: Sat, 16 Sep 1995 17:42
Date: Sat, 16 Sep 1995 17:42
49 lines
2120 bytes
2120 bytes
> In article <MATT.95Sep14102849@physics10.Berkeley.EDU>,
"Eugene Radchenko" <eugene@qsar.chem.msu.su> writes:
> |> I would like to hear the opinions on the following problem:
> |> whether it is possible/worthwhile to introduce the analog of Pascal 'with'
> |> statement into C++ ?
> |> Suppose you have the following declarations:
> |> type tpair = object
> |> m,n: integer;
> |> end;
> |> var pairs : array[1..10] of tpair;
> |> then you can write, for instance:
> |> for i = 1 to 10 do
> |> with pairs[i] do
> |> m = n;
> |> instead of
> |> for i = 1 to 10
> |> pairs[i].m = pairs[i].n;
In article <fjh-950915-234944@cs.mu.oz.au>, moser@bnr.ca (Lionel Moser) writes:
> ... can be a disaster in large software systems.
Agreed. Note that in Modula-3, for about this reason, "with" was changed
to bind to a name, as in (using example above):
> |> for i = 1 to 10 do
> |> with p = pairs[i] do
> |> p.m = p.n;
> |> end end
This gives you most of the conciseness, with none of the problems.
Furthermore, you can get this effect in C++ with references, as in:
for (i = 1; i <= 10; i++) {
tpair & p = pairs[i];
p.m = p.n;
}
Modula-3 doesn't require a type, but C++ doesn't require the
do, with, do, end, end. This is not one of the interesting differences
between the two languages.
speaking for myself,
David Chase
---
[ comp.std.c++ is moderated. Submission address: std-c++@ncar.ucar.edu.
Contact address: std-c++-request@ncar.ucar.edu. The moderation policy
is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
Technical Details
Message-ID:
<43c80c$npk@wcap.centerline.com>Path:
arc1-ca.pugleaf.net!in2.uu.net!bounce-backReferences:
<fjh-950915-234944@cs.mu.oz.au>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!in2.uu.net!bounce-back Date: 16 Sep 95 17:42:41 GMT Approved: fjh@cs.mu.oz.au Return-Path: <daemon@migs.UCAR.EDU> From: chase@centerline.com (David Chase) Newsgroups: comp.std.c++ Subject: Re: Pascal-like 'with' statement feasible in C++? X-Original-Date: 15 Sep 1995 16:01:16 GMT Organization: CenterLine Software Sender: chase@centerline.com (David Chase) Message-ID: <43c80c$npk@wcap.centerline.com> References: <fjh-950915-234944@cs.mu.oz.au>