Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c++ > #78998 > unrolled thread

No, C is not a simple language

Started byJuha Nieminen <nospam@thanks.invalid>
First post2021-04-17 05:56 +0000
Last post2021-04-26 08:49 +0000
Articles 20 on this page of 143 — 32 participants

Back to article view | Back to comp.lang.c++


Contents

  No, C is not a simple language Juha Nieminen <nospam@thanks.invalid> - 2021-04-17 05:56 +0000
    Re: No, C is not a simple language Christian Gollwitzer <auriocus@gmx.de> - 2021-04-17 08:42 +0200
    Re: No, C is not a simple language wij <wyniijj@gmail.com> - 2021-04-16 23:49 -0700
      Re: No, C is not a simple language Juha Nieminen <nospam@thanks.invalid> - 2021-04-18 16:25 +0000
        Re: No, C is not a simple language wij <wyniijj@gmail.com> - 2021-04-19 06:43 -0700
          Re: No, C is not a simple language Bo Persson <bo@bo-persson.se> - 2021-04-19 20:19 +0200
            Re: No, C is not a simple language wij <wyniijj@gmail.com> - 2021-04-19 13:04 -0700
          Re: No, C is not a simple language Juha Nieminen <nospam@thanks.invalid> - 2021-04-20 04:02 +0000
            Re: No, C is not a simple language Chris Vine <chris@cvine--nospam--.freeserve.co.uk> - 2021-04-21 18:30 +0100
              Re: No, C is not a simple language scott@slp53.sl.home (Scott Lurndal) - 2021-04-21 18:33 +0000
                Re: No, C is not a simple language Chris Vine <chris@cvine--nospam--.freeserve.co.uk> - 2021-04-21 21:14 +0100
                  Re: No, C is not a simple language wij <wyniijj@gmail.com> - 2021-04-21 22:38 -0700
                Re: No, C is not a simple language "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-04-21 15:37 -0700
                Re: No, C is not a simple language wij <wyniijj@gmail.com> - 2021-04-22 10:14 -0700
              Re: No, C is not a simple language Juha Nieminen <nospam@thanks.invalid> - 2021-04-22 08:45 +0000
                Re: No, C is not a simple language "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-04-22 01:48 -0700
                Re: No, C is not a simple language "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-04-22 01:51 -0700
                  Re: No, C is not a simple language MrSpook_l0xjKyc@b3jtfv70fxckzmak.net - 2021-04-22 09:40 +0000
                    Re: No, C is not a simple language "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-04-22 12:38 -0700
                    Re: No, C is not a simple language Juha Nieminen <nospam@thanks.invalid> - 2021-04-23 07:12 +0000
                      Re: No, C is not a simple language MrSpook_l0c6dv@66h4_0ccefudc0u8w.gov - 2021-04-23 09:14 +0000
                        Re: No, C is not a simple language Juha Nieminen <nospam@thanks.invalid> - 2021-04-26 04:47 +0000
                          Re: No, C is not a simple language MrSpook_531q@dr4t0dkj168m4ml.tv - 2021-04-26 08:13 +0000
                            Re: No, C is not a simple language "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-04-26 01:22 -0700
                              Re: No, C is not a simple language MrSpook_9p05k3C69@xr34.gov.uk - 2021-04-26 09:03 +0000
                                Re: No, C is not a simple language "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-04-26 02:17 -0700
                                  Re: No, C is not a simple language MrSpook_i4zl8mHy@0tr9r.eu - 2021-04-26 09:23 +0000
                                Re: No, C is not a simple language "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-04-26 02:22 -0700
                            Re: No, C is not a simple language Juha Nieminen <nospam@thanks.invalid> - 2021-04-26 09:37 +0000
                              Re: No, C is not a simple language MrSpook_gbzt63zc@83jpfr9ry9f55a.tv - 2021-04-26 10:22 +0000
                                Re: No, C is not a simple language Bo Persson <bo@bo-persson.se> - 2021-04-26 13:05 +0200
                                Re: No, C is not a simple language David Brown <david.brown@hesbynett.no> - 2021-04-26 13:10 +0200
                            Re: No, C is not a simple language Paavo Helde <myfirstname@osa.pri.ee> - 2021-04-26 14:38 +0300
                              Re: No, C is not a simple language MrSpook_mD_r@g72w8ixztm106rprqnby.tv - 2021-04-26 13:49 +0000
                Re: No, C is not a simple language MrSpook_lxrj1vfhmw@qdgb.org - 2021-04-22 09:37 +0000
                  Re: No, C is not a simple language Ben Bacarisse <ben.usenet@bsb.me.uk> - 2021-04-22 11:32 +0100
                    Re: No, C is not a simple language MrSpook_f0mj9r@d6g.gov.uk - 2021-04-22 10:38 +0000
                      Re: No, C is not a simple language Ben Bacarisse <ben.usenet@bsb.me.uk> - 2021-04-22 12:35 +0100
                Re: No, C is not a simple language Chris Vine <chris@cvine--nospam--.freeserve.co.uk> - 2021-04-22 13:35 +0100
                  Re: No, C is not a simple language Juha Nieminen <nospam@thanks.invalid> - 2021-04-23 07:20 +0000
                    Re: No, C is not a simple language Chris Vine <chris@cvine--nospam--.freeserve.co.uk> - 2021-04-23 11:01 +0100
                      Re: No, C is not a simple language Paavo Helde <myfirstname@osa.pri.ee> - 2021-04-23 15:44 +0300
                        Re: No, C is not a simple language Chris Vine <chris@cvine--nospam--.freeserve.co.uk> - 2021-04-23 17:52 +0100
                          Re: No, C is not a simple language Juha Nieminen <nospam@thanks.invalid> - 2021-04-26 04:55 +0000
                            Re: No, C is not a simple language Chris Vine <chris@cvine--nospam--.freeserve.co.uk> - 2021-04-26 22:16 +0100
                Re: No, C is not a simple language Manfred <noname@add.invalid> - 2021-04-22 16:30 +0200
                  Re: No, C is not a simple language Juha Nieminen <nospam@thanks.invalid> - 2021-04-23 07:32 +0000
                    Re: No, C is not a simple language Manfred <noname@add.invalid> - 2021-04-23 20:35 +0200
                      Re: No, C is not a simple language Juha Nieminen <nospam@thanks.invalid> - 2021-04-26 05:01 +0000
          Re: No, C is not a simple language Juha Nieminen <nospam@thanks.invalid> - 2021-04-20 04:56 +0000
            Re: No, C is not a simple language wij <wyniijj@gmail.com> - 2021-04-20 05:22 -0700
    Re: No, C is not a simple language MrSpook_wb@g9b2a_ex9aicgvs04.net - 2021-04-17 10:27 +0000
      Re: No, C is not a simple language Juha Nieminen <nospam@thanks.invalid> - 2021-04-18 16:30 +0000
        Re: No, C is not a simple language MrSpook_wyzaq1485z@solbi8e3oaumg9.gov.uk - 2021-04-19 07:42 +0000
    Re: No, C is not a simple language jacobnavia <jacob@jacob.remcomp.fr> - 2021-04-17 17:43 +0200
      Re: No, C is not a simple language Juha Nieminen <nospam@thanks.invalid> - 2021-04-18 16:39 +0000
        Re: No, C is not a simple language jacobnavia <jacob@jacob.remcomp.fr> - 2021-04-18 20:48 +0200
    Re: No, C is not a simple language Manfred <noname@add.invalid> - 2021-04-17 19:12 +0200
      Re: No, C is not a simple language Juha Nieminen <nospam@thanks.invalid> - 2021-04-18 16:46 +0000
        Re: No, C is not a simple language Manfred <noname@add.invalid> - 2021-04-18 20:30 +0200
          Re: No, C is not a simple language Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2021-04-18 12:46 -0700
            Re: No, C is not a simple language Manfred <noname@add.invalid> - 2021-04-18 22:53 +0200
          Re: No, C is not a simple language Juha Nieminen <nospam@thanks.invalid> - 2021-04-19 07:18 +0000
            Re: No, C is not a simple language Manfred <noname@add.invalid> - 2021-04-19 17:15 +0200
              Re: No, C is not a simple language Juha Nieminen <nospam@thanks.invalid> - 2021-04-20 04:05 +0000
                Re: No, C is not a simple language Manfred <noname@add.invalid> - 2021-04-20 18:27 +0200
                  Re: No, C is not a simple language Juha Nieminen <nospam@thanks.invalid> - 2021-04-20 16:41 +0000
                    Re: No, C is not a simple language jacobnavia <jacob@jacob.remcomp.fr> - 2021-04-20 19:44 +0200
                      Re: No, C is not a simple language Kaz Kylheku <563-365-8930@kylheku.com> - 2021-04-20 18:30 +0000
                        Re: No, C is not a simple language jacobnavia <jacob@jacob.remcomp.fr> - 2021-04-20 20:47 +0200
                          Re: No, C is not a simple language "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-04-20 13:29 -0700
                          Re: No, C is not a simple language Juha Nieminen <nospam@thanks.invalid> - 2021-04-21 04:37 +0000
                            Re: No, C is not a simple language wij <wyniijj@gmail.com> - 2021-04-20 22:02 -0700
                              Re: No, C is not a simple language wij <wyniijj@gmail.com> - 2021-04-20 22:35 -0700
                            Re: No, C is not a simple language "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-04-21 15:26 -0700
                              Re: No, C is not a simple language wij <wyniijj@gmail.com> - 2021-04-21 22:06 -0700
                                Re: No, C is not a simple language Juha Nieminen <nospam@thanks.invalid> - 2021-04-22 08:52 +0000
                                  Re: No, C is not a simple language wij <wyniijj@gmail.com> - 2021-04-22 09:41 -0700
                                    Re: No, C is not a simple language Juha Nieminen <nospam@thanks.invalid> - 2021-04-23 07:34 +0000
                                      Re: No, C is not a simple language wij <wyniijj@gmail.com> - 2021-04-23 04:58 -0700
                                        Re: No, C is not a simple language Juha Nieminen <nospam@thanks.invalid> - 2021-04-26 05:04 +0000
                                        Re: No, C is not a simple language Paavo Helde <myfirstname@osa.pri.ee> - 2021-04-26 09:41 +0300
                                        Re: No, C is not a simple language James Kuyper <jameskuyper@alumni.caltech.edu> - 2021-04-26 10:25 -0400
                                          Re: No, C is not a simple language wij <wyniijj@gmail.com> - 2021-04-26 12:07 -0700
                                            Re: No, C is not a simple language Christian Gollwitzer <auriocus@gmx.de> - 2021-04-28 08:03 +0200
                                Re: No, C is not a simple language wij <wyniijj@gmail.com> - 2021-04-22 09:26 -0700
                      Re: No, C is not a simple language Richard Damon <Richard@Damon-Family.org> - 2021-04-20 14:46 -0400
                        Re: No, C is not a simple language Kaz Kylheku <563-365-8930@kylheku.com> - 2021-04-20 20:18 +0000
                      Re: No, C is not a simple language "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-04-20 13:19 -0700
                        Re: No, C is not a simple language Kaz Kylheku <563-365-8930@kylheku.com> - 2021-04-20 20:29 +0000
                          Re: No, C is not a simple language "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-04-20 13:39 -0700
                            Re: No, C is not a simple language "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-04-20 14:29 -0700
                      Re: No, C is not a simple language Ian Collins <ian-news@hotmail.com> - 2021-04-21 08:56 +1200
                      Re: No, C is not a simple language "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-04-20 14:07 -0700
                        Re: No, C is not a simple language jacobnavia <jacob@jacob.remcomp.fr> - 2021-04-23 12:10 +0200
                          Re: No, C is not a simple language wij <wyniijj@gmail.com> - 2021-04-23 04:10 -0700
                            Re: No, C is not a simple language "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-04-28 00:32 -0700
                              Re: No, C is not a simple language wij <wyniijj@gmail.com> - 2021-04-28 11:04 -0700
                          Re: No, C is not a simple language "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-04-23 12:37 -0700
                            Re: No, C is not a simple language "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-04-23 12:38 -0700
                            Re: No, C is not a simple language "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-04-23 12:43 -0700
                              Re: No, C is not a simple language jacobnavia <jacob@jacob.remcomp.fr> - 2021-04-23 22:38 +0200
                                Re: No, C is not a simple language "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-04-23 13:44 -0700
                                Re: No, C is not a simple language Ian Collins <ian-news@hotmail.com> - 2021-04-24 10:56 +1200
                                  Re: No, C is not a simple language "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-04-23 16:09 -0700
                              Re: No, C is not a simple language Kaz Kylheku <563-365-8930@kylheku.com> - 2021-04-24 03:51 +0000
                      Re: No, C is not a simple language Robert Latest <boblatest@yahoo.com> - 2021-04-26 09:24 +0000
                      Re: No, C is not a simple language Robert Latest <boblatest@yahoo.com> - 2021-04-26 09:27 +0000
                    Re: No, C is not a simple language "Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com> - 2021-04-20 19:53 +0200
                    Re: No, C is not a simple language Robert Latest <boblatest@yahoo.com> - 2021-04-26 09:02 +0000
                      Re: No, C is not a simple language Juha Nieminen <nospam@thanks.invalid> - 2021-04-26 09:43 +0000
                        Re: No, C is not a simple language Robert Latest <boblatest@yahoo.com> - 2021-04-26 10:35 +0000
                          Re: No, C is not a simple language Juha Nieminen <nospam@thanks.invalid> - 2021-04-26 13:08 +0000
                            Re: No, C is not a simple language Richard Damon <Richard@Damon-Family.org> - 2021-04-26 09:30 -0400
                            Re: No, C is not a simple language Robert Latest <boblatest@yahoo.com> - 2021-04-26 14:15 +0000
                              Re: No, C is not a simple language Juha Nieminen <nospam@thanks.invalid> - 2021-04-27 04:37 +0000
                                Re: No, C is not a simple language Robert Latest <boblatest@yahoo.com> - 2021-04-27 07:22 +0000
      Re: No, C is not a simple language "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-04-19 21:42 -0700
        Re: No, C is not a simple language "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-04-22 00:26 -0700
      Re: No, C is not a simple language "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-04-28 00:02 -0700
    Re: No, C is not a simple language Bonita Montero <Bonita.Montero@gmail.com> - 2021-04-17 21:36 +0200
      Re: No, C is not a simple language Juha Nieminen <nospam@thanks.invalid> - 2021-04-18 16:49 +0000
        Re: No, C is not a simple language Bonita Montero <Bonita.Montero@gmail.com> - 2021-04-18 23:31 +0200
        Re: No, C is not a simple language Ben Bacarisse <ben.usenet@bsb.me.uk> - 2021-04-19 01:36 +0100
          Re: No, C is not a simple language Juha Nieminen <nospam@thanks.invalid> - 2021-04-19 07:19 +0000
            Re: No, C is not a simple language Ben Bacarisse <ben.usenet@bsb.me.uk> - 2021-04-19 11:36 +0100
            Re: No, C is not a simple language Bonita Montero <Bonita.Montero@gmail.com> - 2021-04-19 16:54 +0200
    Re: No, C is not a simple language Paavo Helde <myfirstname@osa.pri.ee> - 2021-04-18 00:48 +0300
    Re: No, C is not a simple language (PLO) olcott <NoOne@NoWhere.com> - 2021-04-18 16:04 -0500
      Re: No, C is not a simple language (PLO) Juha Nieminen <nospam@thanks.invalid> - 2021-04-19 07:22 +0000
        Re: No, C is not a simple language (PLO) olcott <NoOne@NoWhere.com> - 2021-04-19 09:50 -0500
          Re: No, C is not a simple language (PLO) jacobnavia <jacob@jacob.remcomp.fr> - 2021-04-19 19:05 +0200
            Re: No, C is not a simple language (PLO) olcott <NoOne@NoWhere.com> - 2021-04-19 12:23 -0500
            Re: No, C is not a simple language (PLO) scott@slp53.sl.home (Scott Lurndal) - 2021-04-19 18:02 +0000
            Re: No, C is not a simple language (PLO) jacobnavia <jacob@jacob.remcomp.fr> - 2021-04-19 21:03 +0200
              Re: No, C is not a simple language (PLO) olcott <NoOne@NoWhere.com> - 2021-04-19 15:14 -0500
            Re: No, C is not a simple language (PLO) "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-04-19 17:16 -0700
              Re: No, C is not a simple language (PLO) jacobnavia <jacob@jacob.remcomp.fr> - 2021-04-20 07:32 +0200
                Re: No, C is not a simple language (PLO) "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-04-19 23:47 -0700
            Re: No, C is not a simple language (PLO) Juha Nieminen <nospam@thanks.invalid> - 2021-04-20 10:29 +0000
              Re: No, C is not a simple language (PLO) jacobnavia <jacob@jacob.remcomp.fr> - 2021-04-20 14:14 +0200
                Re: No, C is not a simple language (PLO) Juha Nieminen <nospam@thanks.invalid> - 2021-04-20 16:44 +0000
    Re: No, C is not a simple language Robert Latest <boblatest@yahoo.com> - 2021-04-26 08:49 +0000

