Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #78998 > unrolled thread
| Started by | Juha Nieminen <nospam@thanks.invalid> |
|---|---|
| First post | 2021-04-17 05:56 +0000 |
| Last post | 2021-04-26 08:49 +0000 |
| Articles | 20 on this page of 143 — 32 participants |
Back to article view | Back to comp.lang.c++
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 4 of 8 — ← Prev page 1 2 3 [4] 5 6 7 8 Next page →
| From | Keith Thompson <Keith.S.Thompson+u@gmail.com> |
|---|---|
| Date | 2021-04-18 12:46 -0700 |
| Message-ID | <878s5f1im9.fsf@nosuchdomain.example.com> |
| In reply to | #79046 |
Manfred <noname@add.invalid> writes:
> On 4/18/2021 6:46 PM, Juha Nieminen wrote:
>> In comp.lang.c++ Manfred <noname@add.invalid> wrote:
>>> 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.
>>
>> I see no practical difference between that and a String struct. The usage is
>> pretty much the same, and all the same problems appear (such as assigning
>> one string object/pointer to another requiring extra care to avoid destroying
>> the string twice or accessing a destroyed string).
>>
>
> If the struct is opaque, the compiler won't allow you to assign a
> STRING object to another, as a start. In fact it won't allow to
> perform /any/ operation on the object, except through the API that you
> define.
>
> You can still mess up with pointers, but if you want to use C, then
> you have to know better.
>
> This is nothing new, as I wrote the entire FILE* infrastructure works
> this way.
Except that you *can* assign objects of type FILE (if you don't mind
undefined behavior). The FILE type is opaque in the sense that the
standard doesn't say what it looks like, but it has to be an object
type.
--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Working, but not speaking, for Philips Healthcare
void Void(void) { Void(); } /* The recursive call of the void */
[toc] | [prev] | [next] | [standalone]
| From | Manfred <noname@add.invalid> |
|---|---|
| Date | 2021-04-18 22:53 +0200 |
| Message-ID | <s5i68f$1g9m$1@gioia.aioe.org> |
| In reply to | #79052 |
On 4/18/2021 9:46 PM, Keith Thompson wrote:
> Manfred <noname@add.invalid> writes:
>> On 4/18/2021 6:46 PM, Juha Nieminen wrote:
>>> In comp.lang.c++ Manfred <noname@add.invalid> wrote:
>>>> 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.
>>>
>>> I see no practical difference between that and a String struct. The usage is
>>> pretty much the same, and all the same problems appear (such as assigning
>>> one string object/pointer to another requiring extra care to avoid destroying
>>> the string twice or accessing a destroyed string).
>>>
>>
>> If the struct is opaque, the compiler won't allow you to assign a
>> STRING object to another, as a start. In fact it won't allow to
>> perform /any/ operation on the object, except through the API that you
>> define.
>>
>> You can still mess up with pointers, but if you want to use C, then
>> you have to know better.
>>
>> This is nothing new, as I wrote the entire FILE* infrastructure works
>> this way.
>
> Except that you *can* assign objects of type FILE (if you don't mind
> undefined behavior). The FILE type is opaque in the sense that the
> standard doesn't say what it looks like, but it has to be an object
> type.
>
The relevant part was:
> typedef struct string_t STRING;
I am talking about opaque types, which are incomplete and as such you
can't use objects of their type.
As far as the standard is concerned FILE is an opaque type whose
definition might not be seen (and in fact is _not_ intended to be seen,
let alone used) by user code.
I think it is clear that the fact that in some implementations the
definition of FILE might percolate into user TUs is orthogonal to this
discussion.
$ cat opaque.c
typedef struct string_t STRING;
STRING* string_concat(STRING* s1, STRING* s2);
void string_free(STRING* s);
void foo(STRING* s1, STRING* s2)
{
STRING* s3 = string_concat(s1, s2);
string_free(s3);
}
void bar(STRING* s1, STRING* s2)
{
*s2 = *s1; // can't do that
}
$ cc -std=c11 -Wall -pedantic -c opaque.c
opaque.c: In function ‘bar’:
opaque.c:17:9: error: invalid use of incomplete typedef ‘STRING’ {aka
‘struct string_t’}
17 | *s2 = *s1;
| ^
opaque.c:17:7: error: invalid use of incomplete typedef ‘STRING’ {aka
‘struct string_t’}
17 | *s2 = *s1;
| ^
[toc] | [prev] | [next] | [standalone]
| From | Juha Nieminen <nospam@thanks.invalid> |
|---|---|
| Date | 2021-04-19 07:18 +0000 |
| Message-ID | <s5jarj$1gq6$1@gioia.aioe.org> |
| In reply to | #79046 |
In comp.lang.c++ Manfred <noname@add.invalid> wrote:
> If the struct is opaque, the compiler won't allow you to assign a STRING
> object to another, as a start. In fact it won't allow to perform /any/
> operation on the object, except through the API that you define.
I see no difference between your scheme and mine.
String str1 = String_with_cstr("hello");
String str2 = str1;
// lots of code here
String_free(str1);
String_free(str2); // oops
vs.
String* str1 = String_with_c_str("hello");
String* str2 = str1;
// lots of code here
String_free(str1);
String_free(str2); // oops
> You can still mess up with pointers, but if you want to use C, then you
> have to know better.
My point is that for a beginner it's so much simpler to be able to do:
std::string str1 = "hello";
std::string str2 = str1;
// lots of code here
// no need to even destroy those strings, they'll be destroyed
// automatically
It's also significantly easier to try to guide a beginner to create a small
project like I described.
(Sure, you can start arguing about the efficiency issues of std::string
always making a deep copy whenever it's passed around, but this is just
trying to guide a beginner to do one of his first projects. The efficiency
questions can come up much, much later in the learning process. At this
point the efficiency issues are completely irrelevant.)
[toc] | [prev] | [next] | [standalone]
| From | Manfred <noname@add.invalid> |
|---|---|
| Date | 2021-04-19 17:15 +0200 |
| Message-ID | <s5k6q6$301$1@gioia.aioe.org> |
| In reply to | #79072 |
On 4/19/2021 9:18 AM, Juha Nieminen wrote:
> In comp.lang.c++ Manfred <noname@add.invalid> wrote:
>> If the struct is opaque, the compiler won't allow you to assign a STRING
>> object to another, as a start. In fact it won't allow to perform /any/
>> operation on the object, except through the API that you define.
>
> I see no difference between your scheme and mine.
>
> String str1 = String_with_cstr("hello");
> String str2 = str1;
> // lots of code here
> String_free(str1);
> String_free(str2); // oops
>
> vs.
>
> String* str1 = String_with_c_str("hello");
> String* str2 = str1;
> // lots of code here
> String_free(str1);
> String_free(str2); // oops
I do see a difference there, and it is the tiny little '*' in
> String* str2 = str1;
Which means that you are duplicating a pointer to an object and this
should trigger extra attention wrt object lifetime (and other things for
that matter).
Would you ever write with any lightness:
FILE* f1 = fopen("foo", "r");
FILE* f2 = f1;
// ...
If you want to use C you should get trained to this kind of details.
However, I get that this is probably what you mean by C being not simple
- it is not.
My point is that if you are using C, and you are familiar with it, then
there is a difference between the two designs.
(An example where your design is perfectly OK and widely used:
typedef struct point_t
{
int x;
int y;
} POINT;
POINT p1 = {42, 42};
POINT p2 = p1;
...
But here you make sure that the type is safely (trivially) copyable, a.o.)
>
>> You can still mess up with pointers, but if you want to use C, then you
>> have to know better.
>
> My point is that for a beginner it's so much simpler to be able to do:
>
> std::string str1 = "hello";
> std::string str2 = str1;
> // lots of code here
> // no need to even destroy those strings, they'll be destroyed
> // automatically
>
> It's also significantly easier to try to guide a beginner to create a small
> project like I described.
I'd comment about the term "easy" - you still need to know how RAII and
stuff works here, even if it all happens automatically.
I'd say that the fact that it happens behind the scenes might even make
it harder for a beginner.
The code /looks/ simpler, the mechanics of it is not - C++ is not simple
either.
Considering C++ simple is a major source of mistakes, IMO.
>
> (Sure, you can start arguing about the efficiency issues of std::string
> always making a deep copy whenever it's passed around, but this is just
> trying to guide a beginner to do one of his first projects. The efficiency
> questions can come up much, much later in the learning process. At this
> point the efficiency issues are completely irrelevant.)
>
Agreed, performance has no relevance here.
[toc] | [prev] | [next] | [standalone]
| From | Juha Nieminen <nospam@thanks.invalid> |
|---|---|
| Date | 2021-04-20 04:05 +0000 |
| Message-ID | <s5lju6$v0c$2@gioia.aioe.org> |
| In reply to | #79084 |
In comp.lang.c++ Manfred <noname@add.invalid> wrote: >> My point is that for a beginner it's so much simpler to be able to do: >> >> std::string str1 = "hello"; >> std::string str2 = str1; >> // lots of code here >> // no need to even destroy those strings, they'll be destroyed >> // automatically >> >> It's also significantly easier to try to guide a beginner to create a small >> project like I described. > > I'd comment about the term "easy" - you still need to know how RAII and > stuff works here, even if it all happens automatically. > I'd say that the fact that it happens behind the scenes might even make > it harder for a beginner. Might make *what* harder for a beginner, exactly?
[toc] | [prev] | [next] | [standalone]
| From | Manfred <noname@add.invalid> |
|---|---|
| Date | 2021-04-20 18:27 +0200 |
| Message-ID | <s5mvd7$14qh$1@gioia.aioe.org> |
| In reply to | #79102 |
On 4/20/2021 6:05 AM, Juha Nieminen wrote: > In comp.lang.c++ Manfred <noname@add.invalid> wrote: >>> My point is that for a beginner it's so much simpler to be able to do: >>> >>> std::string str1 = "hello"; >>> std::string str2 = str1; >>> // lots of code here >>> // no need to even destroy those strings, they'll be destroyed >>> // automatically >>> >>> It's also significantly easier to try to guide a beginner to create a small >>> project like I described. >> >> I'd comment about the term "easy" - you still need to know how RAII and >> stuff works here, even if it all happens automatically. >> I'd say that the fact that it happens behind the scenes might even make >> it harder for a beginner. > > Might make *what* harder for a beginner, exactly? > 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. 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.
[toc] | [prev] | [next] | [standalone]
| From | Juha Nieminen <nospam@thanks.invalid> |
|---|---|
| Date | 2021-04-20 16:41 +0000 |
| Message-ID | <s5n07m$1ijc$1@gioia.aioe.org> |
| In reply to | #79111 |
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. The complexity can quickly grow exponentially. 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.
[toc] | [prev] | [next] | [standalone]
| From | jacobnavia <jacob@jacob.remcomp.fr> |
|---|---|
| Date | 2021-04-20 19:44 +0200 |
| Message-ID | <s5n3te$eu3$1@dont-email.me> |
| In reply to | #79112 |
Le 20/04/2021 à 18:41, Juha Nieminen a écrit : > 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. No. Just have a constructotr and never free anything. Then link with Boehm's GARBAGE COLLECTOR and be done with it! I have already said this in this thread but people will go on arguing about how difficult is to keep the accounting of memory pieces right. And they are right but refuse to see the right tool for theirpurpose: just use a garbage collector and BE DONE WITH IT. 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... Use an automatic garbage collector and BE DONE WITH IT. And please, do not start with performance problems, in most string applications the gc is completely transparent.
[toc] | [prev] | [next] | [standalone]
| From | Kaz Kylheku <563-365-8930@kylheku.com> |
|---|---|
| Date | 2021-04-20 18:30 +0000 |
| Message-ID | <20210420110446.451@kylheku.com> |
| In reply to | #79114 |
On 2021-04-20, jacobnavia <jacob@jacob.remcomp.fr> wrote:
> Le 20/04/2021 à 18:41, Juha Nieminen a écrit :
>> 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.
>
> No.
>
> Just have a constructotr and never free anything. Then link with Boehm's
> GARBAGE COLLECTOR and be done with it!
You are talking about a different nuance for construction.
In high level, dynamic languages, constructing an object refers to
aggregation.
The ancient function CONS in Lisp may hgave been the first one to use
the construction terminology. If we make a CONS which contains two
strings, there is not construction of those strings going on; they are
already constructed:
(cons "abc" "def")
Juha is probably talking about C++ style construction where if we have
struct foo { string s; foo(); }, the foo::foo constructor has to
call the string::string constructor.
Juha's remarks are true when objects are put together using composition
rather than aggregation.
Because the object B is embedded in another A, and must be initialized,
then the type-B-specific initialization logic for that embedded object
has to be invoked to initialize that B-typed portion of A.
From an abstraction point of view, it's really a shit design. But the
motivation is solid: there are certain efficiencies you can gain when
you compose rather than aggregate objects. You save space by not
allocating separate objects, reducing allocator overhead, and by not
allocating a pointer to navigate from one to the other. By not chasing a
pointer, you reduce pipeline stalls due to dependent loads. Low-level,
systems programming languages benefit from being able to compose
objects.
It's not worth trying to shoehorn that paradigm into a high level
language though. Composition of objects works for simple, low-level code
that has to run fast, and requires only a simple language.
If your idea for building a web browser or word processor includes
anything like this:
class Document {
std::string documentName;
//
}
due to the immense benefit of not having to chase an extra pointer
or allocate an extra object, you must be a supreme moron, and you will
have your lunch eaten by someone working in Javascript or Python.
> I have already said this in this thread but people will go on arguing
> about how difficult is to keep the accounting of memory pieces right.
> And they are right but refuse to see the right tool for theirpurpose:
> just use a garbage collector and BE DONE WITH IT.
That should be: use a language with a garbage collector and be done
with it.
Statistically/probabilistically speaking, given that you have a genuine
reason to be using C, then conditional probability is high that garbage
collection may not be a good fit for the problem.
> 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...
>
> Use an automatic garbage collector and BE DONE WITH IT. And please, do
> not start with performance problems, in most string applications the gc
> is completely transparent.
GC has good performance. But not in a small space. GC needs more memory
than manual freeing in order to perform well.
Most of the speed (in terms of raw throughput) improvements in GC
revolve around the theme of allowing garbage to linger around longer, so
that garbage cycles are either less frequent (e.g. tuning a larger
heap), or smaller in scope (generational GC, visiting just a young
subset of the object graph in most GC passes).
Allowing garbage to stick around longer translates to one thing: larger
memory footprints.
Adding GC to a simple, embedded application in which manual memory
management can be done correctly with relative ease will just bloat
its footprint. If the footprint is kept very tight, GC will run often
which could degrade the performance.
In a single-process system with physical memory, you can just
do collection whenever memory is nearly exausted, which is optimal.
The memory is needed for nothing else.
In a VM system that is using all of its free memory for a buffer/file
cache, any extra slack space for GC encroaches on that cache, even if no
other applications are running. Which they usually are. VM footprints
matter.
--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
[toc] | [prev] | [next] | [standalone]
| From | jacobnavia <jacob@jacob.remcomp.fr> |
|---|---|
| Date | 2021-04-20 20:47 +0200 |
| Message-ID | <s5n7k4$9i2$1@dont-email.me> |
| In reply to | #79116 |
Le 20/04/2021 à 20:30, Kaz Kylheku a écrit : > GC has good performance. But not in a small space. GC needs more memory > than manual freeing in order to perform well. > Note: malloc/free do garbage collection by consolidating free memory blocks into larger ones. This essential FACT is being overlooked here. But granted, in small embedded applications with less CPU power and less RAM GC is not the ideal solution and you do the accounting by hand. But in those environments, C++ is anyway out of the question! > Most of the speed (in terms of raw throughput) improvements in GC > revolve around the theme of allowing garbage to linger around longer, so > that garbage cycles are either less frequent (e.g. tuning a larger > heap), or smaller in scope (generational GC, visiting just a young > subset of the object graph in most GC passes). > See above. In small spaces GC is not that good. But we were talking about a TEXT EDITOR for learning C, so that is probably a PC environment where GC SHINES! > Allowing garbage to stick around longer translates to one thing: larger > memory footprints. > Yes. But you can obviate that by calling the GC explicitely from time to time. > Adding GC to a simple, embedded application in which manual memory > management can be done correctly with relative ease will just bloat > its footprint. If the footprint is kept very tight, GC will run often > which could degrade the performance. > Agreed. As I said above, for simple, embedded applications the GC is not the best solution. > In a single-process system with physical memory, you can just > do collection whenever memory is nearly exausted, which is optimal. > The memory is needed for nothing else. > > In a VM system that is using all of its free memory for a buffer/file > cache, any extra slack space for GC encroaches on that cache, even if no > other applications are running. Which they usually are. VM footprints > matter. There are MANY other solutions in C. You can do pool allocating, for instance, allocating all the related strings from a pool that is freed in a single instruction. ETC.
[toc] | [prev] | [next] | [standalone]
| From | "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> |
|---|---|
| Date | 2021-04-20 13:29 -0700 |
| Message-ID | <s5ndjf$6lo$1@gioia.aioe.org> |
| In reply to | #79118 |
On 4/20/2021 11:47 AM, jacobnavia wrote: > Le 20/04/2021 à 20:30, Kaz Kylheku a écrit : >> GC has good performance. But not in a small space. GC needs more memory >> than manual freeing in order to perform well. >> > > Note: malloc/free do garbage collection by consolidating free memory > blocks into larger ones. This essential FACT is being overlooked here. consolidating smaller blocks into larger ones has nothing to do with the conventional notion of a garbage collector. So, you saying that malloc/free do GC is very odd to me, indeed. > > But granted, in small embedded applications with less CPU power and less > RAM GC is not the ideal solution and you do the accounting by hand. But > in those environments, C++ is anyway out of the question! > >> Most of the speed (in terms of raw throughput) improvements in GC >> revolve around the theme of allowing garbage to linger around longer, so >> that garbage cycles are either less frequent (e.g. tuning a larger >> heap), or smaller in scope (generational GC, visiting just a young >> subset of the object graph in most GC passes). >> > > See above. In small spaces GC is not that good. But we were talking > about a TEXT EDITOR for learning C, so that is probably a PC environment > where GC SHINES! > >> Allowing garbage to stick around longer translates to one thing: larger >> memory footprints. >> > > Yes. But you can obviate that by calling the GC explicitely from time to > time. > >> Adding GC to a simple, embedded application in which manual memory >> management can be done correctly with relative ease will just bloat >> its footprint. If the footprint is kept very tight, GC will run often >> which could degrade the performance. >> > > Agreed. As I said above, for simple, embedded applications the GC is not > the best solution. > >> In a single-process system with physical memory, you can just >> do collection whenever memory is nearly exausted, which is optimal. >> The memory is needed for nothing else. >> >> In a VM system that is using all of its free memory for a buffer/file >> cache, any extra slack space for GC encroaches on that cache, even if no >> other applications are running. Which they usually are. VM footprints >> matter. > > There are MANY other solutions in C. You can do pool allocating, for > instance, allocating all the related strings from a pool that is freed > in a single instruction. ETC. > >
[toc] | [prev] | [next] | [standalone]
| From | Juha Nieminen <nospam@thanks.invalid> |
|---|---|
| Date | 2021-04-21 04:37 +0000 |
| Message-ID | <s5oa5u$1sgb$1@gioia.aioe.org> |
| In reply to | #79118 |
In comp.lang.c++ jacobnavia <jacob@jacob.remcomp.fr> wrote: > See above. In small spaces GC is not that good. But we were talking > about a TEXT EDITOR for learning C, so that is probably a PC environment > where GC SHINES! If that's the case, then just use a language like Java or Python. Or, you know, C++. At least you won't be needing to use non-standard third-party extensions.
[toc] | [prev] | [next] | [standalone]
| From | wij <wyniijj@gmail.com> |
|---|---|
| Date | 2021-04-20 22:02 -0700 |
| Message-ID | <3dcdc702-8163-4aac-9678-959b22a0d46an@googlegroups.com> |
| In reply to | #79134 |
On Wednesday, 21 April 2021 at 12:37:31 UTC+8, Juha Nieminen wrote: > In comp.lang.c++ jacobnavia <ja...@jacob.remcomp.fr> wrote: > > See above. In small spaces GC is not that good. But we were talking > > about a TEXT EDITOR for learning C, so that is probably a PC environment > > where GC SHINES! > If that's the case, then just use a language like Java or Python. > > Or, you know, C++. > > At least you won't be needing to use non-standard third-party extensions. If that's the case, why you learn C/C++? I feel your logic is similar to olcott's, maybe a bit worse.
[toc] | [prev] | [next] | [standalone]
| From | wij <wyniijj@gmail.com> |
|---|---|
| Date | 2021-04-20 22:35 -0700 |
| Message-ID | <5acfb72d-1144-411a-9c4c-7a75791ef109n@googlegroups.com> |
| In reply to | #79135 |
On Wednesday, 21 April 2021 at 13:02:31 UTC+8, wij wrote: > On Wednesday, 21 April 2021 at 12:37:31 UTC+8, Juha Nieminen wrote: > > In comp.lang.c++ jacobnavia <ja...@jacob.remcomp.fr> wrote: > > > See above. In small spaces GC is not that good. But we were talking > > > about a TEXT EDITOR for learning C, so that is probably a PC environment > > > where GC SHINES! > > If that's the case, then just use a language like Java or Python. > > > > Or, you know, C++. > > > > At least you won't be needing to use non-standard third-party extensions. > If that's the case, why you learn C/C++? > I feel your logic is similar to olcott's, maybe a bit worse. By the way, I do not use most "standard" stuff, that enables me to gain more functionality from "C", and much less unnecessary "standard" burdens.
[toc] | [prev] | [next] | [standalone]
| From | "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> |
|---|---|
| Date | 2021-04-21 15:26 -0700 |
| Message-ID | <s5q8rh$1rnd$1@gioia.aioe.org> |
| In reply to | #79134 |
On 4/20/2021 9:37 PM, Juha Nieminen wrote: > In comp.lang.c++ jacobnavia <jacob@jacob.remcomp.fr> wrote: >> See above. In small spaces GC is not that good. But we were talking >> about a TEXT EDITOR for learning C, so that is probably a PC environment >> where GC SHINES! > > If that's the case, then just use a language like Java or Python. > > Or, you know, C++. > > At least you won't be needing to use non-standard third-party extensions. > Fwiw, using an "extension" in C is nothing new. Want to create a server, better learn how to use sockets. If you want to go deep, create your own TCP stack. Is creating a driver in C to use a 3d party device "cheating" by using third-party extensions? third-party API's? Luckily for me a lot of my recent work is 100% workable with pure C and graphics. Pure C generating a PPM image is absolutely perfect. 100% portable and no 3d party code used in any way, shape or form. :^) If the user wants to view the result of my C code, they can choose any PPM viewer they want to. There, pure C code generating fractals, vector fields, abstract art, ect. ;^) Way back in the day I would be forced to use "extensions" to C. Things like POSIX, Pthreads, my own externally assembled atomic's libs for various archs using MASM and GAS, ect... I still have a bunch of code that uses the good ol' Pthreads for win32 lib here: https://sourceware.org/pthreads-win32 When C/C++ 11 made atomic's and threading standard, it was really nice, but made me want to port all of my older code from Pthreads and assembly language to the new stuff. Here is a result of some of my C code generating a single file for another program, PovRay, to raytrace for me: https://youtu.be/skGUAXAx6eg https://youtu.be/R0v_1EBAOr4
[toc] | [prev] | [next] | [standalone]
| From | wij <wyniijj@gmail.com> |
|---|---|
| Date | 2021-04-21 22:06 -0700 |
| Message-ID | <c105a5d3-4a8d-4fc9-a1d2-eab2374dce16n@googlegroups.com> |
| In reply to | #79147 |
On Thursday, 22 April 2021 at 06:27:16 UTC+8, Chris M. Thomasson wrote: > On 4/20/2021 9:37 PM, Juha Nieminen wrote: > > In comp.lang.c++ jacobnavia <ja...@jacob.remcomp.fr> wrote: > >> See above. In small spaces GC is not that good. But we were talking > >> about a TEXT EDITOR for learning C, so that is probably a PC environment > >> where GC SHINES! > > > > If that's the case, then just use a language like Java or Python. > > > > Or, you know, C++. > > > > At least you won't be needing to use non-standard third-party extensions. > > > Fwiw, using an "extension" in C is nothing new. Want to create a server, > better learn how to use sockets. If you want to go deep, create your own > TCP stack. Is creating a driver in C to use a 3d party device "cheating" > by using third-party extensions? third-party API's? > > Luckily for me a lot of my recent work is 100% workable with pure C and > graphics. Pure C generating a PPM image is absolutely perfect. 100% > portable and no 3d party code used in any way, shape or form. :^) > > If the user wants to view the result of my C code, they can choose any > PPM viewer they want to. There, pure C code generating fractals, vector > fields, abstract art, ect. ;^) > > Way back in the day I would be forced to use "extensions" to C. Things > like POSIX, Pthreads, my own externally assembled atomic's libs for > various archs using MASM and GAS, ect... I still have a bunch of code > that uses the good ol' Pthreads for win32 lib here: > > https://sourceware.org/pthreads-win32 > > When C/C++ 11 made atomic's and threading standard, it was really nice, > but made me want to port all of my older code from Pthreads and assembly > language to the new stuff. > > Here is a result of some of my C code generating a single file for > another program, PovRay, to raytrace for me: > When thread was introduced in C++11, I needed to consider using it or not, too. But after weighing the gains and losses, I decided that RAII feature outweigh the efficiency. Thus, not using it. C++ has several places violated its original OO principle, this is just one example. For instance, the added keyword override/final/delete (good, but it reflects the half-true "object model" crap) violated the C++ author's ideal (or guideline) about a a good language "...not add a new feature and then add another to disable it..." > https://youtu.be/skGUAXAx6eg > > https://youtu.be/R0v_1EBAOr4
[toc] | [prev] | [next] | [standalone]
| From | Juha Nieminen <nospam@thanks.invalid> |
|---|---|
| Date | 2021-04-22 08:52 +0000 |
| Message-ID | <s5rdfo$612$1@gioia.aioe.org> |
| In reply to | #79150 |
wij <wyniijj@gmail.com> wrote: > When thread was introduced in C++11, I needed to consider using it or not, too. > But after weighing the gains and losses, I decided that RAII feature outweigh > the efficiency. Thus, not using it. That paragraph doesn't make much sense. Care to rephrase it? (If you are claiming that RAII is inefficient, on what exactly do you base that assumption?) > C++ has several places violated its original OO principle, this is just one example. > For instance, the added keyword override/final/delete (good, but it reflects the > half-true "object model" crap) violated the C++ author's ideal (or guideline) about a > a good language "...not add a new feature and then add another to disable it..." What exactly is the problem with the 'override' keyword? It has zero effect on object-oriented design in one direction or the other, and it helps avoiding mistakes. So what's the problem? As for 'delete', do you prefer the old method of declaring automatically generated functions as private? That was a bit of a kludge in the first place, which '=delete' fixes. Now you have a much clearer way to tell the compiler to not autogenerate those functions, and to get better error messages.
[toc] | [prev] | [next] | [standalone]
| From | wij <wyniijj@gmail.com> |
|---|---|
| Date | 2021-04-22 09:41 -0700 |
| Message-ID | <a96c61d4-d2dc-44cd-b563-61cdea504f83n@googlegroups.com> |
| In reply to | #79160 |
On Thursday, 22 April 2021 at 16:52:26 UTC+8, Juha Nieminen wrote: > wij <wyn...@gmail.com> wrote: > > When thread was introduced in C++11, I needed to consider using it or not, too. > > But after weighing the gains and losses, I decided that RAII feature outweigh > > the efficiency. Thus, not using it. > That paragraph doesn't make much sense. Care to rephrase it? > > (If you are claiming that RAII is inefficient, on what exactly do you base > that assumption?) Checked again from https://en.cppreference.com/w/cpp/thread/thread, along with my document and email. Woo, I could have read a premature version of std::thread (I do not use C++ standard library). I have been so wrong for these years. Sorry about this part. > > C++ has several places violated its original OO principle, this is just one example. > > For instance, the added keyword override/final/delete (good, but it reflects the > > half-true "object model" crap) violated the C++ author's ideal (or guideline) about a > > a good language "...not add a new feature and then add another to disable it..." > What exactly is the problem with the 'override' keyword? It has zero effect on > object-oriented design in one direction or the other, and it helps avoiding > mistakes. So what's the problem? > > As for 'delete', do you prefer the old method of declaring automatically > generated functions as private? That was a bit of a kludge in the first place, > which '=delete' fixes. Now you have a much clearer way to tell the compiler > to not autogenerate those functions, and to get better error messages. As you can only focus on partial sight, like the cases of string manipulations in C. I cannot make it more clear for you.
[toc] | [prev] | [next] | [standalone]
| From | Juha Nieminen <nospam@thanks.invalid> |
|---|---|
| Date | 2021-04-23 07:34 +0000 |
| Message-ID | <s5tt9l$q2b$2@gioia.aioe.org> |
| In reply to | #79174 |
wij <wyniijj@gmail.com> wrote: >> > C++ has several places violated its original OO principle, this is just one example. >> > For instance, the added keyword override/final/delete (good, but it reflects the >> > half-true "object model" crap) violated the C++ author's ideal (or guideline) about a >> > a good language "...not add a new feature and then add another to disable it..." >> What exactly is the problem with the 'override' keyword? It has zero effect on >> object-oriented design in one direction or the other, and it helps avoiding >> mistakes. So what's the problem? >> >> As for 'delete', do you prefer the old method of declaring automatically >> generated functions as private? That was a bit of a kludge in the first place, >> which '=delete' fixes. Now you have a much clearer way to tell the compiler >> to not autogenerate those functions, and to get better error messages. > > As you can only focus on partial sight, like the cases of string manipulations in C. > I cannot make it more clear for you. Because I complain about dynamic string manipulation in C, you can't explain why you oppose C++ keywords like 'override' and 'delete'?
[toc] | [prev] | [next] | [standalone]
| From | wij <wyniijj@gmail.com> |
|---|---|
| Date | 2021-04-23 04:58 -0700 |
| Message-ID | <c3a5bc5f-1f10-443a-b508-b0a71f42af26n@googlegroups.com> |
| In reply to | #79188 |
On Friday, 23 April 2021 at 15:34:26 UTC+8, Juha Nieminen wrote:
> wij <wyn...@gmail.com> wrote:
> >> > C++ has several places violated its original OO principle, this is just one example.
> >> > For instance, the added keyword override/final/delete (good, but it reflects the
> >> > half-true "object model" crap) violated the C++ author's ideal (or guideline) about a
> >> > a good language "...not add a new feature and then add another to disable it..."
> >> What exactly is the problem with the 'override' keyword? It has zero effect on
> >> object-oriented design in one direction or the other, and it helps avoiding
> >> mistakes. So what's the problem?
> >>
> >> As for 'delete', do you prefer the old method of declaring automatically
> >> generated functions as private? That was a bit of a kludge in the first place,
> >> which '=delete' fixes. Now you have a much clearer way to tell the compiler
> >> to not autogenerate those functions, and to get better error messages.
> >
> > As you can only focus on partial sight, like the cases of string manipulations in C.
> > I cannot make it more clear for you.
> Because I complain about dynamic string manipulation in C, you can't explain
> why you oppose C++ keywords like 'override' and 'delete'?
I did not oppose 'override','delete' (I like it, instead). The main point is the
language design principle or ideal avoiding "invent a new feature and then
another one to disable it...". In this case I refer to C++ inheritage ideal
("object model" crap.). This principle can extend further to be not so rightful,
as many ideals are.
std::string provides "helper functions" to manipulate "C-string"
(precisely speaking, this was an error of 'pure' C++, we are now actually
talking about an erroneous feature of C++), does not mean C is ugly.
Helper functions(or macro/template) come with cost (user usually do not care,
but note that it can accumulate) and can not cover all cases. You cannot use
memcpy/memmove in 'pure' C++.
As to the memory allocation issue, in extreme cases (real programs will encounter),
e.g. many string objects, or one long string, one might even need to use zero-terminate
c-string directly and RAII becomes a hinder.
[toc] | [prev] | [next] | [standalone]
Page 4 of 8 — ← Prev page 1 2 3 [4] 5 6 7 8 Next page →
Back to top | Article view | comp.lang.c++
csiph-web