After read a whole OS written by C, someone asks `What is the advantage of C'

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.
 
T

Tom St Denis

Chris said:
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.

Ok change it so you have to use a . prefix.

e.g.

with (that) { .this = 3; .somethingelse = 4; }

Eitherway it was a "what if" question. Sit down, stop the temper
tantrum and just say "how quaint."

Tom
 
C

Chris Dollin

Tom said:
Ok change it so you have to use a . prefix.

No, thank you: that's just introducing an opportunity for error
(since `.` already has a meaning). It also doesn't solve the
nesting problem (unless one uses . and .. and ... ...!)

Using declared names solves the original problem (terser references
to items inside structures), is already available, and is (IMAO)
clearer.
Eitherway it was a "what if" question. Sit down, stop the temper
tantrum

There is no tantrum here.
and just say "how quaint."

"Quaint" is not the adjective I'd choose.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,175
Latest member
Vinay Kumar_ Nevatia
Top