Page 6 of 8 — ← Prev page 1 2 3 4 5 [6] 7 8  Next page →


#79209

From"Chris M. Thomasson" <chris.m.thomasson.1@gmail.com>
Date2021-04-23 12:43 -0700
Message-ID<s5v81c$1ess$3@gioia.aioe.org>
In reply to#79207
On 4/23/2021 12:37 PM, Chris M. Thomasson wrote:
> On 4/23/2021 3:10 AM, jacobnavia wrote:
>> Le 20/04/2021 à 23:07, Chris M. Thomasson a écrit :
>>
>>>
>>> For some reason, anytime I hear somebody go, just use a GC... Well, 
>>> it makes think of this song:
>>>
>>> https://youtu.be/WJabPYimznY
>>>
>>> Or the following scene in Disney's Dragonslayer from 1981:
>>>
>>> https://youtu.be/TJRaLnLDMWg
>>
>> Great arguments!
>>
>> Technically sound, I am convinced now...
>>
>>
>> ... that you have nothing to say
> 
> Have you ever had to deal with GC issues? I have... Unfortunately, some 
> people seem to think that a full blown GC is okay to use for reclaiming 
> memory in lock-free algorithms. It works, but can become a massive, 
> nasty, unpredictable bottleneck. Only then do they complain. I warned 
> some of them...
> 
> https://youtu.be/XcxKIJTb3Hg
> 

