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


Groups > comp.lang.c++ > #85853

Re: To C or not to C++

From David Brown <david.brown@hesbynett.no>
Newsgroups comp.lang.c++
Subject Re: To C or not to C++
Date 2022-08-11 13:53 +0200
Organization A noiseless patient Spider
Message-ID <td2qk0$25mc3$1@dont-email.me> (permalink)
References (1 earlier) <tcsrs5$tnp$1@gioia.aioe.org> <ygah72lu6nv.fsf@akutech.de> <tcutte$11jl$1@gioia.aioe.org> <tcvpc2$1p184$1@dont-email.me> <td1pb9$68h$1@gioia.aioe.org>

Show all headers | View raw


On 11/08/2022 04:25, Manfred wrote:
> On 8/10/2022 10:13 AM, David Brown wrote:
>> On 10/08/2022 02:25, Manfred wrote:
>>> On 8/9/2022 11:07 AM, Ralf Fassel wrote:
>>>> * Juha Nieminen <nospam@thanks.invalid>
>>>> | I have never even heard of the "sketch" language so I can't comment.
>>>> | If I had to make a completely wild guess it's probably some kind of
>>>> | "higher-level" language with its own pros and cons compared to both
>>>> | C and C++.
>>>>
>>>> On the Arduino, you usually only write the loop() (in C/C++)
>>>
>>> Note that the expression (C/C++) is considered a Bad Word nowadays.
>>
>> That wording implies that it was once a more acceptable term - I don't 
>> think anyone knowledgable in the two languages has been happy about 
>> conflating them.  (It's fine to say "C /and/ C++", or "C /or/ C++".)
> 
> I first heard of C++ in the late '80s, and it was described to me as: 
> "It's C, wherein structs can contain functions" (which sounded 
> immediately as a cool feature to me).
> At that time C/C++ was not a Bad Word™, and I think this was justified, 
> for 2 main reasons:
> - C++ was still relatively young, and the view of C++ as a mere 
> evolution of C was still diffuse. It would take some more time for C++ 
> programmers to gain more maturity and fully grasp the different 
> landscape of the two (see how many are still arguing that C code is C++ 
> code as well, even today)
> - C++11 had not happened, yet.
> 
> Today, none of the above is true.

Yes, C++ was originally "C with classes", and it is not unreasonable to 
have used the term "C/C++" in those early days.  I was thinking from the 
time when C++ became more established and standardised as a language of 
choice for a lot of types of development.  But I take your point.

> 
>>
>> But a lot of people with less knowledge and experience do mix the 
>> language names, and think of them as variants or at least that C++ is 
>> just "C with some extra features".  And the Arduino targets relative 
>> beginners, and goes out of its way to try to hide that kind of 
>> "complexity" from users.
>>
>>> The fact is that, even if in principle a C code fragment can be 
>>> compiled as C++ code, which might suggest the two languages are 
>>> closely related, in truth they are now very different languages, so 
>>> that they can't be mixed with each other.
>>
>> They /are/ very closely related languages - and most well-written C 
>> code can be turned into working C++ code with only a few changes (such 
>> as casting the result of calls to malloc - the casts are perfectly 
>> fine in C, but not idoimatic) and without a change in functionality.  
>> C is the base language on which C++ builds.
> 
> I disagree. If you program in C++, i.e. you model a problem domain in 
> C++ from scratch, then you end up with a /very/ different result than 
> you would if you used C.
> 

C++ is multi-paradigm.  There is no single "C++ way" to model a task or 
program.  It can be done in lots of different ways, depending on the 
task and the people working on it.  The same applies to a fair extent to 
C - I have seen plenty of C programs that are object oriented in design, 
or event based, or have "actors" passing messages between them, or many 
other ways to organise the C code.  It may be true that much of C 
programming is "plain imperative" - sets of functions that do things. 
But it is not restricted to that.

Now, C++ certainly makes many other types of code structure and task 
modelling easier - more natural in the language, more efficient to 
write, more efficient at run-time, and better static checking.  So when 
deciding how to attack a programming task, you might pick different 
approaches with C++ than with C, because of different balances in what 
fits well with the language.  But equally you might not do so - if the 
problem lends itself to an imperative approach, you can do that in C++ 
too (and take advantage of better typing and other features that C does 
not have).


>>
>> And yes they /can/ be mixed, and they /are/ mixed.  C++ is designed to 
>> be easy to mix with C, and incompatibilities are not made without good 
>> reason.  Indeed, a good deal of the things people dislike about C++, 
>> or that are not "good modern language design", trace back to 
>> compatibility with C.
> 
> What I mean by "mixed" here is in fact "confused". Nothing to do with 
> C++ calling C functions, and vice versa (however this might be 
> accomplished)
> 

Well, in that sense the languages most certainly /can/ be "mixed" - it 
is done regularly.  What you mean, I think, is that they should not be 
mixed - you feel a programmer should either think, model and design in a 
"C way" and program in C, or they should think, model and design in a 
"C++ way" and program in C++.

While I think there is something in that argument, I don't see it as 
clear-cut or absolute.

>>
>> One area of programming where C and C++ are regularly mixed, is 
>> resource-constrained embedded systems.  You can easily have a project 
>> with an RTOS in C90, some libraries in C99, application code in C++ of 
>> some sort, drivers in modern C - a full mix.  Typically the only code 
>> that is compiled as both C and C++ is the C headers, but you sometimes 
>> get more complicated headers that provide different features depending 
>> on the language at the time.
> 
> Well, I think you agree that a C++ application using a C library is not 
> really about mixing the two languages, don't you?
> 

In embedded systems like this, everything is compiled together.  Even if 
you don't touch the library source code itself, it's common to have 
hooks, user-defined macros, callbacks, and other connections so that the 
library code can absolutely be using the programmer's own code.  Plenty 
of mixing goes on.

>>
>>
>>> If you are writing code that compiles both as C and C++, then you are 
>>> in fact writing C code, not C++.
>>
>> That's just silly.  You are, in fact, writing code that is C code 
>> /and/ C++ code.  It might not be idiomatic code, but it is perfectly 
>> valid.
> 
> Again, I disagree. And it is not silly.
> 
> Let's take an example that makes some sense: you write some code that 
> involves a linked list (or any other container, for that matter) - 
> consider a C implementation and a C++ implementation.
> 
> Are you seriously arguing that the C implementation is a C++ 
> implementation just as well?
> (Please note that I /know/ that the C implementation would be legal C++ 
> code. I'm just saying that if you write such a C implementation in a C++ 
> program, then you are Doing It Wrong™)
> 

I appreciate what you are saying - I just think it is blatantly 
incorrect to say the code is "C, not C++".  What you mean is that it is 
not /idiomatic/ C++ code.  It is not code written in a way that /you/ 
would write it in C++.

C++ is used in a huge range of systems, with a huge range of different 
requirements.  You think that if someone needed a dynamically resizeable 
list of items, in C++ they'd always reach for a std::vector while in C 
they'd write it themselves, and therefore the languages are different. 
When I program in C++, if I needed such a list I'd write it myself, far 
closer to what you think of as "C style".  The standard library 
std::vector will not do what I need it to do, so I would not use it. 
But what I write would still be C++.

Back to comp.lang.c++ | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

To C or not to C++ NOSPAM.Alan.Beck@darkrealms.ca (Alan Beck) - 2022-08-08 09:43 +0000
  Re: To C or not to C++ Paavo Helde <eesnimi@osa.pri.ee> - 2022-08-08 20:02 +0300
  Re: To C or not to C++ Juha Nieminen <nospam@thanks.invalid> - 2022-08-09 05:38 +0000
    Re: To C or not to C++ Ralf Fassel <ralfixx@gmx.de> - 2022-08-09 11:07 +0200
      Re: To C or not to C++ Manfred <noname@add.invalid> - 2022-08-10 02:25 +0200
        Re: To C or not to C++ Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2022-08-09 17:52 -0700
          Re: To C or not to C++ Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2022-08-09 21:39 -0700
            Re: To C or not to C++ Muttley@dastardlyhq.com - 2022-08-10 07:45 +0000
          Re: To C or not to C++ scott@slp53.sl.home (Scott Lurndal) - 2022-08-10 19:50 +0000
            Re: To C or not to C++ Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2022-08-10 13:13 -0700
            Re: To C or not to C++ Manfred <noname@add.invalid> - 2022-08-11 04:29 +0200
        Re: To C or not to C++ Juha Nieminen <nospam@thanks.invalid> - 2022-08-10 02:41 +0000
        Re: To C or not to C++ Muttley@dastardlyhq.com - 2022-08-10 07:39 +0000
          Re: To C or not to C++ Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2022-08-10 10:11 -0700
            Re: To C or not to C++ Muttley@dastardlyhq.com - 2022-08-12 08:23 +0000
              Re: To C or not to C++ Juha Nieminen <nospam@thanks.invalid> - 2022-08-12 12:12 +0000
                Re: To C or not to C++ Muttley@dastardlyhq.com - 2022-08-12 14:41 +0000
                Re: To C or not to C++ Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2022-08-12 12:09 -0700
                Re: To C or not to C++ David Brown <david.brown@hesbynett.no> - 2022-08-13 10:28 +0200
                Re: To C or not to C++ Muttley@dastardlyhq.com - 2022-08-13 09:37 +0000
              Re: To C or not to C++ Paavo Helde <eesnimi@osa.pri.ee> - 2022-08-12 15:55 +0300
                Re: To C or not to C++ Muttley@dastardlyhq.com - 2022-08-12 14:43 +0000
                Re: To C or not to C++ Paavo Helde <eesnimi@osa.pri.ee> - 2022-08-12 18:07 +0300
                Re: To C or not to C++ Muttley@dastardlyhq.com - 2022-08-12 15:14 +0000
                Re: To C or not to C++ Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2022-08-12 12:11 -0700
                Re: To C or not to C++ Muttley@dastardlyhq.com - 2022-08-13 09:38 +0000
                Re: To C or not to C++ David Brown <david.brown@hesbynett.no> - 2022-08-13 17:56 +0200
                Re: To C or not to C++ Paavo Helde <eesnimi@osa.pri.ee> - 2022-08-24 11:32 +0300
                Re: To C or not to C++ Ben Bacarisse <ben.usenet@bsb.me.uk> - 2022-08-24 11:33 +0100
                Re: To C or not to C++ Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2022-08-24 04:37 -0700
                Re: To C or not to C++ Ben Bacarisse <ben.usenet@bsb.me.uk> - 2022-08-24 13:31 +0100
                Re: To C or not to C++ Muttley@dastardlyhq.com - 2022-08-24 14:09 +0000
                Re: To C or not to C++ Ben Bacarisse <ben.usenet@bsb.me.uk> - 2022-08-24 15:31 +0100
                Re: To C or not to C++ Muttley@dastardlyhq.com - 2022-08-24 14:38 +0000
                Re: To C or not to C++ Ben Bacarisse <ben.usenet@bsb.me.uk> - 2022-08-24 15:57 +0100
                Re: To C or not to C++ Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2022-08-24 10:41 -0700
                Re: To C or not to C++ Ben Bacarisse <ben.usenet@bsb.me.uk> - 2022-08-24 21:48 +0100
                Re: To C or not to C++ "Alf P. Steinbach" <alf.p.steinbach@gmail.com> - 2022-08-25 07:34 +0200
                Re: To C or not to C++ Ben Bacarisse <ben.usenet@bsb.me.uk> - 2022-08-25 11:29 +0100
                Re: To C or not to C++ Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2022-08-25 04:14 -0700
                Re: To C or not to C++ Ben Bacarisse <ben.usenet@bsb.me.uk> - 2022-08-25 12:36 +0100
                Re: To C or not to C++ Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2022-08-25 05:16 -0700
                Re: To C or not to C++ Ben Bacarisse <ben.usenet@bsb.me.uk> - 2022-08-25 17:16 +0100
                Re: To C or not to C++ David Brown <david.brown@hesbynett.no> - 2022-08-25 20:35 +0200
                [OT] Bad CS course, no cookie (Was: To C or not to C++) Ben Bacarisse <ben.usenet@bsb.me.uk> - 2022-08-25 21:32 +0100
                Re: [OT] Bad CS course, no cookie (Was: To C or not to C++) David Brown <david.brown@hesbynett.no> - 2022-08-25 23:16 +0200
                Re: [OT] Bad CS course, no cookie Ben Bacarisse <ben.usenet@bsb.me.uk> - 2022-08-26 00:33 +0100
                Re: [OT] Bad CS course, no cookie David Brown <david.brown@hesbynett.no> - 2022-08-26 10:39 +0200
                Re: [OT] Bad CS course, no cookie Ben Bacarisse <ben.usenet@bsb.me.uk> - 2022-08-26 10:57 +0100
                Re: [OT] Bad CS course, no cookie David Brown <david.brown@hesbynett.no> - 2022-08-26 12:49 +0200
                Re: To C or not to C++ Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2022-08-25 19:56 -0700
                Re: To C or not to C++ David Brown <david.brown@hesbynett.no> - 2022-08-26 10:47 +0200
                Re: To C or not to C++ Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2022-08-26 02:48 -0700
                Re: To C or not to C++ David Brown <david.brown@hesbynett.no> - 2022-08-26 13:02 +0200
                Re: To C or not to C++ Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2022-08-26 04:57 -0700
                Re: To C or not to C++ David Brown <david.brown@hesbynett.no> - 2022-08-26 14:55 +0200
                Re: To C or not to C++ Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2022-08-26 06:20 -0700
                Re: To C or not to C++ Manfred <noname@add.invalid> - 2022-08-27 18:44 +0200
                Re: To C or not to C++ David Brown <david.brown@hesbynett.no> - 2022-08-28 11:30 +0200
                Re: To C or not to C++ Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2022-08-25 10:06 -0700
                Re: To C or not to C++ Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2022-08-25 10:32 -0700
                Re: To C or not to C++ Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2022-08-25 11:36 -0700
                Re: To C or not to C++ David Brown <david.brown@hesbynett.no> - 2022-08-25 20:47 +0200
                Re: To C or not to C++ Manfred <noname@add.invalid> - 2022-08-26 03:11 +0200
                Re: To C or not to C++ David Brown <david.brown@hesbynett.no> - 2022-08-25 09:21 +0200
                Re: To C or not to C++ scott@slp53.sl.home (Scott Lurndal) - 2022-08-25 12:58 +0000
                Re: To C or not to C++ Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2022-08-25 10:23 -0700
                Re: To C or not to C++ David Brown <david.brown@hesbynett.no> - 2022-08-25 20:51 +0200
                Re: To C or not to C++ Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2022-08-25 12:14 -0700
                Re: To C or not to C++ scott@slp53.sl.home (Scott Lurndal) - 2022-08-24 13:56 +0000
                Re: To C or not to C++ Paavo Helde <eesnimi@osa.pri.ee> - 2022-08-24 17:18 +0300
                Re: To C or not to C++ Muttley@dastardlyhq.com - 2022-08-24 14:25 +0000
                Re: To C or not to C++ scott@slp53.sl.home (Scott Lurndal) - 2022-08-12 16:46 +0000
                Re: To C or not to C++ Juha Nieminen <nospam@thanks.invalid> - 2022-08-15 06:16 +0000
                Re: To C or not to C++ Muttley@dastardlyhq.com - 2022-08-15 19:01 +0000
                Re: To C or not to C++ Bo Persson <bo@bo-persson.se> - 2022-08-15 22:22 +0200
                Re: To C or not to C++ David Brown <david.brown@hesbynett.no> - 2022-08-16 08:48 +0200
                Re: To C or not to C++ Muttley@dastardlyhq.com - 2022-08-16 19:19 +0000
                Re: To C or not to C++ Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2022-08-16 12:56 -0700
                Re: To C or not to C++ Muttley@dastardlyhq.com - 2022-08-17 18:47 +0000
                Re: To C or not to C++ Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2022-08-17 14:49 -0700
                Re: To C or not to C++ Muttley@dastardlyhq.com - 2022-08-18 14:49 +0000
                Re: To C or not to C++ Manfred <noname@add.invalid> - 2022-08-19 03:10 +0200
                Re: To C or not to C++ d thiebaud <thiebauddick2@aol.com> - 2022-08-18 22:12 -0400
                Re: To C or not to C++ Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2022-08-18 20:08 -0700
                Re: To C or not to C++ Muttley@dastardlyhq.com - 2022-08-19 10:39 +0000
                Re: To C or not to C++ Juha Nieminen <nospam@thanks.invalid> - 2022-08-17 06:45 +0000
                Re: To C or not to C++ Muttley@dastardlyhq.com - 2022-08-17 18:48 +0000
                Re: To C or not to C++ Muttley@dastardlyhq.com - 2022-08-16 19:16 +0000
              Re: To C or not to C++ Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2022-08-12 12:03 -0700
        Re: To C or not to C++ David Brown <david.brown@hesbynett.no> - 2022-08-10 10:13 +0200
          Re: To C or not to C++ Manfred <noname@add.invalid> - 2022-08-11 04:25 +0200
            Re: To C or not to C++ Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2022-08-11 01:03 -0700
            Re: To C or not to C++ Juha Nieminen <nospam@thanks.invalid> - 2022-08-11 08:11 +0000
            Re: To C or not to C++ David Brown <david.brown@hesbynett.no> - 2022-08-11 13:53 +0200
              Re: To C or not to C++ Manfred <noname@add.invalid> - 2022-08-13 04:13 +0200
                Re: To C or not to C++ David Brown <david.brown@hesbynett.no> - 2022-08-13 21:13 +0200
                Re: To C or not to C++ Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2022-08-13 12:29 -0700
                Re: To C or not to C++ Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2022-08-13 13:12 -0700
                Re: To C or not to C++ David Brown <david.brown@hesbynett.no> - 2022-08-14 00:44 +0200
            Re: To C or not to C++ Öö Tiib <ootiib@hot.ee> - 2022-08-12 02:54 -0700
              Re: To C or not to C++ Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2022-08-12 12:12 -0700
                Re: To C or not to C++ Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2022-08-12 16:22 -0700
                Re: To C or not to C++ Öö Tiib <ootiib@hot.ee> - 2022-08-12 17:49 -0700
                Re: To C or not to C++ Manfred <noname@add.invalid> - 2022-08-13 03:16 +0200
                Re: To C or not to C++ Öö Tiib <ootiib@hot.ee> - 2022-08-13 09:08 -0700
                Re: To C or not to C++ Tim Rentsch <tr.17687@z991.linuxsc.com> - 2022-08-15 14:44 -0700
        Re: To C or not to C++ Ralf Fassel <ralfixx@gmx.de> - 2022-08-10 12:06 +0200
        Re: To C or not to C++ Juha Nieminen <nospam@thanks.invalid> - 2022-08-11 07:04 +0000
  Re: To C or not to C++ Bonita Montero <Bonita.Montero@gmail.com> - 2022-08-09 12:31 +0200
    Re: To C or not to C++ Muttley@dastardlyhq.com - 2022-08-09 15:59 +0000
    Re: To C or not to C++ Frederick Virchanza Gotham <cauldwell.thomas@gmail.com> - 2022-08-19 04:09 -0700
  Re: To C or not to C++ "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2022-08-13 12:17 -0700
  Re: To C or not to C++ "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2022-08-27 23:15 -0700

csiph-web