[HN Gopher] Improve type generic programming
       ___________________________________________________________________
        
       Improve type generic programming
        
       Author : signa11
       Score  : 24 points
       Date   : 2021-04-24 07:01 UTC (15 hours ago)
        
 (HTM) web link (gustedt.wordpress.com)
 (TXT) w3m dump (gustedt.wordpress.com)
        
       | pwdisswordfish8 wrote:
       | Having followed those proposals for a while, I can't help but
       | have the same question as the commenter over at the blog: at this
       | point, why not just use C++? The features proposed are already
       | present in C++, and the only C toolchains that I expect would
       | implement them already include a C++ compiler as well. The effort
       | to add those features to C as well seems like pointless busywork.
        
         | samatman wrote:
         | There is a lot of C code out there, right now, doing positively
         | Lovecraftian things with void pointers.
         | 
         | If they wanted to port the library to C++, they would have
         | already. This would let them use something common to the C
         | ecosystem, thus potentially harmonious with other libraries,
         | and hopefully bring some compiler-level discipline to the non-
         | Euclidean insanity.
        
         | david2ndaccount wrote:
         | C++ has a lot of nontrivial problems that make it not a clear
         | improvement over using C. These include things such as
         | exceptions, lack of abi stability, constructors, destructors
         | and greatly longer compile times (I once converted a project to
         | cleanly compile as both C and C++ and compiling as C++ took
         | twice as long).
         | 
         | Some of these features proposed in this paper would be simple
         | additions that have already been battle-tested in real
         | compilers (gcc and clang already have 'auto' by using
         | __auto_type, gcc and clang already have 'typeof'). I am less
         | sanguine about adding any form of capturing closures (by value
         | or by reference), but non-capturing function literals that get
         | desugared to anonymous static functions would be a usability
         | win.
        
         | flohofwoe wrote:
         | There is some value in harmonizing C and C++ a bit more,
         | without going full C++.
         | 
         | Personally I don't have a problem with the approach that C++
         | acts as an experimentation testbed for C to find the few good
         | language features that should eventually trickle into C after
         | they've proven their worth in real-world C++ codebases for at
         | least a decade or so ;)
        
         | pjmlp wrote:
         | Embedded developers and anyone that even at gun point won't
         | ever touch C++, like Linus.
         | 
         | And platforms that keep C alive like UNIX clones.
        
           | quotemstr wrote:
           | And the opposition these people feel to C++ is deeply
           | irrational. Sorry, but it's true: there's just no reason to
           | prefer C to C++ that stands up to scrutiny. Linus is dead
           | wrong and is just tripling down on stubbornness.
           | 
           | C++ doesn't cramp your style if you'd prefer to write C-style
           | code, but it gives you the power to do much more, and on your
           | own schedule and in your own way. Why on earth would you
           | _choose_ to use the much less capable plain C?
           | 
           | Christ, it's not like the moment you switch the compiler from
           | gcc to g++ a demon comes and bonks you over the head with the
           | GoF design patterns book. C++ can be as much like C as you
           | want.
        
             | dnautics wrote:
             | Suppose you are a c programmer and start a project in c++
             | and then someone joins your team and starts using a corner
             | of the language you are not well versed in. That can be a
             | very scary place.
        
               | quotemstr wrote:
               | Suppose you are a C programmer and someone joins and
               | starts using C in a way that you don't like. So what?
               | Deliberately using a crippled language is a poor
               | substitute for having code review and style standards.
        
               | pjmlp wrote:
               | Suppose you are a C89 programmer, and start a project in
               | C18, and then someone joins your team and starts using a
               | corner of the language you are not well versed in. That
               | can be a very scary place.
        
               | jstimpfle wrote:
               | You don't believe a single word of that yourself, do you
               | :-)
        
             | nytgop77 wrote:
             | in defense of linux people:
             | 
             | - more ways to do things -> more effort required to keep
             | somewhat uniform style
             | 
             | - linus and friends just get to decide. (they can be as
             | subjective as they want. The "their house their rules" kind
             | of thing).
             | 
             | - there is no "c/c++" language. there is c and there is
             | c++. they have different std libraries, different idioms,
             | and expert overlap is not that high.
             | 
             | - linux kernel even in c is a huge success - so c is good
             | enough for linux (enough kernel developers are comfortible
             | and productive with it).
             | 
             | - linux might have succeeded with cpp if it were used from
             | the start, but now it's too late. Migration to cpp is a no-
             | go: benefits do not outweigh costs (old code will not be
             | rewritten in cpp, so people maintaining code will now have
             | to be profficient in c AND cpp).
        
           | billfruit wrote:
           | Why would embedded developers ignore the huge amounts of
           | convenience given by C++ in organizing and structuring large
           | programs? Namespaces alone itself is sufficient reason to use
           | c++ than C in many contexts, and that is just one of the many
           | others provided by c++.
        
             | pjmlp wrote:
             | Because it is a culture pretty much anti-C++, to the point
             | that it is a common theme in C++ conferences how to succeed
             | selling C++ to those communities, for example,
             | 
             | "CppCon 2016: Dan Saks "extern c: Talking to C Programmers
             | about C++"
             | 
             | https://www.youtube.com/watch?v=D7Sd8A6_fYU
        
               | lpapez wrote:
               | Highly recommend watching this talk. The lessons conveyed
               | by the author will serve you well not only in
               | communication with C programmers, but communication with
               | anyone really :) As the first comment on the video says:
               | "I came here for a C++ talk, walked away with a life
               | lesson"
        
           | w4rh4wk5 wrote:
           | Do you think the people not using C++ would welcome the
           | proposed features in C? I personally doubt that, but that's
           | just a wild guess.
        
             | pjmlp wrote:
             | Most likely not, but that is their problem, C is no longer
             | Dennis and Thomson language for about 40 years now.
        
         | ddevault wrote:
         | Exactly this. The C++ committee needs to stay the hell away
         | from C.
        
       | ngrilly wrote:
       | At this point, what about using Zig instead?
        
         | dnautics wrote:
         | Aside from it being not 1.0 yet, I think this is the right
         | answer for the future.
        
           | crispyalmond wrote:
           | Once Zig hits 1.0 I'll have almost no need for C anymore. I
           | like what I've experienced when developing with Zig, and I
           | think it's neat.
        
       ___________________________________________________________________
       (page generated 2021-04-24 23:01 UTC)