I used to cringe when I would see code that would allocate nodes all 
over the place, and never free them. Sometimes they would allocate nodes 
in loops! They would say, ahhh, that's for the GC. WOW!

[toc] | [prev] | [next] | [standalone]


#79216

Fromjacobnavia <jacob@jacob.remcomp.fr>
Date2021-04-23 22:38 +0200
Message-ID<s5vb7n$n3o$1@dont-email.me>
In reply to#79209
Le 23/04/2021 à 21:43, Chris M. Thomasson a écrit :
> On 4/23/2021 12:37 PM, Chris M. Thomasson wrote:
>> On 4/23/2021 3:10 AM, jacobnavia wrote:
>>> Le 20/04/2021 à 23:07, Chris M. Thomasson a écrit :
>>>
>>>>
>>>> For some reason, anytime I hear somebody go, just use a GC... Well, 
>>>> it makes think of this song:
>>>>
>>>> https://youtu.be/WJabPYimznY
>>>>
>>>> Or the following scene in Disney's Dragonslayer from 1981:
>>>>
>>>> https://youtu.be/TJRaLnLDMWg
>>>
>>> Great arguments!
>>>
>>> Technically sound, I am convinced now...
>>>
>>>
>>> ... that you have nothing to say
>>
>> Have you ever had to deal with GC issues? I have... Unfortunately, 
>> some people seem to think that a full blown GC is okay to use for 
>> reclaiming memory in lock-free algorithms. It works, but can become a 
>> massive, nasty, unpredictable bottleneck. Only then do they complain. 
>> I warned some of them...
>>
>> https://youtu.be/XcxKIJTb3Hg
>>
> 
> I used to cringe when I would see code that would allocate nodes all 
> over the place, and never free them. Sometimes they would allocate nodes 
> in loops! They would say, ahhh, that's for the GC. WOW!

Thanks for your reply, at least there are some real arguments and not 
that stupid links.

As You seem to know, the GC can be misused, as anything can be misused. 
The GC is great in certain situations, not in others.

I used it in my debugger. It was a GREAT relief to be able to allocate a 
piece of memory in the user interface, pass it to the debugger without 
caring about when and by whom it should be freed. Obviously the memory 
pieces being passed were user inputs,names of variables to be 
displayed,and many other SHORT pieces of memory. The other solution 
would bve to redesign the debugger and use a thread proof memory 
allocator that would keep the accounting,or other massive development 
projects.

By using the GC I was able to concentrate ion the debugger itself, 
already a very complex program, and forget about the memory accounting 
chors.

What is nice of the GC is the SIMPLIFICATION that provides. Of course it 
can be abused, as everything.

Knives? Wondefful for cutting bread. But they can cut your fingers too.

USE WITH CARE!

GC is no differeent

[toc] | [prev] | [next] | [standalone]


#79219

From"Chris M. Thomasson" <chris.m.thomasson.1@gmail.com>
Date2021-04-23 13:44 -0700
Message-ID<s5vbjk$18ra$1@gioia.aioe.org>
In reply to#79216
On 4/23/2021 1:38 PM, jacobnavia wrote:
> Le 23/04/2021 à 21:43, Chris M. Thomasson a écrit :
>> On 4/23/2021 12:37 PM, Chris M. Thomasson wrote:
>>> On 4/23/2021 3:10 AM, jacobnavia wrote:
>>>> Le 20/04/2021 à 23:07, Chris M. Thomasson a écrit :
>>>>
>>>>>
>>>>> For some reason, anytime I hear somebody go, just use a GC... Well, 
>>>>> it makes think of this song:
>>>>>
>>>>> https://youtu.be/WJabPYimznY
>>>>>
>>>>> Or the following scene in Disney's Dragonslayer from 1981:
>>>>>
>>>>> https://youtu.be/TJRaLnLDMWg
>>>>
>>>> Great arguments!
>>>>
>>>> Technically sound, I am convinced now...
>>>>
>>>>
>>>> ... that you have nothing to say
>>>
>>> Have you ever had to deal with GC issues? I have... Unfortunately, 
>>> some people seem to think that a full blown GC is okay to use for 
>>> reclaiming memory in lock-free algorithms. It works, but can become a 
>>> massive, nasty, unpredictable bottleneck. Only then do they complain. 
>>> I warned some of them...
>>>
>>> https://youtu.be/XcxKIJTb3Hg
>>>
>>
>> I used to cringe when I would see code that would allocate nodes all 
>> over the place, and never free them. Sometimes they would allocate 
>> nodes in loops! They would say, ahhh, that's for the GC. WOW!
> 
> Thanks for your reply, at least there are some real arguments and not 
> that stupid links.
> 
> As You seem to know, the GC can be misused, as anything can be misused. 
> The GC is great in certain situations, not in others.

