|
When that becomes easy to read, you know you are a real programmer!
|
|
|
|
|
Neither did I, until I discovered I "was using it wrong" and had some "true C++ programmer" abusing templates lambda functions like there was no tomorrow.
GCS d--(d+) s-/++ a C++++ U+++ P- L+@ E-- W++ N+ o+ K- w+++ O? M-- V? PS+ PE- Y+ PGP t+ 5? X R+++ tv-- b+(+++) DI+++ D++ G e++ h--- r+++ y+++* Weapons extension: ma- k++ F+2 X
|
|
|
|
|
Ung! That sucks! I will admit that I'm not a great fan of lambda syntax, but I love what it is capable of. Putting them in templates - major Ungh!
I would classify that as template metaprogramming, rather than C++, just so I could live in my happy little C++ bubble!
|
|
|
|
|
You're probably not using all the "features".
I've been tripping through some code that I have to study each line for 10-15 minutes to figure out what it's doing. I hate it!
|
|
|
|
|
My question: would it be understandable if it was rewritten using older features without the newfangled stuff, or is it only possible to do using the newfangled stuff? Can it be refactored to be easier to understand?
|
|
|
|
|
No, in the case I am thinking about, it has to do with simple formatting so that the logic flow would be clear. It is a sequence of 30 or so if/elseif statements with embedded if's or if/elseif's with absolutely no indentation. Telling what elseif goes with what if is a pain in the patootie.
But in other cases, I have seen lambdas embedded in templates which makes debugging old code very difficult on an easy day.
My belief is simple: Code should be comprehensible for its intent and objective within a few seconds. Looking for matching braces, buried parens, etc. is very frustrating.
|
|
|
|
|
Then there are unions. Essentially a compiler-driven cast with no type conversions what so ever. It's in-memory aliasing. It takes casting to an entirely new level. I have found many good uses for unions. So has Microsoft - see the LARGE_INTEGER for an example.
"They have a consciousness, they have a life, they have a soul! Damn you! Let the rabbits wear glasses! Save our brothers! Can I get an amen?"
|
|
|
|
|
Yeah, I'm aware - I even adapted the approach for C# using StructLayout.Explicit. It's just that declaring a union type isn't always called for. If you're doing the cast once or twice it doesn't make a lot of sense, so i do it when it's called for.
Real programmers use butterflies
|
|
|
|
|
yeah, that'll work so long as you don't stash your structs pointers this way.
#SupportHeForShe
Government can give you nothing but what it takes from somebody else. A government big enough to give you everything you want is big enough to take everything you've got, including your freedom.-Ezra Taft Benson
You must accept 1 of 2 basic premises: Either we are alone in the universe or we are not alone. Either way, the implications are staggering!-Wernher von Braun
|
|
|
|
|
Yeah I try not to point into the stack for longer than the context of the containing function.
Real programmers use butterflies
|
|
|
|
|
No problem. Placement new to the rescue!
Sorry, wrong language.
|
|
|
|
|
Yeah, but that processing the struct after-the-fact. Her technique is great for 'simple' structs.
#SupportHeForShe
Government can give you nothing but what it takes from somebody else. A government big enough to give you everything you want is big enough to take everything you've got, including your freedom.-Ezra Taft Benson
You must accept 1 of 2 basic premises: Either we are alone in the universe or we are not alone. Either way, the implications are staggering!-Wernher von Braun
|
|
|
|
|
the file is also not compatible between architecture to the next!
i.e. endianess for sure.. but probably computer struct paddings too! :/ though haven't used C in decades, so I am not so sure about that one...
|
|
|
|
|
Sometimes that doesn't matter. Sometimes you're writing software dedicated to a particular microcontroller and it expects the thing to be wired a certain way in order to run anyway.
Real programmers use butterflies
|
|
|
|
|
oh well.. yes if consumer and producer is the same one, I guess it's all good!
|
|
|
|
|
I've read this subject line several times now, wanting to point out what's so wrong with it.
Anyway, I think you will love Javascript.
Wrong is evil and must be defeated. - Jeff Ello
Never stop dreaming - Freddie Kruger
|
|
|
|
|
There's a special place in programmer hell for whoever came up with duck typing.
Real programmers use butterflies
|
|
|
|
|
I have been using C for+/- 32 years and still like it a lot.
The fact that yes, you can do anything, does force you to be very careful what you ask for because you will get it.
|
|
|
|
|
It's very satisfying to be back to it after being confined to coding in C# so much.
Real programmers use butterflies
|
|
|
|
|
You could always use a union, no need to even cast then (:
I wouldn't want to program in C targeting a PC these days; but it is good for 8 & 16 bit embedded work, where you need to get at hardware registers and only have maybe 2K RAM and 16K or 32K ROM.
|
|
|
|
|
I'm coding a microcontroller and technically I'm using C++ but barely because I am avoiding templates and the STL. =(
Real programmers use butterflies
|
|
|
|
|
If you were using fwrite, you wouldn't even need a cast...
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Quote: I love C where types are basically a suggestion rather than a rule
That doesn't sound like C. The only place in C where types are not enforced are in void pointers. Everywhere else you have to literally force the compiler to accept incorrect types.
How is this different from other languages?
|
|
|
|
|
You misunderstand me.
I'm not saying C doesn't enforce types.
I'm saying if you want to change the type it's enforcing you just have to give it a little nudge.
For example
struct S {
int x;
int y;
};
...
S s;
s.x=1;
s.y=1;
byte* bp = (byte*)&s;
Real programmers use butterflies
|
|
|
|
|
Quote: byte* bp = (byte*)&s;
That's a bug :-/. C does not allow conversion of pointers to anything other than a void pointer and back again. A compiler may let you do it but the language standard calls it a bug (undefined behaviour).
In other words, that isn't correct C; many compilers will allow it and let the program produce unpredictable results (anything from producing the correct results, producing incorrect results, all the way to crashing).
The correct way to do that is to use a union, at which point the strong typing gets enforced and alignment is guaranteed and you have not broken any of the C standards rules. While this way isn't Undefined Behaviour, it's not fully defined either - it's Implementation Defined (someone will correct me if I am wrong on this point, no doubt due to padding that may or may not occur depending on what flags were given to the compiler.
To be honest, any time you need to put in a cast in C (not C++) because the compiler is complaining, it's probably a bug. There are very few uses of casting in C (not C++) that aren't bugs. All uses of casting that I've seen in production code were alignment bugs. The few cases you need casting in C is when you are writing generic container functions and want to provide const guarantees to the callers.
Also, 'byte' is not a type in C. You probably mean to use 'uint8_t' or 'uint_least8_t'. I've seen programs use 'char' for bytes, but that isn't correct either as the standard doesn't require 'char' to be unsigned or to be signed (it's left up to the implementation) and 'working' code will suddenly stop working if the program is recompiled on a compiler which defaults to signed char (left bitshift operations on signed integer types are undefined. It's only defined for unsigned integer types).
I've been seeing more and more of this meme "C has weak typing" in various forums recently. In reality there is literally only one or two specific instances where the typing breaks down in C.
|
|
|
|