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. C++ is such a lovely, infuriating puzzlebox

C++ is such a lovely, infuriating puzzlebox

Scheduled Pinned Locked Moved The Lounge
c++tutorial
10 Posts 5 Posters 0 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.
  • H Offline
    H Offline
    honey the codewitch
    wrote on last edited by
    #1

    In most languages, at least in my experience, the things that you can and can't do with it are pretty clear. With C++, this isn't really the case. Because of things like metaprogramming, and the sheer flexibility of it, it's often not a case of whether or not you can do a thing, but rather how you can coax, tease, finagle, or otherwise cajole the compiler into doing what you're asking of it. And therein lies the rub. I sometimes find myself running into things that I know *should* be solvable in C++, but how to do it requires (often) days of banging on a narrow section of code to get it to do what I need. I love the mental challenge of it, but I hate the frustration that often comes with that. Sometimes I don't want a challenge - I just want the thing to work. And even when it does the code is often write only code.

    To err is human. Fortune favors the monsters.

    Mike HankeyM G B 3 Replies Last reply
    0
    • H honey the codewitch

      In most languages, at least in my experience, the things that you can and can't do with it are pretty clear. With C++, this isn't really the case. Because of things like metaprogramming, and the sheer flexibility of it, it's often not a case of whether or not you can do a thing, but rather how you can coax, tease, finagle, or otherwise cajole the compiler into doing what you're asking of it. And therein lies the rub. I sometimes find myself running into things that I know *should* be solvable in C++, but how to do it requires (often) days of banging on a narrow section of code to get it to do what I need. I love the mental challenge of it, but I hate the frustration that often comes with that. Sometimes I don't want a challenge - I just want the thing to work. And even when it does the code is often write only code.

      To err is human. Fortune favors the monsters.

      Mike HankeyM Offline
      Mike HankeyM Offline
      Mike Hankey
      wrote on last edited by
      #2

      I find the same frustration level in WPF. The learning curve is so steep, the language so flexible and powerful that I fight problems for hours or sometimes days at a time to straighten things out. Like you sometimes I just want it to work.

      The less you need, the more you have. Even a blind squirrel gets a nut...occasionally. JaxCoder.com

      G 1 Reply Last reply
      0
      • Mike HankeyM Mike Hankey

        I find the same frustration level in WPF. The learning curve is so steep, the language so flexible and powerful that I fight problems for hours or sometimes days at a time to straighten things out. Like you sometimes I just want it to work.

        The less you need, the more you have. Even a blind squirrel gets a nut...occasionally. JaxCoder.com

        G Offline
        G Offline
        Gary R Wheeler
        wrote on last edited by
        #3

        I've reached that level with WPF. I'll be going along just swimmingly, and all of a sudden the easiest thing just. doesn't. work. I have the most trouble with bindings, largely because the XAML syntax is brutal.

        Software Zen: delete this;

        Mike HankeyM 1 Reply Last reply
        0
        • H honey the codewitch

          In most languages, at least in my experience, the things that you can and can't do with it are pretty clear. With C++, this isn't really the case. Because of things like metaprogramming, and the sheer flexibility of it, it's often not a case of whether or not you can do a thing, but rather how you can coax, tease, finagle, or otherwise cajole the compiler into doing what you're asking of it. And therein lies the rub. I sometimes find myself running into things that I know *should* be solvable in C++, but how to do it requires (often) days of banging on a narrow section of code to get it to do what I need. I love the mental challenge of it, but I hate the frustration that often comes with that. Sometimes I don't want a challenge - I just want the thing to work. And even when it does the code is often write only code.

          To err is human. Fortune favors the monsters.

          G Offline
          G Offline
          Gary R Wheeler
          wrote on last edited by
          #4

          I lay blame for that on the academics who've had control of the language design for so long. There are any number of features that would be useful in the language, but they have this abhorence of limiting conditions of application that it's impossible to add new things. And don't get me started on the run-time library. It may be silly season at times in C# land, but at least we get useful stuff now and then.

          Software Zen: delete this;

          H 1 Reply Last reply
          0
          • G Gary R Wheeler

            I've reached that level with WPF. I'll be going along just swimmingly, and all of a sudden the easiest thing just. doesn't. work. I have the most trouble with bindings, largely because the XAML syntax is brutal.

            Software Zen: delete this;

            Mike HankeyM Offline
            Mike HankeyM Offline
            Mike Hankey
            wrote on last edited by
            #5

            Bindings are very powerful but they can really be a PITA. Chasing a bad binding is akin to a bad pointer.

            The less you need, the more you have. Even a blind squirrel gets a nut...occasionally. JaxCoder.com

            1 Reply Last reply
            0
            • G Gary R Wheeler

              I lay blame for that on the academics who've had control of the language design for so long. There are any number of features that would be useful in the language, but they have this abhorence of limiting conditions of application that it's impossible to add new things. And don't get me started on the run-time library. It may be silly season at times in C# land, but at least we get useful stuff now and then.

              Software Zen: delete this;

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

              I will give C++ this though - I can do things at compile time with it that can't be done in any other language that I'm aware of. The trick is knowing how to do it.

              To err is human. Fortune favors the monsters.

              J 1 Reply Last reply
              0
              • H honey the codewitch

                I will give C++ this though - I can do things at compile time with it that can't be done in any other language that I'm aware of. The trick is knowing how to do it.

                To err is human. Fortune favors the monsters.

                J Offline
                J Offline
                Jacob Williamss
                wrote on last edited by
                #7

                +1 It makes it so easy to do things at compile time.

                H 1 Reply Last reply
                0
                • H honey the codewitch

                  In most languages, at least in my experience, the things that you can and can't do with it are pretty clear. With C++, this isn't really the case. Because of things like metaprogramming, and the sheer flexibility of it, it's often not a case of whether or not you can do a thing, but rather how you can coax, tease, finagle, or otherwise cajole the compiler into doing what you're asking of it. And therein lies the rub. I sometimes find myself running into things that I know *should* be solvable in C++, but how to do it requires (often) days of banging on a narrow section of code to get it to do what I need. I love the mental challenge of it, but I hate the frustration that often comes with that. Sometimes I don't want a challenge - I just want the thing to work. And even when it does the code is often write only code.

                  To err is human. Fortune favors the monsters.

                  B Offline
                  B Offline
                  BernardIE5317
                  wrote on last edited by
                  #8

                  Greetings Kind Regards Can you provide an example of the "narrow code"? Perhaps an article would be useful to this paltry programmer. - Best Cheerio

                  H 1 Reply Last reply
                  0
                  • B BernardIE5317

                    Greetings Kind Regards Can you provide an example of the "narrow code"? Perhaps an article would be useful to this paltry programmer. - Best Cheerio

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

                    By narrow, I just meant code that performs a particular task or something. Like making this return the nearest integer type that can contain data of the specified bit depth:

                    bits::uintx

                    Or a more complicated example, shifting an arbitrary number of bits an arbitrary number of digits left at compile time:

                    nstexpr static void shift_left(void* bits,size_t offset_bits,size_t size_bits, size_t shift) {
                    if(nullptr==bits || 0==size_bits || 0==shift) {
                    return;
                    }
                    // special case if we shift all the bits out
                    if(shift>=size_bits) {
                    set_bits(bits,offset_bits,size_bits,false);
                    return;
                    }
                    uint8_t* pbegin = ((uint8_t*)bits)+(offset_bits/8);
                    const size_t offset = offset_bits % 8;
                    const size_t shift_bytes = shift / 8;
                    const size_t shift_bits = shift % 8;
                    const size_t overhang = (size_bits+offset_bits) % 8;
                    // preserves left prior to offset
                    const uint8_t left_mask = ((uint8_t)uint8_t(0xFF<<(8-offset)));
                    // preserves right after overhang
                    const uint8_t right_mask = 0!=overhang?uint8_t(0xFF>>overhang):0;
                    uint8_t* pend = pbegin+(size_t)((offset_bits+size_bits+7)/8);
                    uint8_t* plast = pend-1;
                    uint8_t* psrc = pbegin+shift_bytes;
                    uint8_t* pdst = pbegin;
                    if(pbegin+1==pend) {
                    // special case for a shift all within one byte
                    uint8_t save_mask = left_mask|right_mask;
                    uint8_t tmp = *pbegin;
                    *pbegin = uint8_t(uint8_t(tmp<>(8-shift_bits));
                    ++psrc;
                    ++pdst;
                    }

                    \*pbegin=(left&left\_mask)|uint8\_t(\*pbegin&~left\_mask);
                    --pend;
                    \*plast=uint8\_t(right&right\_mask)|uint8\_t(\*plast&uint8\_t(~right\_mask));
                    

                    };

                    To err is human. Fortune favors the monsters.

                    1 Reply Last reply
                    0
                    • J Jacob Williamss

                      +1 It makes it so easy to do things at compile time.

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

                      It depends on what you're doing! I have a graphics library that lets you define arbitrary pixel formats and color models using templates. It can then render to bitmapped memory in the given memory layout, doing the appropriate bit shifts and masking and such to pack each individual color channel into the pixel value. gfx_demo/gfx_pixel.hpp at master · codewitch-honey-crisis/gfx_demo · GitHub[^] It also lets you convert to different pixel formats at compile time, and can do alpha blending at compile time. This was not easy to do at compile time.

                      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