Okay, that is fair enough. From my experience, GC it not okay to use in 
high pressure scenarios, under lots of load. It can cause all sorts of 
issues.


> I used it in my debugger. It was a GREAT relief to be able to allocate a 
> piece of memory in the user interface, pass it to the debugger without 
> caring about when and by whom it should be freed. Obviously the memory 
> pieces being passed were user inputs,names of variables to be 
> displayed,and many other SHORT pieces of memory. The other solution 
> would bve to redesign the debugger and use a thread proof memory 
> allocator that would keep the accounting,or other massive development 
> projects.
> 
> By using the GC I was able to concentrate ion the debugger itself, 
> already a very complex program, and forget about the memory accounting 
> chors.
> 
> What is nice of the GC is the SIMPLIFICATION that provides. Of course it 
> can be abused, as everything.
> 
> Knives? Wondefful for cutting bread. But they can cut your fingers too.
> 
> USE WITH CARE!
> 
> GC is no differeent

Just, try not to use a GC as a crutch: The way of all things. Btw, some 
people say C is too dangerous to use, GC or not... Its as if they want 
people to be forced to put corks on their forks to prevent themselves 
from hurting themselves.

https://youtu.be/SKDX-qJaJ08

lol.

[toc] | [prev] | [next] | [standalone]


#79231

FromIan Collins <ian-news@hotmail.com>
Date2021-04-24 10:56 +1200
Message-ID<ieh1kuFb7j0U1@mid.individual.net>
In reply to#79216
On 24/04/2021 08:38, jacobnavia wrote:
> 
> By using the GC I was able to concentrate ion the debugger itself,
> already a very complex program, and forget about the memory accounting
> chors.
> 
> What is nice of the GC is the SIMPLIFICATION that provides. Of course it
> can be abused, as everything.

We could use exactly the same argument for RAII and in the context of 
this thread, std::string.  We could also add deterministic behaviour as 
a significant advantage RAII has over GC, especially in the semi-real 
time embedded world where much of today's C and C++ is written.


> Knives? Wondefful for cutting bread. But they can cut your fingers too.
> 
> USE WITH CARE!
> 
> GC is no differeent


Very true.


GC can be a survivor when working with old, leaky, C code.  I have 
deployed it with long running services that would run out of memory and 
die.  It not only kept the thing running, but that particular library 
kept logs which could be used to find and fix the worst leaks.  I have 
yet to use abetter tool for this job.

-- 
Ian.

[toc] | [prev] | [next] | [standalone]


#79232

From"Chris M. Thomasson" <chris.m.thomasson.1@gmail.com>
Date2021-04-23 16:09 -0700
Message-ID<s5vk2g$jij$1@gioia.aioe.org>
In reply to#79231
On 4/23/2021 3:56 PM, Ian Collins wrote:
> On 24/04/2021 08:38, jacobnavia wrote:
>>
>> By using the GC I was able to concentrate ion the debugger itself,
>> already a very complex program, and forget about the memory accounting
>> chors.
>>
>> What is nice of the GC is the SIMPLIFICATION that provides. Of course it
>> can be abused, as everything.
> 
> We could use exactly the same argument for RAII and in the context of 
> this thread, std::string.  We could also add deterministic behaviour as 
> a significant advantage RAII has over GC, especially in the semi-real 
> time embedded world where much of today's C and C++ is written.
> 
> 
>> Knives? Wondefful for cutting bread. But they can cut your fingers too.
>>
>> USE WITH CARE!
>>
>> GC is no differeent
> 
> 
> Very true.
> 
> 
> GC can be a survivor when working with old, leaky, C code.  I have 
> deployed it with long running services that would run out of memory and 
> die.  It not only kept the thing running, but that particular library 
> kept logs which could be used to find and fix the worst leaks.  I have 
> yet to use abetter tool for this job.
> 

Yeah, I don't think I ever used GC for that, but it sure should help out 
indeed. Good one! :^)

I while back, have had to find a find a horrible race-condition that 
would sometimes miss a call to free. So, sometimes, under certain 
conditions, the memory could grow out of control. It was a bitch and a 
half to debug. Iirc, it was a strange reference counting error that 
would not allow some things to be destroyed, so they would just hang 
around...

I also remember debugging something that would hang up, from time to 
time. Iirc, the problem was that a mutex was not being unlocked under 
certain conditions. This was easier to fix than the previous one. The 
system would deadlock, and then I could go in and debug it in an actual 
deadlocked state.

[toc] | [prev] | [next] | [standalone]


#79235

FromKaz Kylheku <563-365-8930@kylheku.com>
Date2021-04-24 03:51 +0000
Message-ID<20210423204204.51@kylheku.com>
In reply to#79209
["Followup-To:" header set to comp.lang.c.]
On 2021-04-23, Chris M. Thomasson <chris.m.thomasson.1@gmail.com> wrote:
> On 4/23/2021 12:37 PM, Chris M. Thomasson wrote:
>> On 4/23/2021 3:10 AM, jacobnavia wrote:
>>> Le 20/04/2021 à 23:07, Chris M. Thomasson a écrit :
>>>
>>>>
>>>> For some reason, anytime I hear somebody go, just use a GC... Well, 
>>>> it makes think of this song:
>>>>
>>>> https://youtu.be/WJabPYimznY
>>>>
>>>> Or the following scene in Disney's Dragonslayer from 1981:
>>>>
>>>> https://youtu.be/TJRaLnLDMWg
>>>
>>> Great arguments!
>>>
>>> Technically sound, I am convinced now...
>>>
>>>
>>> ... that you have nothing to say
>> 
>> Have you ever had to deal with GC issues? I have... Unfortunately, some 
>> people seem to think that a full blown GC is okay to use for reclaiming 
>> memory in lock-free algorithms. It works, but can become a massive, 
>> nasty, unpredictable bottleneck. Only then do they complain. I warned 
>> some of them...
>> 
>> https://youtu.be/XcxKIJTb3Hg
>> 
>
> I used to cringe when I would see code that would allocate nodes all 
> over the place, and never free them. Sometimes they would allocate nodes 
> in loops! They would say, ahhh, that's for the GC. WOW!

Allocating a node in the loop such that it is unreachable is actually a
pretty easy situation for GC.

  (while true
    (cons x y))

The cons cell is allocated and immediately becomes unreachable.  Being
unreachable it means that when GC is triggered, it does not have to
traverse it.

Traversing the graph of reachable objects is a big expense.

It will have to sweep these cons cells to reclaim them. But that would
have to be done by explicit memory management also!

Sweeping can be a big expense in a naive mark-and-sweep allocator.
A generational garbage collector, though, makes the sweep cheaper.

A generational garbage collector will allocate these new cells into
a "nursery" of baby objects.

When a certain limit is reached, a generational GC pass is triggered.
The GC walks the object graph, but it avoids traversing across "mature"
objects; it looks at areas like the machine registers and stack, looking
only for baby objects.  It will not find any of these baby objects
because only the loop is creating them, and it loses track of each one.

Then comes the generational sweep phase. Unlike in a full GC pass,
the garbage collector only has to sweep through the nursery. The nursery
is chock full of these cons cells made in the body of the loop. None
of them were marked reachable, so they are deallocated.

This sweep pass does not have to look at any mature objects at all.

Basically, GC can be designed and tuned to deal with the pressure of a
fast allocation of temporary objects that soon become garbage.
Such cases arise in practical applications. For instance, macro
expansion in Lisp. Or string processing. Or calculations with numbers
that have to be boxed on the heap, like bignums and sometimes
floating-point values.

