Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | David Brown <david.brown@hesbynett.no> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: CAlive special use instance class, called an angel |
| Date | 2015-10-30 16:43 +0100 |
| Organization | A noiseless patient Spider |
| Message-ID | <n1032k$3la$1@dont-email.me> (permalink) |
| References | (2 earlier) <306c76e3-1ac6-4237-af32-bd5ef4488dd0@googlegroups.com> <87twp8g0gl.fsf@bsb.me.uk> <7f773e2a-fb37-49f8-bb83-97dded468fba@googlegroups.com> <n0vq4r$t74$1@dont-email.me> <e8f30178-64cd-41ed-9c71-078b9d7f61bb@googlegroups.com> |
On 30/10/15 14:21, Rick C. Hodgin wrote:
> On Friday, October 30, 2015 at 9:11:05 AM UTC-4, David Brown wrote:
>> On 30/10/15 12:35, Rick C. Hodgin wrote:
>>> On Friday, October 30, 2015 at 5:39:07 AM UTC-4, Ben Bacarisse wrote:
>>>> "Rick C. Hodgin" <rick.c.hodgin@gmail.com> writes:
>>>>
>>>>> On Thursday, October 29, 2015 at 9:27:29 PM UTC-4, Ian Collins wrote:
>>>> <snip>
>>>>> So, with angels you use:
>>>>>
>>>>> AWhatever w;
>>>>> something(w("1"), w("2"), w("3"));
>>>>> // At this point, no instance of w remains in scope
>>>>
>>>> Somewhat topical: you are confusing scope and lifetime: scope is a
>>>> spacial property of a name; lifetime is a temporal property of an
>>>> object. Obviously they are connected but "no instance of w remains in
>>>> scope" is, at best, confusing.
>>>
>>> I have stopped responding to you because I see in my case and others,
>>> you're often having trouble understanding the things people write. I
>>> think you actually do understand in all cases, so it makes the response
>>> pointless.
>>
>> I have found Ben's comments almost always to be accurate, considered,
>> informed and to the point. He rates very highly on my list of people to
>> listen to in this group. (But please don't reply to this point - I'd
>> rather not have a discussion about people here.)
>>
>>>
>>> However, it is very likely I'm using the terms improperly compared to
>>> however they're defined in C or C++ because I don't know how they're
>>> technically defined in C or C++.
>>
>> "scope" and "lifetime" are rather critical terms in most programming
>> languages, and you must learn to understand them properly to use a
>> language. It is certainly not possible to create a consistent and
>> workable programming language without understanding the concepts, and
>> you might as well get the terms right too.
>>
>> "scope" concerns names and identifiers - something is "in scope" if you
>> can refer to the name, and "out of scope" if you cannot. "lifetime"
>> concerns objects - their lifetime begins logically when they are created
>> or initialised (and in C++, a constructor is called), and logically ends
>> when they are destroyed (and in C++, a destructor may be called). I
>> write "logically" here, because compilers are free to re-arrange the
>> actual generated code as long as the logical effect is correct.
>>
>> Scope and lifetime often go hand-in-hand - this is true for automatic
>> (stack) variables and temporaries. But they can be different. For
>> example, file-level variables have program lifetimes and global scope.
>> File-level statics have program lifetimes and file-level scope.
>> Function local statics have program lifetimes and function-local scope
>> (or block scope within a function). Objects created on a heap and
>> returned outside the block in which they were allocated, have longer
>> lifetimes than scope.
>>
>> In the case of your equivalent code, the temporaries tw1, tw2 and tw3
>> are pointers whose scope and lifetimes are the same. The AWhatever
>> objects have lifetimes stretching from when they are created by "new",
>> until they are destroyed by "delete". But these objects have no scope -
>> they have no names. Only the pointers to the objects have scope.
>>
>>
>>> So... here goes:
>>>
>>> Internally, CAlive does this:
>>>
>>> // AWhatever w;
>>> // something(w("1"), w("2"), w("3"));
>>>
>>> ||||||||||
>>> ||| Equivalent of:
>>> ||
>>> || AWhatever* tw1 = new AWhatever("1");
>>> || AWhatever* tw2 = new AWhatever("2");
>>> || AWhatever* tw3 = new AWhatever("3"):
>>> ||
>>> || something(tw1, tw2, tw3);
>>> ||
>>> || delete tw1;
>>> || delete tw2;
>>> || delete tw3;
>>> ||
>>> ||||||
>>>
>>> // The names tw1, tw2, tw3 do not exist, and their instances do not
>>> // exist. The tw1, tw2, and tw3 "slots" on the stack still exist,
>>> // but they are out of scope (which, to me, means they are not longer
>>> // viable entities, as whatever their destructors did is now done,
>>> // only the allocated space for their static data members exist.
>>> // If later code reused additional w("..") instances, those twN slots
>>> // would be re-used, and the maximum number of twN slots allocated
>>> // relates to the maximum number of concurrent instance uses found in
>>> // source code.
>>
>>
>> In C++, if you write:
>>
>> something(AWhatever("1"), AWhatever("2"), AWhatever("3"));
>>
>> it is roughly equivalent to:
>>
>> {
>> // The order of these is not specified
>> AWhatever tw1("1");
>> AWhatever tw2("2");
>> AWhatever tw3("3");
>>
>> something(tw1, tw2, tw3);
>>
>> // The tw1, tw2, tw3 go out of scope and are destructed
>> // in reverse creation order
>> }
>>
>> In other words, you already get the temporary nature of the objects in C++.
>>
>> Are you /sure/ that in CAlive, the temporary objects are constructed on
>> the heap (with new/delete) rather than the stack, as they are in C++?
>> Certainly stack allocation is a better choice in most cases, as it is
>> far more efficient.
>
> They are on the stack. I use lnew and new to determine where runtime-
> allocated classes, structs, and angels are allocated.
Then why bother with all the extra pointers?
>
>> And in C++, the destruction order is guaranteed to be the reverse of the
>> construction order. Is that not also the case in CAlive?
>
> Not today. If that's a requirement in C++ then I can make it be that
> way. I had planned on them being released in the order they were
> allocated. As such, I'll probably make that a compiler option.
Controlled, guaranteed reverse construction order for destructors is
absolutely crucial to RAII, which is a cornerstone of C++. It means you
can wrap your resource acquisition in class constructors, and their
release in class destructors, and know /exactly/ how and when they are
acquired and released in code.
(Of course, a compiler can re-arrange destructors if there is no logical
difference, just like for any other code.)
>
>>> -----
>>> Oh, and CAlive also introduces the || whitespace, and the ||| line comment,
>>> allowing for visual groupings like the above example.
>>>
>>
>> Now I /know/ you are joking. What is wrong with using spaces for white
>> space? And what insanity possessed you to make long lists of bar
>> characters, where even numbers means white space and odd numbers mean
>> comments?
>
> The grouped appearance of text above answers your question. It is
> obvious to the eye at a glance that that block of code is related.
White space does that fine too. And a bit of syntax highlighting, such
as italics or a different colour for comments, makes it even easier.
> In addition, within the debugger, it allows you to do a special kind
> of single-step debugging, called a single-group-step, allowing you
> to step over concepts in your code, and not just mechanical lines.
>
Other debuggers do that fine today - the grouping is called "functions".
Another option is "run to line", or putting breakpoints at steps in the
code.
You might like to introduce a kind of breakpoint and stepping so that a
step-breakpoint is only enabled for breaking if you are doing
group-stepping - then the user can easily add or remove such
step-breakpoints as needed, without changing the source code. That
would be a useful debugging feature, I think.
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
CAlive special use instance class, called an angel "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-10-29 18:18 -0700
Re: CAlive special use instance class, called an angel "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-10-29 18:23 -0700
Re: CAlive special use instance class, called an angel Ian Collins <ian-news@hotmail.com> - 2015-10-30 14:27 +1300
Re: CAlive special use instance class, called an angel "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-10-29 19:18 -0700
Re: CAlive special use instance class, called an angel Philip Lantz <prl@canterey.us> - 2015-10-29 22:29 -0700
Re: CAlive special use instance class, called an angel Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-10-29 22:53 -0700
Re: CAlive special use instance class, called an angel gazelle@shell.xmission.com (Kenny McCormack) - 2015-10-30 08:40 +0000
Re: CAlive special use instance class, called an angel Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-10-30 01:49 -0700
Re: CAlive special use instance class, called an angel Richard Heathfield <rjh@cpax.org.uk> - 2015-10-30 09:15 +0000
Re: CAlive special use instance class, called an angel "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-10-30 05:37 -0700
Re: CAlive special use instance class, called an angel David Brown <david.brown@hesbynett.no> - 2015-10-30 14:25 +0100
Re: CAlive special use instance class, called an angel "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-10-30 06:35 -0700
Re: CAlive special use instance class, called an angel David Brown <david.brown@hesbynett.no> - 2015-10-30 16:34 +0100
Re: CAlive special use instance class, called an angel "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-10-30 08:44 -0700
Re: CAlive special use instance class, called an angel Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-10-30 13:32 +0000
Re: CAlive special use instance class, called an angel "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-10-30 05:34 -0700
Re: CAlive special use instance class, called an angel gazelle@shell.xmission.com (Kenny McCormack) - 2015-10-30 13:13 +0000
Re: CAlive special use instance class, called an angel "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-10-30 06:25 -0700
Re: CAlive special use instance class, called an angel Ian Collins <ian-news@hotmail.com> - 2015-10-31 11:03 +1300
Re: CAlive special use instance class, called an angel "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-10-30 15:17 -0700
Re: CAlive special use instance class, called an angel Ian Collins <ian-news@hotmail.com> - 2015-10-31 16:55 +1300
Re: CAlive special use instance class, called an angel "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-10-30 21:13 -0700
Re: CAlive special use instance class, called an angel "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-10-30 21:36 -0700
Re: CAlive special use instance class, called an angel Ian Collins <ian-news@hotmail.com> - 2015-10-31 17:44 +1300
Re: CAlive special use instance class, called an angel "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-10-30 21:53 -0700
Re: CAlive special use instance class, called an angel "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-10-30 21:57 -0700
Re: CAlive special use instance class, called an angel Ian Collins <ian-news@hotmail.com> - 2015-10-31 22:16 +1300
Re: CAlive special use instance class, called an angel "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-10-31 09:50 -0700
Re: CAlive special use instance class, called an angel Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-10-31 01:52 -0700
Re: CAlive special use instance class, called an angel Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-10-30 22:44 +0000
Re: CAlive special use instance class, called an angel "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-10-30 16:14 -0700
Re: CAlive special use instance class, called an angel Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-10-31 01:03 +0000
Re: CAlive special use instance class, called an angel "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-10-30 19:14 -0700
Re: CAlive special use instance class, called an angel Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-10-31 11:56 +0000
Re: CAlive special use instance class, called an angel "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-10-31 09:55 -0700
Re: CAlive special use instance class, called an angel Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-10-31 20:17 +0000
Re: CAlive special use instance class, called an angel "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-10-31 14:27 -0700
Re: CAlive special use instance class, called an angel Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-10-31 22:38 +0000
Re: CAlive special use instance class, called an angel Richard Damon <Richard@Damon-Family.org> - 2015-10-31 10:44 -0400
Re: CAlive special use instance class, called an angel Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-10-31 12:16 -0700
Re: CAlive special use instance class, called an angel Ian Collins <ian-news@hotmail.com> - 2015-10-31 13:13 +1300
Re: CAlive special use instance class, called an angel James Kuyper <jameskuyper@verizon.net> - 2015-10-30 22:17 -0400
Re: CAlive special use instance class, called an angel James Kuyper <jameskuyper@verizon.net> - 2015-10-30 22:31 -0400
Re: CAlive special use instance class, called an angel Philip Lantz <prl@canterey.us> - 2015-10-30 01:42 -0700
Re: CAlive special use instance class, called an angel Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-10-30 09:38 +0000
Re: CAlive special use instance class, called an angel "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-10-30 04:35 -0700
Re: CAlive special use instance class, called an angel David Brown <david.brown@hesbynett.no> - 2015-10-30 14:10 +0100
Re: CAlive special use instance class, called an angel "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-10-30 06:21 -0700
Re: CAlive special use instance class, called an angel David Brown <david.brown@hesbynett.no> - 2015-10-30 16:43 +0100
Re: CAlive special use instance class, called an angel "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-10-30 08:55 -0700
Re: CAlive special use instance class, called an angel Ian Collins <ian-news@hotmail.com> - 2015-10-31 11:09 +1300
Re: CAlive special use instance class, called an angel "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-10-30 15:19 -0700
Re: CAlive special use instance class, called an angel David Brown <david.brown@hesbynett.no> - 2015-11-01 00:47 +0100
Re: CAlive special use instance class, called an angel "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-10-31 17:24 -0700
Re: CAlive special use instance class, called an angel David Brown <david.brown@hesbynett.no> - 2015-11-01 23:39 +0100
Re: CAlive special use instance class, called an angel "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-11-01 16:50 -0800
Re: CAlive special use instance class, called an angel Philip Lantz <prl@canterey.us> - 2015-11-01 23:22 -0800
Re: CAlive special use instance class, called an angel Bartc <bc@freeuk.com> - 2015-11-02 13:54 +0000
Re: CAlive special use instance class, called an angel "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-11-02 06:23 -0800
Re: CAlive special use instance class, called an angel supercat@casperkitty.com - 2015-11-01 18:46 -0800
Re: CAlive special use instance class, called an angel Bartc <bc@freeuk.com> - 2015-10-30 13:55 +0000
Re: CAlive special use instance class, called an angel David Brown <david.brown@hesbynett.no> - 2015-10-30 10:16 +0100
Re: CAlive special use instance class, called an angel "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-10-30 05:39 -0700
Re: CAlive special use instance class, called an angel David Brown <david.brown@hesbynett.no> - 2015-10-30 14:38 +0100
Re: CAlive special use instance class, called an angel "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-10-30 06:59 -0700
Re: CAlive special use instance class, called an angel Bartc <bc@freeuk.com> - 2015-10-30 14:41 +0000
Re: CAlive special use instance class, called an angel "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-10-30 08:31 -0700
Re: CAlive special use instance class, called an angel "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-10-30 08:38 -0700
Re: CAlive special use instance class, called an angel asetofsymbols@gmail.com - 2015-10-30 08:39 -0700
Re: CAlive special use instance class, called an angel supercat@casperkitty.com - 2015-10-30 15:20 -0700
Re: CAlive special use instance class, called an angel David Brown <david.brown@hesbynett.no> - 2015-10-30 16:48 +0100
Re: CAlive special use instance class, called an angel "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-10-30 09:07 -0700
Re: CAlive special use instance class, called an angel David Brown <david.brown@hesbynett.no> - 2015-11-01 14:53 +0100
Re: CAlive special use instance class, called an angel Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-11-01 06:12 -0800
Re: CAlive special use instance class, called an angel Bartc <bc@freeuk.com> - 2015-11-02 14:16 +0000
Re: CAlive special use instance class, called an angel "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-11-01 06:25 -0800
CLC as a dating site (Was: CAlive special use instance class, called an angel) gazelle@shell.xmission.com (Kenny McCormack) - 2015-11-01 14:33 +0000
Re: CLC as a dating site (Was: CAlive special use instance class, called an angel) "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-11-01 06:45 -0800
Re: CAlive special use instance class, called an angel "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-11-01 07:53 -0800
Using CLC for crowdsourcing (Was: CAlive special use instance class, called an angel) gazelle@shell.xmission.com (Kenny McCormack) - 2015-11-01 15:56 +0000
csiph-web