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 3 of 8 — ← Prev page 1 2 [3] 4 5 6 7 8 Next page →
| From | Chris Vine <chris@cvine--nospam--.freeserve.co.uk> |
|---|---|
| Date | 2021-04-23 11:01 +0100 |
| Message-ID | <20210423110153.31d2181481261b6531424bcb@cvine--nospam--.freeserve.co.uk> |
| In reply to | #79186 |
On Fri, 23 Apr 2021 07:20:39 +0000 (UTC) Juha Nieminen <nospam@thanks.invalid> wrote: > Chris Vine <chris@cvine--nospam--.freeserve.co.uk> wrote: > > You are simply not > > going to get very far in C++ if you don't understand C strings. > > The problem in this case is not understanding how C strings work, but > managing dynamically allocated (and length-changing) strings. That as well then. First, if beginners are to write their own RAII classes effectively, they need to know how dynamically allocated memory works; and secondly beginners cannot I believe call themselves even moderately competent until they understand RAII, as it is so fundamental in C++. I would go further and say that a beginner cannot properly understand the use of std::unique_ptr and std::shared_ptr without understanding both dynamically allocated memory and RAII. Also, I do not believe that either dynamically allocated memory or RAII are difficult concepts for a beginner to understand, once object lifetime is grasped.
[toc] | [prev] | [next] | [standalone]
| From | Paavo Helde <myfirstname@osa.pri.ee> |
|---|---|
| Date | 2021-04-23 15:44 +0300 |
| Message-ID | <s5uffl$7e4$1@dont-email.me> |
| In reply to | #79194 |
23.04.2021 13:01 Chris Vine kirjutas: > On Fri, 23 Apr 2021 07:20:39 +0000 (UTC) > Juha Nieminen <nospam@thanks.invalid> wrote: >> Chris Vine <chris@cvine--nospam--.freeserve.co.uk> wrote: >>> You are simply not >>> going to get very far in C++ if you don't understand C strings. >> >> The problem in this case is not understanding how C strings work, but >> managing dynamically allocated (and length-changing) strings. > > That as well then. > > First, if beginners are to write their own RAII classes effectively, > they need to know how dynamically allocated memory works; and secondly > beginners cannot I believe call themselves even moderately competent > until they understand RAII, as it is so fundamental in C++. > > I would go further and say that a beginner cannot properly understand > the use of std::unique_ptr and std::shared_ptr without understanding > both dynamically allocated memory and RAII. Also, I do not believe > that either dynamically allocated memory or RAII are difficult > concepts for a beginner to understand, once object lifetime is grasped. This is all fine and good, but missing a point that this is all not needed for beginners for just using some strings. In C++ a string is effectively a simple scalar value object as it should be, there are no issues with dynamic allocation, lifetime or RAII. Yes, the *implementation* of strings does use all of this, but this has no relevance for beginners. There are tons of other things in C++ to learn, the implementation of strings can be well postponed. It has absolutely no importance to a beginner that a string is technically stored as an array of bytes somewhere.
[toc] | [prev] | [next] | [standalone]
| From | Chris Vine <chris@cvine--nospam--.freeserve.co.uk> |
|---|---|
| Date | 2021-04-23 17:52 +0100 |
| Message-ID | <20210423175202.1b87da4d73c3ccf57ae9e520@cvine--nospam--.freeserve.co.uk> |
| In reply to | #79199 |
On Fri, 23 Apr 2021 15:44:36 +0300 Paavo Helde <myfirstname@osa.pri.ee> wrote: > 23.04.2021 13:01 Chris Vine kirjutas: > > On Fri, 23 Apr 2021 07:20:39 +0000 (UTC) > > Juha Nieminen <nospam@thanks.invalid> wrote: > >> Chris Vine <chris@cvine--nospam--.freeserve.co.uk> wrote: > >>> You are simply not > >>> going to get very far in C++ if you don't understand C strings. > >> > >> The problem in this case is not understanding how C strings work, but > >> managing dynamically allocated (and length-changing) strings. > > > > That as well then. > > > > First, if beginners are to write their own RAII classes effectively, > > they need to know how dynamically allocated memory works; and secondly > > beginners cannot I believe call themselves even moderately competent > > until they understand RAII, as it is so fundamental in C++. > > > > I would go further and say that a beginner cannot properly understand > > the use of std::unique_ptr and std::shared_ptr without understanding > > both dynamically allocated memory and RAII. Also, I do not believe > > that either dynamically allocated memory or RAII are difficult > > concepts for a beginner to understand, once object lifetime is grasped. > > This is all fine and good, but missing a point that this is all not > needed for beginners for just using some strings. In C++ a string is > effectively a simple scalar value object as it should be, there are no > issues with dynamic allocation, lifetime or RAII. > > Yes, the *implementation* of strings does use all of this, but this has > no relevance for beginners. There are tons of other things in C++ to > learn, the implementation of strings can be well postponed. It has > absolutely no importance to a beginner that a string is technically > stored as an array of bytes somewhere. Sure, but that was not my point. In the thread to which I was replying, a beginner's struggles with string manipulation was used as a proxy for the argument that C, although much smaller as a language than C++, is not simpler than C++ and that C++ is easier to learn. My view is that that is an unhelpful proxy: C++ may postpone the day when the beginner has to expand her knowledge to include issues such as the resource management which caused the beginner's misunderstandings with string manipulation in C, but not by much. In my view, as I said, "both languages are difficult for beginners and require a high degree of skill to use well". To digress, I will certainly agree that C++'s ubiquitous use of RAII reduces the mistake count as compared with the equivalent code in C, but I don't think that that was the point being made.
[toc] | [prev] | [next] | [standalone]
| From | Juha Nieminen <nospam@thanks.invalid> |
|---|---|
| Date | 2021-04-26 04:55 +0000 |
| Message-ID | <s65h3k$1l87$1@gioia.aioe.org> |
| In reply to | #79202 |
Chris Vine <chris@cvine--nospam--.freeserve.co.uk> wrote: > Sure, but that was not my point. In the thread to which I was > replying, a beginner's struggles with string manipulation was used as a > proxy for the argument that C, although much smaller as a language than > C++, is not simpler than C++ and that C++ is easier to learn. I actually made no point about learning. My point was about usage. It doesn't make a difference whether it's a complete beginner or someone who has programmed with both languages for decades. I myself have done the latter, and I still find C++ significantly easier and simpler to program with. When it comes to dynamic strings, I'll use std::string. It's not just some kind of "beginner tool" that's useful only until you learn the "better way". std::string *is* the better way. And it so happens to also be the more beginner-friendly way. (That doesn't mean I never use char* to do things with strings. Of course I do. I know quite well how both ways work internally, and when it's better to use which. Use the best tool for the task at hand.)
[toc] | [prev] | [next] | [standalone]
| From | Chris Vine <chris@cvine--nospam--.freeserve.co.uk> |
|---|---|
| Date | 2021-04-26 22:16 +0100 |
| Message-ID | <20210426221645.9dc059e284ee5cc33c4a3213@cvine--nospam--.freeserve.co.uk> |
| In reply to | #79261 |
On Mon, 26 Apr 2021 04:55:18 +0000 (UTC) Juha Nieminen <nospam@thanks.invalid> wrote: > Chris Vine <chris@cvine--nospam--.freeserve.co.uk> wrote: > > Sure, but that was not my point. In the thread to which I was > > replying, a beginner's struggles with string manipulation was used as a > > proxy for the argument that C, although much smaller as a language than > > C++, is not simpler than C++ and that C++ is easier to learn. > > I actually made no point about learning. My point was about usage. I don't agree. Your original post was on a mission, and I can only read the words you use. You employed as a case study that of a beginner struggling with string manipulation. See your original post (17 Apr 2021 05:56:42 +0000). You may have picked an example not well fitting to the point you were hoping to make, but so be it. If you were concerned with usage not with learning, you might have been better served by choosing a case study involving an experienced programmer. For an experienced C and C++ programmer, if all you are doing is string manipulation, then as I have already said std::string is easier to use. You agree with me. I have also said that RAII improves the error rate with respect to resource management as compared with C. You agree with that too. I also said that building classes for RAII requires you to understand the resource management issues that your beginner found difficulty grasping. My basic position that you disagreed with was that "Both languages are difficult for beginners and require a high degree of skill to use well". I stand by it. For code which is not performance critical the managed languages are considerably easier to use. But no language exempts you from the need to get your algorithms right.
[toc] | [prev] | [next] | [standalone]
| From | Manfred <noname@add.invalid> |
|---|---|
| Date | 2021-04-22 16:30 +0200 |
| Message-ID | <s5s1as$e9g$1@gioia.aioe.org> |
| In reply to | #79157 |
On 4/22/2021 10:45 AM, Juha Nieminen wrote: > The only arguments I have seen from C programmers against my original post > have been "use this non-standard extension to make the language better > (not that C is bad and needs any extensions to make it better)". > Not a single actual refutation to my original point: Which one is simpler > from a beginner programmer's perspective, std::string in C++, or raw char > arrays in C (for which standard C offers pretty much no tools to make > their memory management easier or more automatic). For what is worth, my argument is somewhat different: If you try to use a design that would be well suited for C++, it is no surprise that the same design will lead to frustration if attempted with in C. Again, despite their name, the languages are very different. In addition, there are well known ways to do OO programming in C, but from the examples you described your attempt was to replicate in C some C++ code style instead, with all the clumsiness that may be expected from such approach. C and C++ have both their strong suits (I am not talking about performance only) - the fact that string manipulation has a much more comprehensive support in C++ does not make C++ a better language in absolute terms, the same applies to containers, the standard library and all the bells and whistles of C++ - all of these are useful features, but they are only relevant if actually essential to the problem domain, otherwise they constitute extra baggage that is best not paid for. One field where C++ really stands up, IMO, is templates and generic programming - here the life of a C programmer would get really miserable, but again, it is only as useful as what you are building actually needs it. (for the record, I have have been using C++ much more than C in my career, and almost exclusively C++ in more recent years - this is to say that I am probably not the most keen of C fans) > > The irony here is that the C programmers making that argument are tacitly > admitting C to be limited and defective, and in bad need for extensions that > would make it better and easier to use. While still strongly maintaining > that it doesn't. It is true that the feature portfolio of C++ is considerably larger than that of C. As far as I am concerned, this is only a benefit if your problem domain needs such extra features, otherwise it is actually a drawback. https://www.stroustrup.com/P0977-remember-the-vasa.pdf
[toc] | [prev] | [next] | [standalone]
| From | Juha Nieminen <nospam@thanks.invalid> |
|---|---|
| Date | 2021-04-23 07:32 +0000 |
| Message-ID | <s5tt6a$q2b$1@gioia.aioe.org> |
| In reply to | #79170 |
Manfred <noname@add.invalid> wrote: > If you try to use a design that would be well suited for C++, it is no > surprise that the same design will lead to frustration if attempted with > in C. Again, despite their name, the languages are very different. The attempt to modularize, abstract away, the dynamic memory management of strings is much better than trying to manage all that mess directly in the code that's using those strings, by using just raw char pointers and trying to always do the right thing in-line (such as reallocating, copying, appending, shrinking, freeing...). It only makes sense to create helper functions for all the needed string operations, and for those functions to operate on a struct that contains any necessary data to manage the string (such as its current length and its allocated capacity). I can't think of a better way that makes the code simpler and easier. This is *not* a case of "trying to do C++ in C". This is a case of trying to use *modular design* in C. To use abstractions that make it much easier and safer to manage dynamically allocated length-changing strings. > C and C++ have both their strong suits (I am not talking about > performance only) - the fact that string manipulation has a much more > comprehensive support in C++ does not make C++ a better language in > absolute terms, the same applies to containers, the standard library and > all the bells and whistles of C++ - all of these are useful features, > but they are only relevant if actually essential to the problem domain, > otherwise they constitute extra baggage that is best not paid for. I can't think of many situations where C shines over C++. Perhaps some kind of minor argument could be presented about C having the 'resrtict' keyword, which C++ lacks. Or about VLAs. But I'm not sure those would be reason enough to choose C over C++ regardless of the task at hand. I program in both C++ and C as my job. C is usually chosen when there are no other options (such as when programming for certain 8-bit embedded processors). Quite often (and fortunately) when C is the only viable opion, the hardware is so limited that dynamic memory allocation is usually out of the question, so the C code is restricted to fully static memory management, which is largely non-problematic and quite straightforward. (In those 8-bit processors you usually don't even need any dynamic memory allocation at any point.) C is ok of a language to program with in such restricted situations.
[toc] | [prev] | [next] | [standalone]
| From | Manfred <noname@add.invalid> |
|---|---|
| Date | 2021-04-23 20:35 +0200 |
| Message-ID | <s5v42a$1o4r$1@gioia.aioe.org> |
| In reply to | #79187 |
On 4/23/2021 9:32 AM, Juha Nieminen wrote:
> Manfred <noname@add.invalid> wrote:
>> If you try to use a design that would be well suited for C++, it is no
>> surprise that the same design will lead to frustration if attempted with
>> in C. Again, despite their name, the languages are very different.
>
> The attempt to modularize, abstract away, the dynamic memory management of
> strings is much better than trying to manage all that mess directly in the
> code that's using those strings, by using just raw char pointers and trying
> to always do the right thing in-line (such as reallocating, copying,
> appending, shrinking, freeing...). It only makes sense to create helper
> functions for all the needed string operations, and for those functions to
> operate on a struct that contains any necessary data to manage the string
> (such as its current length and its allocated capacity).
>
> I can't think of a better way that makes the code simpler and easier.
These are design goals that make sense in many domains.
My point is that they /can/ be used in C as well, although, granted,
considerably more verbosely than in C++.
However, the way to do this in C is not how it looks you were trying to
do it from the sketches you presented:
> String str1 = String_with_cstr("hello");
> String str2 = str1;
>
> This is *not* a case of "trying to do C++ in C".
I think it is. We may agree to disagree - just my view of it.
This is a case of trying
> to use *modular design* in C. To use abstractions that make it much easier
> and safer to manage dynamically allocated length-changing strings.
And I don't think the proper way to use modular design in C is how you
sketched it. Again, just my perspective.
>
>> C and C++ have both their strong suits (I am not talking about
>> performance only) - the fact that string manipulation has a much more
>> comprehensive support in C++ does not make C++ a better language in
>> absolute terms, the same applies to containers, the standard library and
>> all the bells and whistles of C++ - all of these are useful features,
>> but they are only relevant if actually essential to the problem domain,
>> otherwise they constitute extra baggage that is best not paid for.
>
> I can't think of many situations where C shines over C++.
- Stability
- Portability
- Interoperability
- Availability
As I said earlier, I put performance aside because it is often
overestimated, and most of the times C and C++ are on par. Smaller
runtime footprint is maybe the most common plus of C in this respect.
>
> Perhaps some kind of minor argument could be presented about C having
> the 'resrtict' keyword, which C++ lacks. Or about VLAs. But I'm not
> sure those would be reason enough to choose C over C++ regardless of
> the task at hand.
If you look at the language syntax and semantics, then strictly speaking
for the most part C is a subset of C++. (although what of C++ is outside
C is so huge that the way the two languages are meant to be used is
substantially different)
The comparison would be about how much value is added by the extra
features of C++ (which is a huge amount) compared to the cost of
handling them (learn/design/maintain). Obviously this is heavily
dependent on the problem domain.
>
> I program in both C++ and C as my job. C is usually chosen when there
> are no other options (such as when programming for certain 8-bit
> embedded processors). Quite often (and fortunately) when C is the only
> viable opion, the hardware is so limited that dynamic memory allocation
> is usually out of the question, so the C code is restricted to fully
> static memory management, which is largely non-problematic and quite
> straightforward. (In those 8-bit processors you usually don't even need
> any dynamic memory allocation at any point.)
>
> C is ok of a language to program with in such restricted situations.
>
I have seen successful large projects in C, mostly back end services.
[toc] | [prev] | [next] | [standalone]
| From | Juha Nieminen <nospam@thanks.invalid> |
|---|---|
| Date | 2021-04-26 05:01 +0000 |
| Message-ID | <s65hfh$1opn$1@gioia.aioe.org> |
| In reply to | #79204 |
Manfred <noname@add.invalid> wrote: > I have seen successful large projects in C, mostly back end services. Of course there are successful C projects. The Linux kernel is written almost entirely in C. I haven't really looked at the source code but I wouldn't be surprised if it's relatively clean and easy to undrestand (at least for the most part). Many large projects like gcc and clang are written mostly in C. There are many other examples. The question is not really whether a large project *can* be written in C.
[toc] | [prev] | [next] | [standalone]
| From | Juha Nieminen <nospam@thanks.invalid> |
|---|---|
| Date | 2021-04-20 04:56 +0000 |
| Message-ID | <s5lmth$1vlu$1@gioia.aioe.org> |
| In reply to | #79080 |
wij <wyniijj@gmail.com> wrote: > Such kind of topic (like, C/C++ which one is better) had been heavily discussed > several times before, in ways like debating which religion is better. > Just do not be overly zealous. The thing that prompted me to vent my frustrations in this thread was, as I mentioned in my original post, a recent attempt at helping a beginner who wanted to learn C. It's hard to convey the difficulty and frustration trying to do this, during the several days of trying to explain things and teach a good proper approach at this type of C development, especially given the kind of project that this person was trying to create (ie. a simple text editor that loads a text file and allows the user to make edits to it). During the ordeal I just couldn't help but to think, and to comment several times, how utterly and radically easier the very things he was trying to do would be in C++, using std::string and std::vector. (But he wanted to learn C specifically, I'm not sure exactly why.) It was not only difficult to try to explain how dynamic memory allocation works in C, and how such string manipulation should be approached, but also it was difficult to explain *why* it should be approached like that (ie. the idea of creating a more abstract reusable "module" for handling dynamically allocated strings). I would have been able to write such a program, but it was very difficult to teach a complete beginner to do so (other than just giving all the code readymade, which kind of defeats the purpose). This whole thing just reminded me of *why* I dislike C so much. Sometimes, even oftentimes, doing things that are extraordinarily simple in other languages (such as C++) are really laborious and error-prone in C, and require a level of knowledge, understanding and care that in general you don't need in those other languages. This is not the first time that pretty much this exact thing has happened to me. It was merely the latest reminder and refresher.
[toc] | [prev] | [next] | [standalone]
| From | wij <wyniijj@gmail.com> |
|---|---|
| Date | 2021-04-20 05:22 -0700 |
| Message-ID | <7a4dbbaf-c043-4abb-b407-789f89122cacn@googlegroups.com> |
| In reply to | #79105 |
On Tuesday, 20 April 2021 at 12:56:34 UTC+8, Juha Nieminen wrote: > wij <wyn...@gmail.com> wrote: > > Such kind of topic (like, C/C++ which one is better) had been heavily discussed > > several times before, in ways like debating which religion is better. > > Just do not be overly zealous. > The thing that prompted me to vent my frustrations in this thread was, as > I mentioned in my original post, a recent attempt at helping a beginner > who wanted to learn C. > > It's hard to convey the difficulty and frustration trying to do this, > during the several days of trying to explain things and teach a good > proper approach at this type of C development, especially given the > kind of project that this person was trying to create (ie. a simple > text editor that loads a text file and allows the user to make > edits to it). > Those are common problems to teach that kind level of C beginners. Nothing to surprise or be frustrated. A minimal functional text editor (like nano) is not simple from ground up. I do not think using 'pure' C++ (Smart Macro Library or STL) can do the job 'elegantly' and 'efficiently', as well as numerous system commands, with respect to using C. > During the ordeal I just couldn't help but to think, and to comment > several times, how utterly and radically easier the very things he > was trying to do would be in C++, using std::string and std::vector. > (But he wanted to learn C specifically, I'm not sure exactly why.) > It was not only difficult to try to explain how dynamic memory > allocation works in C, and how such string manipulation should be > approached, but also it was difficult to explain *why* it should > be approached like that (ie. the idea of creating a more abstract > reusable "module" for handling dynamically allocated strings). > > I would have been able to write such a program, but it was very difficult > to teach a complete beginner to do so (other than just giving all the > code readymade, which kind of defeats the purpose). > > This whole thing just reminded me of *why* I dislike C so much. Sometimes, > even oftentimes, doing things that are extraordinarily simple in other > languages (such as C++) are really laborious and error-prone in C, > and require a level of knowledge, understanding and care that in > general you don't need in those other languages. > > This is not the first time that pretty much this exact thing has happened > to me. It was merely the latest reminder and refresher. If we were talking some example programs from some C++ book, I have no comment.
[toc] | [prev] | [next] | [standalone]
| From | MrSpook_wb@g9b2a_ex9aicgvs04.net |
|---|---|
| Date | 2021-04-17 10:27 +0000 |
| Message-ID | <s5ed6m$1ad0$1@gioia.aioe.org> |
| In reply to | #78998 |
On Sat, 17 Apr 2021 05:56:42 +0000 (UTC) Juha Nieminen <nospam@thanks.invalid> wrote: >It quite quickly turned very frustrating for *both* of us that dynamic >string manipulation in C is so damn complicated, especially for a >complete beginner who has never programmed in C, and has only very >little experience even with other programming languages (he had some >very small experience with Python.) Umm, asprintf() >Now try to explain why that doesn't directly work (obviously causes >a compiler error), and try to think whether you should explain that >he *can* assign the string literal to the member char* of the struct >(remember to also update the length parameter) but once again how fraught >with peril that is, because now he will have to remember to *not* destruct >*this* particular object, or else bad things will happen. > >Then try to explain the concept of string capacity vs its length, >which is useful in this kind of module because of efficiency reasons >(and also because the string may become shorter, while retaining its >capacity). Any powerful language is hard to learn at the start. Try telling a beginner about C++ virtual function overloading or templates and watch the blank expression appear. However once someone DOES know C or C++ it all becomes 2nd nature.
[toc] | [prev] | [next] | [standalone]
| From | Juha Nieminen <nospam@thanks.invalid> |
|---|---|
| Date | 2021-04-18 16:30 +0000 |
| Message-ID | <s5hmqj$4k3$1@gioia.aioe.org> |
| In reply to | #79001 |
MrSpook_wb@g9b2a_ex9aicgvs04.net wrote: > On Sat, 17 Apr 2021 05:56:42 +0000 (UTC) > Juha Nieminen <nospam@thanks.invalid> wrote: >>It quite quickly turned very frustrating for *both* of us that dynamic >>string manipulation in C is so damn complicated, especially for a >>complete beginner who has never programmed in C, and has only very >>little experience even with other programming languages (he had some >>very small experience with Python.) > > Umm, asprintf() Use a non-standard-C non-posix compiler extension for... what, exactly? Doesn't help one bit with allocation and deallocation of string objects. If you are going to suggest functions that are not part of the standard language, you could just as well recommend using Python or something. > Any powerful language is hard to learn at the start. Try telling a beginner > about C++ virtual function overloading or templates and watch the blank > expression appear. Why? He wanted to make a simple text editor, which manipulates dynamically allocated strings. What do virtual functions or templates have anything to do with this?
[toc] | [prev] | [next] | [standalone]
| From | MrSpook_wyzaq1485z@solbi8e3oaumg9.gov.uk |
|---|---|
| Date | 2021-04-19 07:42 +0000 |
| Message-ID | <s5jc97$6f9$1@gioia.aioe.org> |
| In reply to | #79035 |
On Sun, 18 Apr 2021 16:30:13 +0000 (UTC) Juha Nieminen <nospam@thanks.invalid> wrote: >MrSpook_wb@g9b2a_ex9aicgvs04.net wrote: >> On Sat, 17 Apr 2021 05:56:42 +0000 (UTC) >> Juha Nieminen <nospam@thanks.invalid> wrote: >>>It quite quickly turned very frustrating for *both* of us that dynamic >>>string manipulation in C is so damn complicated, especially for a >>>complete beginner who has never programmed in C, and has only very >>>little experience even with other programming languages (he had some >>>very small experience with Python.) >> >> Umm, asprintf() > >Use a non-standard-C non-posix compiler extension for... what, exactly? Its a defacto function standard found on Linux, BSD and MacOS and thats good enough for me. >Doesn't help one bit with allocation and deallocation of string >objects. Sorry? Allocation of the correct size string for the format is its raison d'etre! >If you are going to suggest functions that are not part of the >standard language, you could just as well recommend using Python >or something. Sockets arn't part of the standard language so how would you suggest solving networking issues using the language? Inline assembler? >> Any powerful language is hard to learn at the start. Try telling a beginner >> about C++ virtual function overloading or templates and watch the blank >> expression appear. > >Why? He wanted to make a simple text editor, which manipulates dynamically >allocated strings. What do virtual functions or templates have anything >to do with this? *sigh* It helps if you read whats been written before replying.
[toc] | [prev] | [next] | [standalone]
| From | jacobnavia <jacob@jacob.remcomp.fr> |
|---|---|
| Date | 2021-04-17 17:43 +0200 |
| Message-ID | <s5evmn$2bp$1@dont-email.me> |
| In reply to | #78998 |
Le 17/04/2021 à 07:56, Juha Nieminen a écrit :
> I know that this is probably going to piss off avid C programmers,
> but I don't really care all that much.
>
It is funny how comic you look trying to convince people that C is
complicated, even more complicated than c++, imagine that. Obviously I
am one of those "avid" C programmers that never quite got into the c++
bandwagon.
> Many C fans keep insisting how C is so much better than C++ because
> C++ is so utterly complicated, with a standard that reads like a
> phonebook and a standard library so vast that nobody in their sane
> mind could ever even hope to remember all of it, and how C++ is
> becoming more and more complicated with every standard, and how
> C is such a simple, straightforward and beautiful language, so
> immensely better than C++.
>
The whole C language fits in your brain without overflowing it with
computer trivia. Try that with c++.
>
[snip]
> Also, trying to inculcate how wrong this is, and how important it is
> to avoid it:
>
> String str1 = String_with_cstr("hello");
> String str2 = String_with_cstr("there");
> str1 = str2; // No!
>
Did you try to explain him about why c++ has similar problems?
For instance:
#include <iostream>
#include <string>
#include <string_view>
int main() {
std::string s = "Hellooooooooooooooo ";
std::string_view sv = s + "World\n";
std::cout << sv;
}
Here, the expression s + "World" yields a std::string that is converted
to a string view and immediately freed. Each time you use the string
view you risk a segmentation fault.
Now, try to explain that to a beginner!
And of course you did NOT tell that beginner that he could avoid all
accounting problems with strings if ne NEVER frees any string and just
uses Boehm's GC that is available for C since more than a decade.
You are ignoring how to use C efficiently and using the right tools.
> He also asked why he couldn't do something like this:
>
> String str = "hello";
>
He could do:
const String str = { 5, "hello"};
But that is beyond the poor beginner's brain capacity or what?
Obviously assuming that writing a text editor for a guy that doesn't
know much about programming is an "easy" task is not an error from YOUR
side!
Nonsense really
[toc] | [prev] | [next] | [standalone]
| From | Juha Nieminen <nospam@thanks.invalid> |
|---|---|
| Date | 2021-04-18 16:39 +0000 |
| Message-ID | <s5hnbj$d0a$1@gioia.aioe.org> |
| In reply to | #79008 |
jacobnavia <jacob@jacob.remcomp.fr> wrote:
>> Also, trying to inculcate how wrong this is, and how important it is
>> to avoid it:
>>
>> String str1 = String_with_cstr("hello");
>> String str2 = String_with_cstr("there");
>> str1 = str2; // No!
>>
>
> Did you try to explain him about why c++ has similar problems?
I always love it when C programmers try to come up with the most
contrived ways to defend their beloved language.
You didn't actually give an argument of why C would be better for the
beginner in question than C++, who only wanted to create a simple text
editor that manipulates dynamically allocated strings. Instead, you
deliberately came up with a contrived example that has nothing to do
with it.
> And of course you did NOT tell that beginner that he could avoid all
> accounting problems with strings if ne NEVER frees any string and just
> uses Boehm's GC that is available for C since more than a decade.
Why not just recommend him to use Python, while we are at it? All the
problems solved.
The funny thing is that you seem to be completely oblivious to the fact
that you are trying to recommend a fix to a flaw in the language, while
still defending the language.
>> He also asked why he couldn't do something like this:
>>
>> String str = "hello";
>>
>
> He could do:
> const String str = { 5, "hello"};
>
> But that is beyond the poor beginner's brain capacity or what?
I already explained why that's such a horrible idea in C, when the
'String' struct is supposed to hold a dynamically allocated string
that you are supposed to destroy before it goes out of scope.
You are writing that as if I didn't know that.
[toc] | [prev] | [next] | [standalone]
| From | jacobnavia <jacob@jacob.remcomp.fr> |
|---|---|
| Date | 2021-04-18 20:48 +0200 |
| Message-ID | <s5hut3$ntt$1@dont-email.me> |
| In reply to | #79036 |
Le 18/04/2021 à 18:39, Juha Nieminen a écrit : > The funny thing is that you seem to be completely oblivious to the fact > that you are trying to recommend a fix to a flaw in the language, while > still defending the language. Obviously C strings are a flaw in the language. C is not the perfect language. C++ isn't flawless either. Python has the excellent idea that white space (tabulations) have a semantic meaning, imagine that... Rust has its "unsafe" keyword that voids any advantages the language may have, lisp has too much parenthesis for anybody's taste. Should I go on? Rants like this are completely sterile
[toc] | [prev] | [next] | [standalone]
| From | Manfred <noname@add.invalid> |
|---|---|
| Date | 2021-04-17 19:12 +0200 |
| Message-ID | <s5f4u8$1t7u$1@gioia.aioe.org> |
| In reply to | #78998 |
(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]
[toc] | [prev] | [next] | [standalone]
| From | Juha Nieminen <nospam@thanks.invalid> |
|---|---|
| Date | 2021-04-18 16:46 +0000 |
| Message-ID | <s5hnpu$k19$1@gioia.aioe.org> |
| In reply to | #79010 |
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).
[toc] | [prev] | [next] | [standalone]
| From | Manfred <noname@add.invalid> |
|---|---|
| Date | 2021-04-18 20:30 +0200 |
| Message-ID | <s5htsr$1jr9$1@gioia.aioe.org> |
| In reply to | #79037 |
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.
[toc] | [prev] | [next] | [standalone]
Page 3 of 8 — ← Prev page 1 2 [3] 4 5 6 7 8 Next page →
Back to top | Article view | comp.lang.c++
csiph-web