Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. The Lounge
  3. I like C more than I thought I would

I like C more than I thought I would

Scheduled Pinned Locked Moved The Lounge
c++wpfiot
50 Posts 20 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D David ONeil

    First time I saw C I immediately liked it. The syntax made sense at a gut level. I had Fortran and Basic under my belt at that time, so not a lot of exposure to other languages, but it was non-case locked, and arbitrary length variable names were a godsend. But I still dislike two items about it. First is the typedefs that surround all structs in the MS headers. I still don't understand why that was done, although I never delved into it very much. The second is that everything has to be casted on both sides of the '='. That got old quick. I still like the language, though. C++ is far betterer! And when I finally understood true OOP in C++ I was in heaven!

    Our Forgotten Astronomy | Object Oriented Programming with C++ | Wordle solver

    U Offline
    U Offline
    User 13269747
    wrote on last edited by
    #38

    Quote:

    The second is that everything has to be casted on both sides of the '='. That got old quick.

    You must have first seen C back in the 80s? Since C99, anytime a cast is done in C it's a code-smell; casting should almost never be required.

    D 1 Reply Last reply
    0
    • U User 13269747

      Quote:

      I'd guess that the mantra "C is for embedded" is mostly because of legacy systems. There was also Embedded C++, which removed templates, exceptions, and RTTI. Memory is now so cheap that C is only justified in small systems.

      I tend to enforce it on my teams the other way around: provide a real justification for using C++ over C. It becomes very hard to justify using C++ over C for embedded projects that cannot use exceptions, as at that point you're into real implementation-defined behaviour which changes with the compiler being used, or even the flags passed to it. When C is not suitable for some problem space, I don't find myself reaching for C++ because there are much nicer languages. C++ is in this weird position - for very small embedded systems, C is better, for very large embedded systems (SBCs, for example), any other high-level language can be used. For uncrippled C++, the target needs to be larger than atmega level and smaller than Raspberry Pi level. Not a lot of need in that particular niche.

      Quote:

      I wouldn't sign onto a C project unless the team was small and disciplined. The risk of dealing with hacked-together code is simply too great.

      I would. C is one of the easier languages to unf***k. A C++ project that was hacked together can be very difficult to reason about (OTOH, A Lisp project that was hacked together may as well be thrown away)

      Greg UtasG Offline
      Greg UtasG Offline
      Greg Utas
      wrote on last edited by
      #39

      Our experiences are rather different. I worked on large, embedded systems (call servers) in a proprietary language that could be compared to C, though with better type safety and other things that made it a competitive advantage at the time. And later in the same language after it was extended in much the same way that C was extended to C++. Having the OO version of the language enabled much clearer frameworks to be defined, which eliminated superfluous diversity when it came to designs. And just like C++/C, legacy, non-OO code could be reused, or the non-OO subset of the language used when appropriate. Not being able to use exceptions is certainly a problem if using C++, but I don't know why they should be ruled out. They're far better than setjmp/longjmp. My "hacked together" comment wasn't really about languages, but about the attitude of developers who prefer C over C++. Too many of them are hotshots at the micro level but don't care about the abstractions that are needed in a large system. And I can't really blame them, because doing C++ types of things in C requires more boilerplate than even C++ has.

      Robust Services Core | Software Techniques for Lemmings | Articles
      The fox knows many things, but the hedgehog knows one big thing.

      <p><a href="https://github.com/GregUtas/robust-services-core/blob/master/README.md">Robust Services Core</a>
      <em>The fox knows many things, but the hedgehog knows one big thing.</em></p>

      1 Reply Last reply
      0
      • H honey the codewitch

        Martin ISDN wrote:

        C will set you free. the oldest dogmas i've heard were: goto is evil and macros are evil

        There's a time and a place for nearly everything (except Python :-D ). Macros make certain impossible things possible in C, like conditionally compiling code for different platforms, or setting compile time configuration parameters in the absence of templates. Gotos are pretty handy for state machines, where higher level constructs don't work because you can't jump in and out of while loops.

        Martin ISDN wrote:

        the most astonishing for me has always been "The arguments to functions are passed by copying the value of the argument, and it is impossible for the called function to change the actual argument in the caller"

        I'm surprised this astonished you, as it's the default in most any programming language including asm, where the most natural way to call is to put a *copy* of a value in a register or onto the stack. Indeed to pass by reference you need to put the *address* of the object in a register or on the stack. BASIC facilitates this using the Byref keyword, C# with the ref and out keywords, but it's pretty much always extra typing. The exception is arrays including strings, because you *reference* them (in C by referencing the first element), and while in theory you could push each element onto the stack in practice that's prohibitive.

        To err is human. Fortune favors the monsters.

        M Offline
        M Offline
        Martin ISDN
        wrote on last edited by
        #40

        honey the codewitch wrote: I'm surprised this astonished you, as it's the default in most any programming language including asm, where the most natural way to call is to put a *copy* of a value in a register or onto the stack. Indeed to pass by reference you need to put the *address* of the object in a register or on the stack. BASIC facilitates this using the Byref keyword, C# with the ref and out keywords, but it's pretty much always extra typing. The exception is arrays including strings, because you *reference* them (in C by referencing the first element), and while in theory you could push each element onto the stack in practice that's prohibitive. probably i wanted to give Dennis more credit than he deserves. once an idea like "i have underrated C, Dennis was more clever and foreseeing than i thought. he made the right compromises" appeared in my mind it is constantly working in the background trying to find new prof of greatness. cannot test it, but the BASICs on the home computers may have been default to pass by reference. that set the intuition that the function changes the callers arguments at very young age :( though, he made copy by value the only way to pass. except for that array! i often wonder at length, why he did so. the default way is to pass it by reference i suppose for economical reasons. there is a way to pass it by copy if you put it inside a struct. or simply, cast the array as a struct. i wish i could find some paper written by Ritchie about this or "the other things, not because they are easy, but because they are hard"

        1 Reply Last reply
        0
        • H honey the codewitch

          I've always been a C++ nerd. I came at C++ self taught, but I came at it fresh, without "graduating" from writing C code. I've never regarded C++ as OOP, but rather GP oriented, although in truth it's a chameleon, and can do pretty much anything. However, I make heavy use of template based programming. So I didn't think I'd enjoy C. I figured I'd miss templates. I still do. There is some real ugly in terms of things you have to do with C that are elegant in C++. That being said, I don't miss them as much as I thought I would. Also, using the preprocessor freely is kind of liberating. In C++ I use it only as a last resort. In C it's more first class for me. Anyway, I like C. I do wish it had templates! And it's kind of verbose, which is hard on the fingers (everything has a handle) but also it wasn't a huge transition for me, since I do a lot of IoT coding I don't use things like exceptions, nor do I make heavy use of the STL, so C wasn't so bad. :)

          To err is human. Fortune favors the monsters.

          C Offline
          C Offline
          Cpichols
          wrote on last edited by
          #41

          Back in the day, working for a NASA contractor, we were working on graphic representation of data from the engineering (FORTRAN) programs, which had to be done in C on massive UNIX machines. OOP was still a new concept, but we used the flexibility of C to create object-like arrays of data (okay, just the parameter part of objects, but with a suite of functions to support each). OOP was the natural progression, but I never did learn C++. Perhaps I should. The freedom of C is both scary and appealing to the megalomaniac in me; I always delighted in writing in it.

          1 Reply Last reply
          0
          • H honey the codewitch

            I've always been a C++ nerd. I came at C++ self taught, but I came at it fresh, without "graduating" from writing C code. I've never regarded C++ as OOP, but rather GP oriented, although in truth it's a chameleon, and can do pretty much anything. However, I make heavy use of template based programming. So I didn't think I'd enjoy C. I figured I'd miss templates. I still do. There is some real ugly in terms of things you have to do with C that are elegant in C++. That being said, I don't miss them as much as I thought I would. Also, using the preprocessor freely is kind of liberating. In C++ I use it only as a last resort. In C it's more first class for me. Anyway, I like C. I do wish it had templates! And it's kind of verbose, which is hard on the fingers (everything has a handle) but also it wasn't a huge transition for me, since I do a lot of IoT coding I don't use things like exceptions, nor do I make heavy use of the STL, so C wasn't so bad. :)

            To err is human. Fortune favors the monsters.

            J Offline
            J Offline
            Juan Pablo Reyes Altamirano
            wrote on last edited by
            #42

            My main language is C, although I've coded in C++ far longer. I don't use classes unless I have a very good reason to and on only one very specific occasion I used templates (I hate generics). That said I have to confess I come from the opposite end of programming. C is a very nice abstraction of assembler, with the added caveat of being portable and I have emulated objects in C using function pointers within structs. Despite the supposed (never seen it) security implications of void pointers, those are about as close as I can imagine to using generic data types in your functions (I do videogames so performance and efficiency always trumps readability...and security will always be an afterthought) Anyways welcome :)

            1 Reply Last reply
            0
            • H honey the codewitch

              I've always been a C++ nerd. I came at C++ self taught, but I came at it fresh, without "graduating" from writing C code. I've never regarded C++ as OOP, but rather GP oriented, although in truth it's a chameleon, and can do pretty much anything. However, I make heavy use of template based programming. So I didn't think I'd enjoy C. I figured I'd miss templates. I still do. There is some real ugly in terms of things you have to do with C that are elegant in C++. That being said, I don't miss them as much as I thought I would. Also, using the preprocessor freely is kind of liberating. In C++ I use it only as a last resort. In C it's more first class for me. Anyway, I like C. I do wish it had templates! And it's kind of verbose, which is hard on the fingers (everything has a handle) but also it wasn't a huge transition for me, since I do a lot of IoT coding I don't use things like exceptions, nor do I make heavy use of the STL, so C wasn't so bad. :)

              To err is human. Fortune favors the monsters.

              S Offline
              S Offline
              sasadler
              wrote on last edited by
              #43

              I spent my career as an embedded developer (retired now) and I've only had one project that had enough RAM to be able to use something like STL. The project was basically done when I got it so all I did to it was add/fix miscellaneous features. For most of my projects in the last 15 years of my career, I was using C++ but stayed away from dynamic object creation (all objects instantiated at startup) and inheritance. Since compiler tech had gotten so good, I did use templates for common things like FIFO's, queue's and components for some DSP (filters, tone generators, etc). Don't be afraid to use C++ features, just make sure you know the memory and time cost.

              H 1 Reply Last reply
              0
              • S sasadler

                I spent my career as an embedded developer (retired now) and I've only had one project that had enough RAM to be able to use something like STL. The project was basically done when I got it so all I did to it was add/fix miscellaneous features. For most of my projects in the last 15 years of my career, I was using C++ but stayed away from dynamic object creation (all objects instantiated at startup) and inheritance. Since compiler tech had gotten so good, I did use templates for common things like FIFO's, queue's and components for some DSP (filters, tone generators, etc). Don't be afraid to use C++ features, just make sure you know the memory and time cost.

                H Offline
                H Offline
                honey the codewitch
                wrote on last edited by
                #44

                Sounds like we're very similar in how we approach C++ on embedded and IoT. In projects like htcw_gfx[^] I rarely allocate memory for you, although temporary allocations are sometimes necessary for performance, they are few and far between, plus allow you to specify custom allocators. I don't use STL in such projects. In fact, I've gone out of my way to avoid it, even implementing my own streams and basic data structures like a hashtable and a vector that you can't remove items from aside from clearing the whole thing. The reason is flash size and memory usage - primarily heap frag. I keep my constructors inlineable by my compiler and generally use template based "interfaces" at the source level rather than inheritance based interfaces at the binary level. The idea being flash size is at less of a premium than CPU cycles.

                To err is human. Fortune favors the monsters.

                1 Reply Last reply
                0
                • U User 13269747

                  Quote:

                  The second is that everything has to be casted on both sides of the '='. That got old quick.

                  You must have first seen C back in the 80s? Since C99, anytime a cast is done in C it's a code-smell; casting should almost never be required.

                  D Offline
                  D Offline
                  David ONeil
                  wrote on last edited by
                  #45

                  Yeah, my first exposure was in college, around '88. Every time I've came across C-like code even within the past 10 years it has been full of casts. But I haven't programmed C, so am not too familiar with the current idiosyncrasies.

                  Our Forgotten Astronomy | Object Oriented Programming with C++ | Wordle solver

                  1 Reply Last reply
                  0
                  • H honey the codewitch

                    I've always been a C++ nerd. I came at C++ self taught, but I came at it fresh, without "graduating" from writing C code. I've never regarded C++ as OOP, but rather GP oriented, although in truth it's a chameleon, and can do pretty much anything. However, I make heavy use of template based programming. So I didn't think I'd enjoy C. I figured I'd miss templates. I still do. There is some real ugly in terms of things you have to do with C that are elegant in C++. That being said, I don't miss them as much as I thought I would. Also, using the preprocessor freely is kind of liberating. In C++ I use it only as a last resort. In C it's more first class for me. Anyway, I like C. I do wish it had templates! And it's kind of verbose, which is hard on the fingers (everything has a handle) but also it wasn't a huge transition for me, since I do a lot of IoT coding I don't use things like exceptions, nor do I make heavy use of the STL, so C wasn't so bad. :)

                    To err is human. Fortune favors the monsters.

                    R Offline
                    R Offline
                    rjmoses
                    wrote on last edited by
                    #46

                    As a late-comer to this thread, all I can say is that somewhere inside C++ is a beautiful language waiting to get out. C/C++ both suffer from readability issues. When I look at a piece of code, I want to be able to "grok" it in a few seconds. My most serious complaint about both is that the very things, flexibility and conciseness, that make them usable work against them. I trip through a lot of third party code and it takes waaaaay too much time to understand what the original author wanted to do and how he went about it. Then try to find the error or where it needs to be tweaked to add/modify the code.....days turn into weeks, then months. Simply put, I want to look at the code and comprehend its intent and organization in minutes. Bottom line: C/C++ allow a programmer too many variations to accomplish a task. Good and bad.

                    H 1 Reply Last reply
                    0
                    • R rjmoses

                      As a late-comer to this thread, all I can say is that somewhere inside C++ is a beautiful language waiting to get out. C/C++ both suffer from readability issues. When I look at a piece of code, I want to be able to "grok" it in a few seconds. My most serious complaint about both is that the very things, flexibility and conciseness, that make them usable work against them. I trip through a lot of third party code and it takes waaaaay too much time to understand what the original author wanted to do and how he went about it. Then try to find the error or where it needs to be tweaked to add/modify the code.....days turn into weeks, then months. Simply put, I want to look at the code and comprehend its intent and organization in minutes. Bottom line: C/C++ allow a programmer too many variations to accomplish a task. Good and bad.

                      H Offline
                      H Offline
                      honey the codewitch
                      wrote on last edited by
                      #47

                      I think you have to be more careful to write readable C++ code but it's totally doable. It's just that a lot of people (sadly, including myself :~ ) don't bother. On the other hand, reading C++ is a bit like listening to Aesop Rock. Absolutely unintelligible at first, each for similar reasons, actually, but you start to get an organic feel for the various ways it tends to get put together and then it clicks.

                      To err is human. Fortune favors the monsters.

                      R 1 Reply Last reply
                      0
                      • H honey the codewitch

                        I think you have to be more careful to write readable C++ code but it's totally doable. It's just that a lot of people (sadly, including myself :~ ) don't bother. On the other hand, reading C++ is a bit like listening to Aesop Rock. Absolutely unintelligible at first, each for similar reasons, actually, but you start to get an organic feel for the various ways it tends to get put together and then it clicks.

                        To err is human. Fortune favors the monsters.

                        R Offline
                        R Offline
                        rjmoses
                        wrote on last edited by
                        #48

                        I agree on both counts: It's doable, ...don't bother.

                        1 Reply Last reply
                        0
                        • H honey the codewitch

                          I've always been a C++ nerd. I came at C++ self taught, but I came at it fresh, without "graduating" from writing C code. I've never regarded C++ as OOP, but rather GP oriented, although in truth it's a chameleon, and can do pretty much anything. However, I make heavy use of template based programming. So I didn't think I'd enjoy C. I figured I'd miss templates. I still do. There is some real ugly in terms of things you have to do with C that are elegant in C++. That being said, I don't miss them as much as I thought I would. Also, using the preprocessor freely is kind of liberating. In C++ I use it only as a last resort. In C it's more first class for me. Anyway, I like C. I do wish it had templates! And it's kind of verbose, which is hard on the fingers (everything has a handle) but also it wasn't a huge transition for me, since I do a lot of IoT coding I don't use things like exceptions, nor do I make heavy use of the STL, so C wasn't so bad. :)

                          To err is human. Fortune favors the monsters.

                          C Offline
                          C Offline
                          Clive Hudson
                          wrote on last edited by
                          #49

                          If you like C, wait until you see C#! It's what C++ was meant to be.:cool:

                          H 1 Reply Last reply
                          0
                          • C Clive Hudson

                            If you like C, wait until you see C#! It's what C++ was meant to be.:cool:

                            H Offline
                            H Offline
                            honey the codewitch
                            wrote on last edited by
                            #50

                            No it isn't. Just sayin'

                            To err is human. Fortune favors the monsters.

                            1 Reply Last reply
                            0
                            Reply
                            • Reply as topic
                            Log in to reply
                            • Oldest to Newest
                            • Newest to Oldest
                            • Most Votes


                            • Login

                            • Don't have an account? Register

                            • Login or register to search.
                            • First post
                              Last post
                            0
                            • Categories
                            • Recent
                            • Tags
                            • Popular
                            • World
                            • Users
                            • Groups