Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c > #139209
| From | David Brown <david.brown@hesbynett.no> |
|---|---|
| Newsgroups | comp.lang.c, comp.lang.c++ |
| Subject | Re: if cargo blocks |
| Date | 2018-12-29 17:26 +0100 |
| Organization | A noiseless patient Spider |
| Message-ID | <q0878a$bct$1@dont-email.me> (permalink) |
| References | <q084io$qe1$1@dont-email.me> |
Cross-posted to 2 groups.
On 29/12/2018 16:42, Rick C. Hodgin wrote:
> I've had the idea for an "if cargo" block. It is a standard if {}
> block, but one containing additional cargo prefixed by in, out, and
> enter keywords, to be contained within each if clause to run before,
> after, and when entering the if statement.
>
> The enter clause is given specifically to relate to something that
> should be done, possibly to undo something done in the in clause,
> including possibly calling the out clause to undo that setup, and
> prepare it for whatever other code is needed within the block.
>
> The cargo portion allows a sequence of conditions to be established
> sequentially, in a traditional if{} block, with the ability to inject
> new code at each stage to augment the environment, to then live-test
> the condition.
>
> if (some_test1)
> in { setup_for_test1 }
> out { cleanup_for_test1 }
> enter { related_code_if_block_entered1 }
> {
> // Code1 here for this test passing
>
> } else if (some_test2)
> in { setup_for_test2 }
> out { cleanup_for_test2 }
> enter { related_code_if_block_entered2 }
> {
> // Code2 here for this test passing
> }
>
> -----
> The above would work out to this logic:
>
> setup_for_test1;
> if (some_test1)
> {
> related_code_if_block_is_entered1;
> // Code1 here for this test passing
> goto all_done;
>
> } else {
> cleanup_for_test1;
> }
>
> setup_for_test2;
> if (some_test2)
> {
> related_code_if_block_is_entered2;
> // Code2 here for this test passing
>
> } else {
> cleanup_for_test2;
> }
> all_done:
>
> -----
> It allows code for setup_for_test, cleanup_for_test, and
> related_code_if_block_entered to be encapsulated into its
> intended meaning by placing it where it's used, related
> to how it's being used, being easily understood as to what
> it's really doing.
>
> It also implicitly documents the purpose of that code nearby,
> as being part of each if{} statement's prepare, test, cleanup
> code.
>
If your suggestion works out to that code, why not just write that code?
It is simpler and clearer, and would make it obvious that the
"cleanup" code is not called if the branch is taken. And the "goto" can
be avoided by using nested "if", or early returns, if that is what
bothers you.
I am at a loss to understand why you want so many new syntaxes for
different ways of writing the same code in different non-sequential orders.
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
if cargo blocks "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2018-12-29 10:42 -0500
Re: if cargo blocks David Brown <david.brown@hesbynett.no> - 2018-12-29 17:26 +0100
Re: if cargo blocks Mr Flibble <flibbleREMOVETHISBIT@i42.co.uk> - 2018-12-29 16:32 +0000
Re: if cargo blocks Bart <bc@freeuk.com> - 2018-12-29 16:56 +0000
Re: if cargo blocks "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2018-12-29 12:34 -0500
Re: if cargo blocks Bart <bc@freeuk.com> - 2018-12-29 23:49 +0000
Re: if cargo blocks "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2018-12-29 18:52 -0500
Re: if cargo blocks Mr Flibble <flibbleREMOVETHISBIT@i42.co.uk> - 2018-12-30 00:12 +0000
Re: if cargo blocks rbowman <bowman@montana.com> - 2018-12-29 19:04 -0700
Re: if cargo blocks Ralf Goertz <me@myprovider.invalid> - 2018-12-30 06:12 +0100
Re: if cargo blocks David Brown <david.brown@hesbynett.no> - 2018-12-30 15:23 +0100
Language (Was: if cargo blocks) gazelle@shell.xmission.com (Kenny McCormack) - 2018-12-30 15:39 +0000
Re: Language (Was: if cargo blocks) rbowman <bowman@montana.com> - 2018-12-30 11:23 -0700
Re: if cargo blocks Ralf Goertz <me@myprovider.invalid> - 2018-12-31 05:21 +0100
Re: if cargo blocks David Brown <david.brown@hesbynett.no> - 2018-12-31 18:09 +0100
Re: if cargo blocks rbowman <bowman@montana.com> - 2018-12-31 12:22 -0700
Re: if cargo blocks Ralf Goertz <me@myprovider.invalid> - 2019-01-01 12:04 +0100
Re: if cargo blocks rbowman <bowman@montana.com> - 2018-12-31 11:50 -0700
Re: if cargo blocks Ralf Goertz <me@myprovider.invalid> - 2019-01-01 11:43 +0100
Re: if cargo blocks Ralf Goertz <me@myprovider.invalid> - 2019-01-01 14:27 +0100
German grammar (Was: if cargo blocks) gazelle@shell.xmission.com (Kenny McCormack) - 2019-01-01 14:17 +0000
Re: if cargo blocks rbowman <bowman@montana.com> - 2019-01-01 11:04 -0700
Re: if cargo blocks fir <profesor.fir@gmail.com> - 2019-01-01 10:38 -0800
Re: if cargo blocks rbowman <bowman@montana.com> - 2019-01-01 10:57 -0700
DDR Ralf Goertz <me@myprovider.invalid> - 2019-01-01 21:18 +0100
Re: DDR rbowman <bowman@montana.com> - 2019-01-01 16:18 -0700
Re: if cargo blocks Siri Cruise <chine.bleu@yahoo.com> - 2019-01-01 16:30 -0800
Re: if cargo blocks rbowman <bowman@montana.com> - 2018-12-30 11:09 -0700
Re: if cargo blocks Ralf Goertz <me@myprovider.invalid> - 2018-12-31 05:43 +0100
Re: if cargo blocks rbowman <bowman@montana.com> - 2018-12-31 12:06 -0700
Linguistics. Re: if cargo blocks Siri Cruise <chine.bleu@yahoo.com> - 2019-01-01 16:27 -0800
Re: Linguistics. Re: if cargo blocks rbowman <bowman@montana.com> - 2019-01-01 22:30 -0700
Re: Linguistics. Re: if cargo blocks Louis Krupp <lkrupp@nospam.pssw.com.invalid> - 2019-01-02 04:18 -0700
Re: if cargo blocks Bart <bc@freeuk.com> - 2018-12-30 02:07 +0000
Re: if cargo blocks "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2018-12-29 21:59 -0500
Re: if cargo blocks rbowman <bowman@montana.com> - 2018-12-29 13:57 -0700
Re: if cargo blocks "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2018-12-29 16:03 -0500
Re: if cargo blocks Mr Flibble <flibbleREMOVETHISBIT@i42.co.uk> - 2018-12-29 21:32 +0000
Re: if cargo blocks rbowman <bowman@montana.com> - 2018-12-29 16:06 -0700
Re: if cargo blocks "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2018-12-29 18:15 -0500
Re: if cargo blocks fir <profesor.fir@gmail.com> - 2018-12-29 15:32 -0800
Re: if cargo blocks fir <profesor.fir@gmail.com> - 2018-12-29 15:34 -0800
Re: if cargo blocks fir <profesor.fir@gmail.com> - 2018-12-29 15:38 -0800
Re: if cargo blocks "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2018-12-29 15:40 -0800
Re: if cargo blocks fir <profesor.fir@gmail.com> - 2018-12-29 15:45 -0800
Re: if cargo blocks "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2018-12-29 18:36 -0500
Re: if cargo blocks fir <profesor.fir@gmail.com> - 2018-12-29 15:42 -0800
Re: if cargo blocks "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2018-12-29 15:45 -0800
Re: if cargo blocks fir <profesor.fir@gmail.com> - 2018-12-29 15:54 -0800
Re: if cargo blocks "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2018-12-29 18:58 -0500
Re: if cargo blocks fir <profesor.fir@gmail.com> - 2018-12-29 16:01 -0800
Re: if cargo blocks "Chris M. Thomasson" <invalid_chris_thomasson@invalid.invalid> - 2018-12-29 13:36 -0800
Re: if cargo blocks "I Set My Girlfriend's Pantyhose on Fire" <cdalten@gmail.com> - 2018-12-29 13:16 -0800
Re: if cargo blocks "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2018-12-29 16:32 -0500
Re: if cargo blocks Siri Cruise <chine.bleu@yahoo.com> - 2018-12-30 13:00 -0800
Re: if cargo blocks "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2018-12-30 16:12 -0500
Re: if cargo blocks Siri Cruise <chine.bleu@yahoo.com> - 2018-12-30 13:31 -0800
Re: if cargo blocks "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2018-12-30 16:45 -0500
Re: if cargo blocks Bart <bc@freeuk.com> - 2018-12-30 22:17 +0000
Re: if cargo blocks "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2018-12-30 17:22 -0500
Re: if cargo blocks "Chris M. Thomasson" <invalid_chris_thomasson@invalid.invalid> - 2018-12-30 20:25 -0800
Re: if cargo blocks Ian Collins <ian-news@hotmail.com> - 2019-01-03 09:50 +1300
Re: if cargo blocks "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2019-01-02 15:54 -0500
Re: if cargo blocks "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2019-01-02 16:29 -0500
Re: if cargo blocks mark.bluemel@gmail.com - 2019-01-03 00:44 -0800
Re: if cargo blocks "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2019-01-03 08:17 -0500
Re: if cargo blocks mark.bluemel@gmail.com - 2019-01-03 05:40 -0800
Re: if cargo blocks "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2019-01-03 09:15 -0500
You are so full of shit (Was: if cargo blocks) gazelle@shell.xmission.com (Kenny McCormack) - 2019-01-03 13:42 +0000
Re: if cargo blocks fir <profesor.fir@gmail.com> - 2019-01-03 12:27 -0800
Re: if cargo blocks Ian Collins <ian-news@hotmail.com> - 2019-01-04 11:11 +1300
Re: if cargo blocks "Chris M. Thomasson" <invalid_chris_thomasson@invalid.invalid> - 2019-01-03 14:37 -0800
Re: if cargo blocks "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2019-01-03 17:48 -0500
Re: if cargo blocks fir <profesor.fir@gmail.com> - 2019-01-03 14:59 -0800
Re: if cargo blocks mark.bluemel@gmail.com - 2019-01-03 00:44 -0800
Re: if cargo blocks "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2019-01-03 08:19 -0500
Re: if cargo blocks mark.bluemel@gmail.com - 2019-01-03 05:43 -0800
Re: if cargo blocks "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2019-01-03 05:51 -0800
Re: if cargo blocks "Chris M. Thomasson" <invalid_chris_thomasson@invalid.invalid> - 2019-01-03 13:22 -0800
Re: if cargo blocks Ian Collins <ian-news@hotmail.com> - 2019-01-04 11:10 +1300
csiph-web