C
Chris Dollin
Tom said:Not really.
Yes, really. `with` is a /pain/; local alias declarations (which is
what you can easily construct in C, even if it's a bit clunky) are
more general and more useful.
Yeah you can work around it but it would be cooler if it
was a native function of the language. It would integrate well I think
as you'd just have scoping rules. E.g. variables in the struct/union
that you with'ed would take precedence over stuff external, e.g.
int this;
with (mystruct) { this = 4; }
Modifies the "this" in the struct. You'd have to be able to nest it
too...
Yes, I know all that. Here is my opinion:
It's not worth it.
It makes the code harder to read (because, inside the body, you
/don't know/ if an identifier refers to a record component or
not). It doesn't nest. If you make provision for nesting, you
end up wanting names for the different nests - at which point,
you've reinvented local alias declarations.
yeah but if you see
somefile.c line 1033
p->npny = cba(SOME_VALUE);
Or someshit which is common in coporate code you still have to read the
headers to decipher wtf "npny" is and what else *p contains.
`with` doesn't help either.
{
WhateverTypeItIs *pp = p[4]->this.item;
pp->values = 3; pp->key = "hello"; blah();
}
Yeah, that's clearly so much simpler.
It's /available/. Now.
Now, if what you are wanting is something like:
with <declaration sequence> do <statement>;
I'd be with you. Of course in C99 you just do:
<declaration sequence>
<statement>
[fiddle with scopes if necessary], ie, the code above becomes:
WhateverTypeItIs *pp = p[4]->this.item;
pp->values = 3; pp->key = "hello"; blah();
which is pretty much the same as your `with`, but now there's
no special dinking around with scopes.
Hmm ... right.
Anyways, given that I've been coding/developing in C for a while I too
know how to work around that and make it all maintainable. I'm just
answering the OPs question. If you were to add something to C, I think
with would be a cool thing to add.
If you were to add something to C, there are /lots/ of things that
would be more useful.