*cries in C++*
-
honey the codewitch wrote:
The code is evil. It's absolutely terrible to read, almost as if they were *trying* to hide intent.
I am now responsible for a piece of code that's been part of our business for over thirty years. This software handles rendering our proprietary printer language into bitmaps, and then shipping those bitmaps out to be printed. It was originally written by a guy who I'll call BK. BK worked on this one code base for 25 years. It had been 'stable' (bugs are features at that point) for quite a while, and they tried to reassign BK to another project. After six months of doing absolutely nothing he decided to retire when he was confronted. When this landed in my lap, we had not even recompiled this stuff in over ten years. I looked through the source code a few times to answer questions, but hadn't needed to really understand it. Last fall we had a piece of customer-specific hardware go obsolete so we needed to design a replacement. I started looking through the code to see what would need changed. Good :elephant:ing grief. This code was written explicitly so that only a single person could maintain it. It was in C. Function prototypes weren't used. Header files didn't define the functions or data in the corresponding .C source file. There were numerous global structs, variables, and
#define
's with 3, 2, and yes even 1! character names. I think the best bit of numb:elephant:ery was a group of#define
's he'd added before#include <windows.h>
which changed the definition of a number of values in the Windows headers which his comment (one of the few) claimed "Microsoft got wrong". I spent over 100 manhours identifying precisely the changes I needed to make and where. My replacement took less than a day from the time I started writing it to when it was compiled, tested, and ready for a trial on customer equipment. This code is [in]famous for something else. I'm a vulgar man, and I swear a lot in casual conversation with people I know, including my coworkers. That said, I've never cussed or used foul language in my source code. It just didn't seem professional. Until. This. Crap. There is now a comment block in this code following my modifications which looks something like this:// ====================================================================
// USELESS SHIT LEFT OVER FROM THE ORIGINAL IMPLEMENTATION
// =======================================Gary R. Wheeler wrote:
I am now responsible for a piece of code that's been part of our business for over thirty years...Function prototypes weren't used. Header files didn't define the functions or data in the corresponding .C source file. There were...
So at least 1992. So yes that was par for the course for C code then. Things like prototypes sort of came about probably associated with C++ (perhaps not entirely but for the same reason that C++ added them.) Someone used to the the older style would not have used them. Globals were something that any C app would be using. Single char variable names were common.
Gary R. Wheeler wrote:
a group of #define's he'd added before #include <windows.h> which changed the definition of a number of values in the Windows headers which his comment (one of the few) claimed "Microsoft got wrong".
Could not speak specifically to that but as I recall there were a lot of problems with the early Microsoft C++. I know for a fact that for years after the ANSI C++ spec was released the Microsoft scored very poorly on implementing it. That was back when people could actually post comparisons of software without getting sued.
-
but to be honest, that can be done in any language. I'm reading through "learning python" and just hit the description of formatting strings. I don't know what that guy was smoking when they came up with their approach, but I want some.
Charlie Gilley “They who can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety.” BF, 1759 Has never been more appropriate.
charlieg wrote:
but to be honest, that can be done in any language.
Err..no it can't. I had a C program that had assembly code in a text literal. I would cast it to a function and the call it. Pseudo code for that was something like the following
char* code = "\xCC\xFF...";
typedef int* myfunct(int i)
int result = (myfunct)(code)(45);If I hadn't put a lot of comments around that, including the exact assembly, then a maintenance programmer, even an experienced one, would have spent a lot of time figuring that out.
-
Memtha wrote:
only because I am forced to run it through a painfully awful "security" code scanner.
...and because you are working for a company that doesn't know what they are doing. Or perhaps an individual up the authority chain that doesn't.
> working for a company that doesn't know what they are doing Close. The company is very good, but the client is... government. Need I say more? Some battles just aren't worth the effort. We had to teach the "security lead" how to use git to get the zip and upload it to the scanning service they have forced on us. It's not even the government personnel that chose the scanner, it's a rival contractor that loves to tout the sheer number of "vulnerabilities" that "they" "addressed" by forcing us to add try/catch/throw on every single method.
-
mischasan wrote:
because it is superfast for solving complex problems, and surprisingly straightforward.
Right up until someone asks for the studies that demonstrates those statements using something besides benchmarks (that are often coded well in one language and then so poorly done in other languages that one suspects that they were written that way deliberately.) But to be fair I am certain I have seen that claim about every language and based, when based on anything at all, on the same sort of lopsided benchmarks.
"Superfast for solving problems" -- superfast for the solver to formulate. Sorry if that it sounds like, "superfast execution time". Building systems in APL for Rank Xerox, I sometimes completed and ran a solution in the course of a short conversation; so we could get on with the conclusion from its result. Occasionally (rarely) was its speed of execution an issue.
-
I love this language except when it's used cryptically. You can produce more incomprehensible code with C++ than I think you can in any other major language. I'm poring over C code right now - C really isn't that much better, but fortunately you can do less with it. The code is evil. It's absolutely terrible to read, almost as if they were *trying* to hide intent. Porting it to C++ is my fresh hell. I love this language, but would it kill people to write readable code, or at least comment it with something *helpful*? Anyway, I guess what I'm saying is C++ is both my favorite and least favorite language. It's weird like that.
Real programmers use butterflies
I feel like if you can't program it in C/C++ then you don't really understand it. If the C/C++ answer is obvious then the others are trivial.
-
I feel like if you can't program it in C/C++ then you don't really understand it. If the C/C++ answer is obvious then the others are trivial.
Yeah, but that's not what I was talking about. More I'm talking about things like this.
if(pin_d1>31) {
b |= (((pins_h>>((pin_d1-32)&31))&1)<<1);
} else if(pin_d1>-1) {
b |= (((pins_l>>(pin_d1))&1)<<1);
}
if(pin_d2>31) {
b |= (((pins_h>>((pin_d2-32)&31))&1)<<2);
} else if(pin_d2>-1) {
b |= (((pins_l>>(pin_d2))&1)<<2);
}
if(pin_d3>31) {
b |= (((pins_h>>((pin_d3-32)&31))&1)<<3);
} else if(pin_d3>-1) {
b |= (((pins_l>>(pin_d3))&1)<<3);
}
if(pin_d4>31) {
b |= (((pins_h>>((pin_d4-32)&31))&1)<<4);
} else if(pin_d4>-1) {
b |= (((pins_l>>((pin_d4)&31))&1)<<4);
}
if(pin_d5>31) {
b |= (((pins_h>>((pin_d5-32)&31))&1)<<5);
} else if(pin_d5>-1) {
b |= (((pins_l>>(pin_d5))&1)<<5);
}
if(pin_d6>31) {
b |= (((pins_h>>((pin_d6-32)&31))&1)<<6);
} else if(pin_d6>-1) {
b |= (((pins_l>>(pin_d6))&1)<<6);
}
if(pin_d7>31) {
b |= (((pins_h>>((pin_d7-32)&31))&1)<<7);
} else if(pin_d7>-1) {
b |= (((pins_l>>(pin_d7))&1)<<7);
}How many of these if statements will be compiled into the binary? You can't know that just by looking at it, assuming this is C++. In this case, none will, because they all evaluate constexpr values. But those can be buried under templates, for example, and then the answer non-obvious.
Real programmers use butterflies
-
charlieg wrote:
but to be honest, that can be done in any language.
Err..no it can't. I had a C program that had assembly code in a text literal. I would cast it to a function and the call it. Pseudo code for that was something like the following
char* code = "\xCC\xFF...";
typedef int* myfunct(int i)
int result = (myfunct)(code)(45);If I hadn't put a lot of comments around that, including the exact assembly, then a maintenance programmer, even an experienced one, would have spent a lot of time figuring that out.
I'm sorry, but what is your point? You have special code, you knew it was special code, so you made it real obvious what you were doing. :confused:
Charlie Gilley “They who can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety.” BF, 1759 Has never been more appropriate.
-
If you've got a system that supports dc, try this:
dc -e '2p3p[dl!d2+s!%0=@l!l^!<#]s#[s/0ds^]s@[p]s&[ddvs^3s!l#x0<&2+l.x]ds.x'
Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012
That's a prime post !
-
Gary R. Wheeler wrote:
I am now responsible for a piece of code that's been part of our business for over thirty years...Function prototypes weren't used. Header files didn't define the functions or data in the corresponding .C source file. There were...
So at least 1992. So yes that was par for the course for C code then. Things like prototypes sort of came about probably associated with C++ (perhaps not entirely but for the same reason that C++ added them.) Someone used to the the older style would not have used them. Globals were something that any C app would be using. Single char variable names were common.
Gary R. Wheeler wrote:
a group of #define's he'd added before #include <windows.h> which changed the definition of a number of values in the Windows headers which his comment (one of the few) claimed "Microsoft got wrong".
Could not speak specifically to that but as I recall there were a lot of problems with the early Microsoft C++. I know for a fact that for years after the ANSI C++ spec was released the Microsoft scored very poorly on implementing it. That was back when people could actually post comparisons of software without getting sued.
In some circumstances what you're saying could be true. This code was adapted to Windows in the early 2000's, so function prototyping was the norm. No excuse there.
jschell wrote:
Could not speak specifically to that but as I recall there were a lot of problems with the early Microsoft C++. I know for a fact that for years after the ANSI C++ spec was released the Microsoft scored very poorly on implementing it. That was back when people could actually post comparisons of software without getting sued.
This is a case where BK was redefining constants for arguments to and return values from Windows API functions, thereby guaranteeing they would not work as documented. BK was an asshole.
Software Zen:
delete this;
-
Well, after about 24 hours on an ancient and very slow laptop, it hit this milestone:
99999847
99999931
99999941
99999959
99999971
99999989
100000007
100000037
100000039
100000049
100000073
100000081
100000123
100000127
100000193
100000213
100000217
100000223I took pity on the poor beast shortly afterwards. ;P :laugh:
Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012
-
I love this language except when it's used cryptically. You can produce more incomprehensible code with C++ than I think you can in any other major language. I'm poring over C code right now - C really isn't that much better, but fortunately you can do less with it. The code is evil. It's absolutely terrible to read, almost as if they were *trying* to hide intent. Porting it to C++ is my fresh hell. I love this language, but would it kill people to write readable code, or at least comment it with something *helpful*? Anyway, I guess what I'm saying is C++ is both my favorite and least favorite language. It's weird like that.
Real programmers use butterflies
From 1985 to 2010, any decent run-of-the-mill-general-purpose coding standard worked pretty well for C and C++. But since C++11, every batch of new features also added more tools that were easy to misuse against the spirit if not the letter of said guidelines. Nowadays, the only way to maintain good code with modern C++ is using modern standards following Clean-Code / SOLID principles. I've found the most important thing is keeping classes and functions small: just one purpose is the key. The best way to find out if your function or class is small enough is thinking about a name that describes it well: if a good description requires an 'or' or 'and' or 'then', then your class or function tries to fulfil more than one purpose and should be split!
GOTOs are a bit like wire coat hangers: they tend to breed in the darkness, such that where there once were few, eventually there are many, and the program's architecture collapses beneath them. (Fran Poretto)
-
From 1985 to 2010, any decent run-of-the-mill-general-purpose coding standard worked pretty well for C and C++. But since C++11, every batch of new features also added more tools that were easy to misuse against the spirit if not the letter of said guidelines. Nowadays, the only way to maintain good code with modern C++ is using modern standards following Clean-Code / SOLID principles. I've found the most important thing is keeping classes and functions small: just one purpose is the key. The best way to find out if your function or class is small enough is thinking about a name that describes it well: if a good description requires an 'or' or 'and' or 'then', then your class or function tries to fulfil more than one purpose and should be split!
GOTOs are a bit like wire coat hangers: they tend to breed in the darkness, such that where there once were few, eventually there are many, and the program's architecture collapses beneath them. (Fran Poretto)
"draw::text<>" has one purpose in my draw class in GFX, and has multiple overloads, the implementation of which spans several functions and one entire private header+cpp file. Because it renders truetype text. Even after factoring the function is half a screen on my display. I agree with you in principle, but in practice I can't code that way. I have some wiring issues in my head that affect my short term memory, and if I over-factor I forgot how to navigate all the layers and calls. In some respects my condition can be debilitating. This is not one of those areas, but it does mean I have to adjust my approach. Cognitive load on the other hand, I can take for days. So give me a long function, as long as its purpose is singular. But I understand that this is less than ideal, because I code professionally, and have coded on teams, from PM to lead to QA. That's one reason I'm not a stickler for industry wide standards. I think a good coder can pick up a standard someone else uses, as long as that someone was consistent, and it's not awful - like there's sense to it. I mean, I have to consider myself and that I'm probably not the only one coding with a handicap of sorts. As far as C++11 and beyond, I agree with you. But also I'm going to be difficult here - the introduction of variadic template arguments and things like that which facilitate metaprogramming and the metaprogramming itself creates its own kind of maintenance monster. When you get used to reading "metaprogrammed" C++ it gets easier, but it's still a beast. I've had to reimplement a lot of what the STL hides at points because I target frameworks where the STL is partial if at all, and I don't know which parts are necessarily available, so I understand the sausage making therein. On the other hand, you can do so much with it. Opening a dialogue with the compiler using your code, so that it can shape the generated code is just ... no other coding is like that. It sets C++ apart, and allows you to do some truly amazing things. In GFX I allow you to define pixels with arbitrary binary layouts and color formats. It then lets you manipulate all the individual color channels and if everything is const, it all resolves const. That means if you use a predefined color like "hot_pink" (an X11 standard color) it will resolve to a single scalar const value at compile time. You can even get the compiler to color blend and convert color formats (from like Y'UV to RGBA or BGR) All that with C++14 and a somewhat byzantine header file (linked if you'r
-
> working for a company that doesn't know what they are doing Close. The company is very good, but the client is... government. Need I say more? Some battles just aren't worth the effort. We had to teach the "security lead" how to use git to get the zip and upload it to the scanning service they have forced on us. It's not even the government personnel that chose the scanner, it's a rival contractor that loves to tout the sheer number of "vulnerabilities" that "they" "addressed" by forcing us to add try/catch/throw on every single method.