-- 
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal

[toc] | [prev] | [next] | [standalone]


#79279

FromRobert Latest <boblatest@yahoo.com>
Date2021-04-26 09:24 +0000
Message-ID<ienf7bFi7m1U9@mid.individual.net>
In reply to#79114
["Followup-To:" header set to comp.lang.c.]
jacobnavia wrote:
> Just have a constructotr and never free anything. Then link with Boehm's 
> GARBAGE COLLECTOR and be done with it!

Whan I find myself in a situation where explicitly freeing resources becomes
unwieldy I start thinking about using another language than C (which, like
i.e. Python, comes with garage collection).

If you're too lazy to use free(), you should also be too lazy to use malloc()
or to declare your variables. Better to use a language where you don't have to
do any of it.

-- 
robert

[toc] | [prev] | [next] | [standalone]


#79280

FromRobert Latest <boblatest@yahoo.com>
Date2021-04-26 09:27 +0000
Message-ID<ienfctFi7m1U10@mid.individual.net>
In reply to#79114
["Followup-To:" header set to comp.lang.c.]
jacobnavia wrote:
> I use an automatic car, no passing of gears. Recently I spoke with a 
> taxi driver... "Don't you get bored passing gears all day?"
>
> And he acknowledged: yes, My arm hurts at the end of the day. Maybe you 
> are right, should get an automatic...

The C-with-GC analogy would be to first buy a stick shift car and then
expensively retrofit it with an automatic transmiassion (probably voiding the
warranty in the process). Better to buy a car that already comes with automatic
transmission.

-- 
robert

[toc] | [prev] | [next] | [standalone]


#79115

