C++ is such a lovely, infuriating puzzlebox
-
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.
-
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.
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
-
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
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;
-
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.
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;
-
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;
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
-
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;
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.
-
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.
+1 It makes it so easy to do things at compile time.
-
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.
Greetings Kind Regards Can you provide an example of the "narrow code"? Perhaps an article would be useful to this paltry programmer. - Best Cheerio
-
Greetings Kind Regards Can you provide an example of the "narrow code"? Perhaps an article would be useful to this paltry programmer. - Best Cheerio
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 It makes it so easy to do things at compile time.
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.