December 09, 2007 Re: Does anyone use 'with' statement? | ||||
---|---|---|---|---|
| ||||
Posted in reply to serg kovrov | serg kovrov wrote: > Recently I have studied a (proprietary language) code. The language features 'with' statement in the same sense that D does. To understand what this code sample really do I had to remove all 'with's and fix/compile code many times before it start working as original. > > I don't know why never tried to use it in my own code before, but now I definitely will NOT use it ever. Even if it could save me some typing. I found 'with' far more evil than even 'goto' (which I don't use as well). I sometimes use it to bring in a certain template instantiation for multi-member templates, like: with(EuclidianSpace!(3,float)) { Vector a,b; // ... } -- Oskar |
December 09, 2007 Re: Does anyone use 'with' statement? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Bill Baxter | Bill Baxter wrote:
> These are rules of thumb, not hard and fast. The basic question is "will I be able to figure out what this is doing if I come back to this code next year". Which is really what I try to ask myself for all code I write, so 'with' isn't really special in that sense.
My (original) question rather is, will I (average Joe) understand your code (using 'with') without refactoring it?
-- serg.
|
December 09, 2007 Re: Does anyone use 'with' statement? | ||||
---|---|---|---|---|
| ||||
Posted in reply to serg kovrov | Well, I perfectly understand the intent. My first thoughts regarding 'with' was it could be used for isolating/grouping of complex objects initialization. for example: with (window = new Window()) { Create(); Move(12, 34); Attach(children); Show(true); Etc(); } But as everyone agreed so far, 'with' requires discipline. And my experience taught me that when it comes to others code, discipline is not the thing you can count on. Speaking of other 'disciplined' software development aspects such as manual memory management, manual references management, goto's, etc., it could be mitigated by unit and system testing. But still, testing do not guaranteed program correctness. And in case of readability I don't see means to enforce (or even motivate) 'correctness' just yet. -- serg. |
Copyright © 1999-2021 by the D Language Foundation