From"Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com>
Date2021-04-20 19:53 +0200
Message-ID<s5n4e0$itg$1@dont-email.me>
In reply to#79112
On 20.04.2021 18:41, Juha Nieminen wrote:
> In comp.lang.c++ Manfred <noname@add.invalid> wrote:
>> Anything that happens behind the scenes and the compiler "does it for
>> you" does require knowledge by the programmer about something they don't
>> see and yet they must be aware of and know how it works.
>> And yes, they are intended to (and actually do) make life easier for the
>> programmer /after/ they master their mechanics, but a beginner's mistake
>> related with such hidden features is likely to lead to somewhat
>> shady/obscure bugs - i.e. hard for said beginner.
> 
> The problem with C is that anything that requires manual construction and
> destruction will "contaminate" (can't think of a better word) anything that
> uses that first thing, with the same requirements. All the way down.
> 
> If you have this kind of "string" object that requires manual construction
> and destruction, and you put it as a member of a struct, suddenly that
> struct "inherits" the same requirement. Use that struct in yet another
> struct and that, too, will "inherit" the same requirement.
> 
> Moreover, suppose you have a complex hierarchy of structs as members of
> other structs, no dynamic memory allocation in sight so far. Then you need
> to add dynamic memory allocation to one of the structs (that's being used
> as a member of other structs etc) and suddenly all that code breaks. If
> there are millions of lines of code using any of those structs that have
> now "inherited" the need for manual construction and destruction (even though
> they were never designed for that initially), you'll have to go and modify
> those millions of lines to follow suit.

Very good points.

In addition, what C++ provides as built-in language features, has to be 
supplied as 3d party library or DIY functionality in C.

That means that in C

* one can't leverage a single knowledge base, but must learn each
   support library that's needed for those C++ features, and
* the compiler can't be fine tuned to a particular implementation.



> The complexity can quickly grow exponentially.

Not sure about that though, but that it grows, yes.


> Not so in C++, if you design your structs/classes correctly. Even if some
> struct/class very deep in the dependency tree suddenly starts allocating
> memory dynamically, that doesn't matter. None of the other structs/classes
> that may be using it as their members need to be touched in any way. The
> struct/class automatically takes care of its own memory management. You
> don't need to go through the millions of lines of code to add support.
> 
>> On a different perspective, consider e.g. rvalue refs and "universal"
>> refs (in Meyers' terms) - they make a useful feature, but good luck
>> explaining it to said beginner.
> 
> I wouldn't teach function and array pointers as a first thing to a beginner.
> Likewise I wouldn't teach rvalue references as a first thing.

The "Accelerated C++" book by Andrew Koenig and Barbara Mooooooooo 
showed that the high level approach can really work for C++.

But I think that for these fundamental aspects of programming, if one 
desires to teach at a high level of abstraction then some other language 
will be better suited. I'm thinking C# (which I known from the "classic" 
C# days) or, say, Rust (which I don't know beyond "Hello, world!").

A nice feature of C++ is that it's /possible/ to teach programming in a 
mixed way, introducing the low level stuff but using containers, strings 
etc. It's sad that C++ still lacks standard 128-bit integers and ditto 
currency type; still lacks datetime type; still lacks a practically 
usable for beginners version of `std::ranges::views::iota` (I prefer to 
define things so one can write e.g. `for( const int i: zero_to( n ) )`; 
not to mention that the common /C++ implementations/ for Windows still 
lack support for UTF-8, both in console and GUI programs, so that 
learners can't even write a program that displays their non-English name 
in Windows without using 3rd party libraries or the Windows API.

That's just basic functionality.

Try motivating a leaner by coding up the (recursive) C curve in standard 
C++ only. Oh, no graphics. Oh well.

So, as I see it standard C++ in itself is not good for learners, but it 
can be good with the right 3rd party libraries. I guess you all know 
that I've been hobby-working on libraries to fill the mentioned data 
type and console i/o voids, and that I've found that it decidedly is a 
non-trivial design task (which may be part of the reason why such 
libraries don't already exists). And perhaps the good Mr. Fibble's 
Neo-something could help with the graphics and sound aspects.

- Alf

[toc] | [prev] | [next] | [standalone]


#79274

FromRobert Latest <boblatest@yahoo.com>
Date2021-04-26 09:02 +0000
Message-ID<iendscFi7m1U8@mid.individual.net>
In reply to#79112
["Followup-To:" header set to comp.lang.c.]
Juha Nieminen wrote:
> The problem with C is that anything that requires manual construction and
> destruction will "contaminate" (can't think of a better word) anything that
> uses that first thing, with the same requirements. All the way down.

Of course it does. If you insist on doing it in C, it's best to define
functions new_xxx and free_xxx for each type xxx, and make sure that free_yyy
is called from free_xxx if the xxx type contains dynamically allocated objects
of type yyy. It's really not hard, just requires a bit of typing, but it's a
tremendously helpful exercise especially for a beginner.

BTW if this concept is new or "The problem" for you, I don't believe you have
much experience with C.

> If you have this kind of "string" object that requires manual construction
> and destruction, and you put it as a member of a struct, suddenly that
> struct "inherits" the same requirement. Use that struct in yet another
> struct and that, too, will "inherit" the same requirement.


Trivially dealt with, see above.

> Moreover, suppose you have a complex hierarchy of structs as members of
> other structs, no dynamic memory allocation in sight so far. Then you need
> to add dynamic memory allocation to one of the structs (that's being used
> as a member of other structs etc) and suddenly all that code breaks.

...as it would in any language if you change the architecture of your design
without making the appropriate changes where needed.

> If
> there are millions of lines of code using any of those structs that have
> now "inherited" the need for manual construction and destruction (even though
> they were never designed for that initially), you'll have to go and modify
> those millions of lines to follow suit.

If that's a problem for you, just don't use a strongly typed language.

> Not so in C++, if you design your structs/classes correctly.

Your argument above is based on NOT designing your data structures correctly in
C, and now you say C++ handles better but only IF you do it correctly? Doesn't
make sense.

Even when trying to do everything explicitly right in C you will make mistakes.
Or I will, anyway.  I've found valgrind to be an invaluable tool when debugging
C code.

I'm very happy with teaming up C and Python. Low level ultrafast stuff in C
extension, high level OO garbage-collected stuff in Python. In the 90's I did a
largish project in C++ and never grew to like it much.

-- 
robert

[toc] | [prev] | [next] | [standalone]


#79282

FromJuha Nieminen <nospam@thanks.invalid>
Date2021-04-26 09:43 +0000
Message-ID<s661v4$102q$1@gioia.aioe.org>
In reply to#79274
In comp.lang.c++ Robert Latest <boblatest@yahoo.com> wrote:
> Your argument above is based on NOT designing your data structures correctly in
> C, and now you say C++ handles better but only IF you do it correctly? Doesn't
> make sense.

Are you telling be that every single time you create a struct in a C program
you always write a "constructor" and "destructor" for it, just in case that
some time in the future they might start requiring them?

Well, even if you actually do, my point stands: In C++ you don't need to do
that.

[toc] | [prev] | [next] | [standalone]


#79285

FromRobert Latest <boblatest@yahoo.com>
Date2021-04-26 10:35 +0000
Message-ID<ienjanFl5j5U1@mid.individual.net>
In reply to#79282
["Followup-To:" header set to comp.lang.c.]
Juha Nieminen wrote:
> In comp.lang.c++ Robert Latest <boblatest@yahoo.com> wrote:
>> Your argument above is based on NOT designing your data structures correctly
>> in C, and now you say C++ handles better but only IF you do it correctly?
>> Doesn't make sense.
>
> Are you telling be that every single time you create a struct in a C program
> you always write a "constructor" and "destructor" for it,

Of course not.

> just in case that some time in the future they might start requiring them?

No. Only if the data structure requires it, as is typical with nested,
dynamically allocated structs. Then of course it requires only a few extra
lines of code per struct type. If your struct is used for any non-trivial
amount of work you'll need some init code anyway.

> Well, even if you actually do, my point stands: In C++ you don't need to do
> that.

Then why don't you use C++ if thinking about memory management bothers you so
much?

-- 
robert

[toc] | [prev] | [next] | [standalone]


#79291

FromJuha Nieminen <nospam@thanks.invalid>
Date2021-04-26 13:08 +0000
Message-ID<s66dvh$1dj2$1@gioia.aioe.org>
In reply to#79285
In comp.lang.c++ Robert Latest <boblatest@yahoo.com> wrote:
> ["Followup-To:" header set to comp.lang.c.]
> Juha Nieminen wrote:
>> In comp.lang.c++ Robert Latest <boblatest@yahoo.com> wrote:
>>> Your argument above is based on NOT designing your data structures correctly
>>> in C, and now you say C++ handles better but only IF you do it correctly?
>>> Doesn't make sense.
>>
>> Are you telling be that every single time you create a struct in a C program
>> you always write a "constructor" and "destructor" for it,
> 
> Of course not.

That's exactly my point:

Suppose you have a huge amount of code, with lots and lots of structs, structs
as members of other structs, and a lot of code that uses those structs.

Then one day you decide to add a dynamically allocated array (such as a
dynamically allocated string) to one of the structs, which is used in
lots of other structs, which themselves are used in other structs, and
so on...

Because of a chance in this one struct, suddenly lots of other structs
"inherit" its need for manual construction and destruction, and tons of
code that uses those other structs need to be refactored to now call the
constructors and destructors of all the structs that now require it.
All because of this one struct.

In C++, you don't have to. You just add the dynamic data structure to
that one struct, and you're done. No need to modify anything else.

>> Well, even if you actually do, my point stands: In C++ you don't need to do
>> that.

> Then why don't you use C++ if thinking about memory management bothers you so
> much?

That's exactly what I do, whenever I can.

[toc] | [prev] | [next] | [standalone]


#79293

FromRichard Damon <Richard@Damon-Family.org>
Date2021-04-26 09:30 -0400
Message-ID<dgzhI.147872$PE7.113157@fx39.iad>
In reply to#79291
On 4/26/21 9:08 AM, Juha Nieminen wrote:
> In comp.lang.c++ Robert Latest <boblatest@yahoo.com> wrote:
>> ["Followup-To:" header set to comp.lang.c.]
>> Juha Nieminen wrote:
>>> In comp.lang.c++ Robert Latest <boblatest@yahoo.com> wrote:
>>>> Your argument above is based on NOT designing your data structures correctly
>>>> in C, and now you say C++ handles better but only IF you do it correctly?
>>>> Doesn't make sense.
>>>
>>> Are you telling be that every single time you create a struct in a C program
>>> you always write a "constructor" and "destructor" for it,
>>
>> Of course not.
> 
> That's exactly my point:
> 
> Suppose you have a huge amount of code, with lots and lots of structs, structs
> as members of other structs, and a lot of code that uses those structs.
> 
> Then one day you decide to add a dynamically allocated array (such as a
> dynamically allocated string) to one of the structs, which is used in
> lots of other structs, which themselves are used in other structs, and
> so on...
> 
> Because of a chance in this one struct, suddenly lots of other structs
> "inherit" its need for manual construction and destruction, and tons of
> code that uses those other structs need to be refactored to now call the
> constructors and destructors of all the structs that now require it.
> All because of this one struct.
> 
> In C++, you don't have to. You just add the dynamic data structure to
> that one struct, and you're done. No need to modify anything else.
> 
>>> Well, even if you actually do, my point stands: In C++ you don't need to do
>>> that.
> 
>> Then why don't you use C++ if thinking about memory management bothers you so
>> much?
> 
> That's exactly what I do, whenever I can.
> 

Yes, in C if you make that sort of change, you need to change a lot of code.

That is also, if you really think about it, a major breaking change in
the definition of the struct.

BECAUSE in C, you need to manual handle allocation, this is a breaking
API change to a structure from DEFINED to not need management, to
needing management. In C, you need to think ahead and ask if you can
conceive of a need to manage the life of the structure, and if so add
explicit create/destroy methods, even if for now, they do nothing. (You
can make them in-liene no-ops so can be no cost.

Yes, that is one of the advantages of C++, that you can easily change
this as C++ will automatically make this change for you. It also can be
seen as a weakness. It can be easy to make an apparently innocent
looking change that affects the performance of wide swathes of code as
that code get replicated everywhere.

[toc] | [prev] | [next] | [standalone]


#79295

FromRobert Latest <boblatest@yahoo.com>
Date2021-04-26 14:15 +0000
Message-ID<ieo07nFn0d5U2@mid.individual.net>
In reply to#79291
["Followup-To:" header set to comp.lang.c.]
Juha Nieminen wrote:
>
> Suppose you have a huge amount of code, with lots and lots of structs,
> structs as members of other structs, and a lot of code that uses those
> structs.

In other words, a mess.

> Then one day you decide to add a dynamically allocated array (such as a
> dynamically allocated string) to one of the structs, which is used in lots of
> other structs, which themselves are used in other structs, and so on...

I get your point. BTW I take "lots of structs" to mean "lots of struct types,"
not "lots of instances"

> Because of a chance in this one struct, suddenly lots of other structs
> "inherit" its need for manual construction and destruction, and tons of code
> that uses those other structs need to be refactored to now call the
> constructors and destructors of all the structs that now require it.  All
> because of this one struct.

Correct. At fault is not the language, nor the lack of a garbage collector, but
an ill-designed and unmaintainable pile of code which is badly in need of
refactoring anyway. Are you speaking of a real-life example? Dozens of
different struct types that all include one another and none of which
(originally) have dynamically allocated members?

-- 
robert

[toc] | [prev] | [next] | [standalone]


#79320

FromJuha Nieminen <nospam@thanks.invalid>
Date2021-04-27 04:37 +0000
Message-ID<s684eu$qg3$1@gioia.aioe.org>
In reply to#79295
In comp.lang.c++ Robert Latest <boblatest@yahoo.com> wrote:
>> Because of a chance in this one struct, suddenly lots of other structs
>> "inherit" its need for manual construction and destruction, and tons of code
>> that uses those other structs need to be refactored to now call the
>> constructors and destructors of all the structs that now require it.  All
>> because of this one struct.
> 
> Correct. At fault is not the language, nor the lack of a garbage collector, but
> an ill-designed and unmaintainable pile of code which is badly in need of
> refactoring anyway. Are you speaking of a real-life example? Dozens of
> different struct types that all include one another and none of which
> (originally) have dynamically allocated members?

But you yourself said that you don't automatically add manual constructors
and destructors to every struct you write, just in case.

I don't even understand what you mean by "well-designed code" then.
Is "well-designed" C code one where every struct has a constructor and
destructor function (that you always call for every single instance)?
Or is it something else?

[toc] | [prev] | [next] | [standalone]


#79322

FromRobert Latest <boblatest@yahoo.com>
Date2021-04-27 07:22 +0000
Message-ID<iepse2F3s1nU1@mid.individual.net>
In reply to#79320
["Followup-To:" header set to comp.lang.c.]
Juha Nieminen wrote:
> In comp.lang.c++ Robert Latest <boblatest@yahoo.com> wrote:
>>> Because of a chance in this one struct, suddenly lots of other structs
>>> "inherit" its need for manual construction and destruction, and tons of
>>> code that uses those other structs need to be refactored to now call the
>>> constructors and destructors of all the structs that now require it.  All
>>> because of this one struct.
>> 
>> Correct. At fault is not the language, nor the lack of a garbage collector,
>> but an ill-designed and unmaintainable pile of code which is badly in need
>> of refactoring anyway. Are you speaking of a real-life example? Dozens of
>> different struct types that all include one another and none of which
>> (originally) have dynamically allocated members?
>
> But you yourself said that you don't automatically add manual constructors
> and destructors to every struct you write, just in case.

Of course not. When you design a struct type you should already know what it is
supposed to represent and if the represented things lend themselves to dynamic
allocation. If so, better write construction / deconstriction functions. It
hardly adds significant amounts of code

> I don't even understand what you mean by "well-designed code" then.  Is
> "well-designed" C code one where every struct has a constructor and
> destructor function (that you always call for every single instance)?  Or is
> it something else?

A certain amount of foresight is part of good planning. If you jump straight
into coding without paying attention to possible issues of extending and re-use
you may face some refactoring effort later. This of course goes for anything,
not just changing from static to dynamic allocation in C.

I suspect you once had to refactor some code with a few structs because you
forgot this planning and have now worked yourself into a fret about some
contrived example with "lots and lots" of struct types that need to be adapted.
I don't believe it's a real world case, but if it is, it's poorly planned.

-- 
robert

[toc] | [prev] | [next] | [standalone]


#79104

From"Chris M. Thomasson" <chris.m.thomasson.1@gmail.com>
Date2021-04-19 21:42 -0700
Message-ID<s5lm36$1o58$1@gioia.aioe.org>
In reply to#79010
On 4/17/2021 10:12 AM, Manfred wrote:
> (cross-posting to comp.lang.c to let the heat fire up)
> 
> On 4/17/2021 7:56 AM, Juha Nieminen wrote:
>> I know that this is probably going to piss off avid C programmers,
>> but I don't really care all that much.
> 
> Excellent start
> 
> [...]
>>
>> I myself happen to know both languages quite well, and in fact I
>> program in both languages as my profession, and I would say that
>> I am very knowledgeable and proficient in both languages and have
>> no trouble in developing in either one. I am of the strong opinion
>> that no, C is not a "simple" language, and that C++ makes so many
>> things so much simpler, easier and safer.
>>
>> I was reminded of this in a quite concrete manner recently when I was
>> trying to help a beginner programmer who had decided to try his hands
>> on C, and wanted to create a simple text editor, which would read a
>> text file, allow the user to edit the text in several ways, and to
>> save the file.
>>
>> It quite quickly turned very frustrating for *both* of us ...
> 
> The first comment that comes to mind is that probably part of the 
> frustration stems from your approach (no offense) to try and use in C a 
> design that would be suitable for C++ instead. Despite their name, the 
> two are quite different languages. The similarities are about their 
> runtime footprint, not about how they are used.
> 
> For example, at a first glance the design of string object is not that 
> great for C.
> A common pattern that pops to the mind is to use opaque structs (see 
> e.g. FILE*), and have something like:
> 
> typedef struct string_t STRING;
> 
> STRING* alloc_string(); // creates the empty string
> STRING* set_string(STRING* s, const char* value);
> void free_string(STRING* s);
> STRING* concat_string(STRING* s1, STRING* s2);
> ...
> 
> This way there would be no ambiguity about how the STRING object has to 
> be used.
> And yes, in C you have to do all yourself - C is a low level language, 
> and it is meant for low level stuff. It is hardly the right tool for 
> anything meant to interface with a human user - it is (still) great for 
> system programming and back-end processing, IMO.
> 
> As second, I agree with Jacob that a text editor is a simple tool, but 
> it is not easy to make expecially for a beginner.
> 
> 
> [snip]

I would not call C easy. Instead, I would refer to it as being more to 
"the point", perhaps? Things have to be "explicit", it can be more 
verbose. I say that because C does not have RAII. Also, C is really nice 
to create plugins wrt creating portable bindings to other languages. 
Usually in C, things tend go like the following when coding up a new 
"object", so to speak:

Typing in the newsreader, sorry for typos.
________________________________

#include <stdio.h>
#include <stdlib.h>


struct foo
{
     int a;
     void* mem;
};

int foo_create(struct foo* const self)
{
     if ((self->mem = malloc(sizeof(42))))
     {
         self->a = 84;
         printf("foo_create(%p)\n", (void*)self);
         return 1;
     }

     return 0;
}

void foo_destroy(struct foo const* const self)
{
     printf("foo_destroy(%p)\n", (void*)self);
     free(self->mem);
}

void foo_output(struct foo const* self, FILE* output)
{
     printf("foo_output(%p)\n", (void*)self);
     fprintf(output, "struct foo(%p)->a = %d\n", (void*)self, self->a);
     fprintf(output, "struct foo(%p)->mem = %p\n", (void*)self, self->mem);
}


int main()
{
     struct foo foo;

     if (foo_create(&foo))
     {
         foo_output(&foo, stdout);

         foo_destroy(&foo);
     }

     return 0;
}
________________________________


See how I have to make an explicit call to foo_destroy? This can be 
handled in C++ in a "cleaner/safer" manner. Again, typing in the 
newsreader sorry for typos. This would be a simple C++ wrapper to the C 
API above:
________________________________

struct foo_wrapper
{
     struct foo m_foo;

     foo_wrapper() { if (! foo_create(&m_foo)) throw; }
     ~foo_wrapper() { foo_destroy(&m_foo); }

     void output(FILE* output_) const
     {
         foo_output(&m_foo, output_);
     }
};

________________________________

Then we can go:

{
     foo_wrapper foo;
     foo.output(stdout);
}

There. If it fails to create a foo in foo_create, it throws. Otherwise, 
foo_destroy is guaranteed to be called when foo goes out of scope. So, 
C++ can be more convenient, and safer. No need to use all of C++, but it 
does have its moments.

[toc] | [prev] | [next] | [standalone]


#79153

From"Chris M. Thomasson" <chris.m.thomasson.1@gmail.com>
Date2021-04-22 00:26 -0700
Message-ID<s5r8fk$1pn0$1@gioia.aioe.org>
In reply to#79104
On 4/19/2021 9:42 PM, Chris M. Thomasson wrote:
> On 4/17/2021 10:12 AM, Manfred wrote:
>> (cross-posting to comp.lang.c to let the heat fire up)
>>
>> On 4/17/2021 7:56 AM, Juha Nieminen wrote:
>>> I know that this is probably going to piss off avid C programmers,
>>> but I don't really care all that much.
>>
>> Excellent start
>>
>> [...]
>>>
>>> I myself happen to know both languages quite well, and in fact I
>>> program in both languages as my profession, and I would say that
>>> I am very knowledgeable and proficient in both languages and have
>>> no trouble in developing in either one. I am of the strong opinion
>>> that no, C is not a "simple" language, and that C++ makes so many
>>> things so much simpler, easier and safer.
>>>
>>> I was reminded of this in a quite concrete manner recently when I was
>>> trying to help a beginner programmer who had decided to try his hands
>>> on C, and wanted to create a simple text editor, which would read a
>>> text file, allow the user to edit the text in several ways, and to
>>> save the file.
>>>
>>> It quite quickly turned very frustrating for *both* of us ...
>>
>> The first comment that comes to mind is that probably part of the 
>> frustration stems from your approach (no offense) to try and use in C 
>> a design that would be suitable for C++ instead. Despite their name, 
>> the two are quite different languages. The similarities are about 
>> their runtime footprint, not about how they are used.
>>
>> For example, at a first glance the design of string object is not that 
>> great for C.
>> A common pattern that pops to the mind is to use opaque structs (see 
>> e.g. FILE*), and have something like:
>>
>> typedef struct string_t STRING;
>>
>> STRING* alloc_string(); // creates the empty string
>> STRING* set_string(STRING* s, const char* value);
>> void free_string(STRING* s);
>> STRING* concat_string(STRING* s1, STRING* s2);
>> ...
>>
>> This way there would be no ambiguity about how the STRING object has 
>> to be used.
>> And yes, in C you have to do all yourself - C is a low level language, 
>> and it is meant for low level stuff. It is hardly the right tool for 
>> anything meant to interface with a human user - it is (still) great 
>> for system programming and back-end processing, IMO.
>>
>> As second, I agree with Jacob that a text editor is a simple tool, but 
>> it is not easy to make expecially for a beginner.
>>
>>
>> [snip]
> 
> I would not call C easy. Instead, I would refer to it as being more to 
> "the point", perhaps? Things have to be "explicit", it can be more 
> verbose. I say that because C does not have RAII. Also, C is really nice 
> to create plugins wrt creating portable bindings to other languages. 
> Usually in C, things tend go like the following when coding up a new 
> "object", so to speak:
> 
> Typing in the newsreader, sorry for typos.
> ________________________________
> 
> #include <stdio.h>
> #include <stdlib.h>
> 
> 
> struct foo
> {
>     int a;
>     void* mem;
> };
> 
> int foo_create(struct foo* const self)
> {
>     if ((self->mem = malloc(sizeof(42))))
>     {
>         self->a = 84;
>         printf("foo_create(%p)\n", (void*)self);
>         return 1;
>     }
> 
>     return 0;
> }
> 
> void foo_destroy(struct foo const* const self)
> {
>     printf("foo_destroy(%p)\n", (void*)self);
>     free(self->mem);
> }
> 
> void foo_output(struct foo const* self, FILE* output)
> {
>     printf("foo_output(%p)\n", (void*)self);
>     fprintf(output, "struct foo(%p)->a = %d\n", (void*)self, self->a);
>     fprintf(output, "struct foo(%p)->mem = %p\n", (void*)self, self->mem);
> }
> 
> 
> int main()
> {
>     struct foo foo;
> 
>     if (foo_create(&foo))
>     {
>         foo_output(&foo, stdout);
> 
>         foo_destroy(&foo);
>     }
> 
>     return 0;
> }
> ________________________________
> 
> 
> See how I have to make an explicit call to foo_destroy? This can be 
> handled in C++ in a "cleaner/safer" manner. Again, typing in the 
> newsreader sorry for typos. This would be a simple C++ wrapper to the C 
> API above:
> ________________________________
> 
> struct foo_wrapper
> {
>     struct foo m_foo;
> 
>     foo_wrapper() { if (! foo_create(&m_foo)) throw; }
>     ~foo_wrapper() { foo_destroy(&m_foo); }
> 
>     void output(FILE* output_) const
>     {
>         foo_output(&m_foo, output_);
>     }
> };
> 
> ________________________________
> 
> Then we can go:
> 
> {
>     foo_wrapper foo;
>     foo.output(stdout);
> }
> 
> There. If it fails to create a foo in foo_create, it throws. Otherwise, 
> foo_destroy is guaranteed to be called when foo goes out of scope. So, 
> C++ can be more convenient, and safer. No need to use all of C++, but it 
> does have its moments.

First learning about RAII, even when I learned about ScopeGuard, back in 
my C++ days, for some reason, makes me think of the following song:

https://youtu.be/UZ2-FfXZlAU

Even though I was working with C/C++ well before this song was created, 
it makes think way back when I was a little kid using basic on my Atari.

[toc] | [prev] | [next] | [standalone]


#79347

From"Chris M. Thomasson" <chris.m.thomasson.1@gmail.com>
Date2021-04-28 00:02 -0700
Message-ID<s6b1a3$152b$1@gioia.aioe.org>
In reply to#79010
On 4/17/2021 10:12 AM, Manfred wrote:
> (cross-posting to comp.lang.c to let the heat fire up)
> 
> On 4/17/2021 7:56 AM, Juha Nieminen wrote:
>> I know that this is probably going to piss off avid C programmers,
>> but I don't really care all that much.
> 
> Excellent start
> 
> [...]
>>
>> I myself happen to know both languages quite well, and in fact I
>> program in both languages as my profession, and I would say that
>> I am very knowledgeable and proficient in both languages and have
>> no trouble in developing in either one. I am of the strong opinion
>> that no, C is not a "simple" language, and that C++ makes so many
>> things so much simpler, easier and safer.
>>
>> I was reminded of this in a quite concrete manner recently when I was
>> trying to help a beginner programmer who had decided to try his hands
>> on C, and wanted to create a simple text editor, which would read a
>> text file, allow the user to edit the text in several ways, and to
>> save the file.
>>
>> It quite quickly turned very frustrating for *both* of us ...
> 
> The first comment that comes to mind is that probably part of the 
> frustration stems from your approach (no offense) to try and use in C a 
> design that would be suitable for C++ instead. Despite their name, the 
> two are quite different languages. The similarities are about their 
> runtime footprint, not about how they are used.
> 
> For example, at a first glance the design of string object is not that 
> great for C.
> A common pattern that pops to the mind is to use opaque structs (see 
> e.g. FILE*), and have something like:
> 
> typedef struct string_t STRING;
> 
> STRING* alloc_string(); // creates the empty string
> STRING* set_string(STRING* s, const char* value);
> void free_string(STRING* s);
> STRING* concat_string(STRING* s1, STRING* s2);
> ...
> 
> This way there would be no ambiguity about how the STRING object has to 
> be used.
> And yes, in C you have to do all yourself - C is a low level language, 
> and it is meant for low level stuff. It is hardly the right tool for 
> anything meant to interface with a human user - it is (still) great for 
> system programming and back-end processing, IMO.
> 
> As second, I agree with Jacob that a text editor is a simple tool, but 
> it is not easy to make expecially for a beginner.
> 
> 
> [snip]

Wrt using GC as the everlasting crutch:

https://youtu.be/ao-Sahfy7Hg

[toc] | [prev] | [next] | [standalone]


Page 6 of 8 — ← Prev page 1 2 3 4 5 [6] 7 8  Next page →

Back to top | Article view | comp.lang.c++


csiph-web