|
Saw this today:code:
code:
|
# ¿ Apr 3, 2008 15:33 |
|
|
# ¿ Apr 29, 2024 05:37 |
|
Victor posted:Clearly, return is a function.
|
# ¿ Apr 3, 2008 17:20 |
|
Nada, I agree there.
|
# ¿ Apr 3, 2008 18:11 |
|
So we use middleware to pass serialized objects around a network of machines. All code is c++. We have to interface with other people's code over this middleware. They define the objects that get sent back and forth over the middleware. Here's a "snippet" (not really, but to give you an idea of the horror) of their headers:code:
...
|
# ¿ Apr 10, 2008 23:58 |
|
Ok, but, the software is called "middleware." And, conceptually, it stands between two computers. Also, the messaging is platform agnostic. What you put in is what you get out, no matter what platform you're on. So if a 64 bit machine puts in a 20 bit object, a 32 bit machine will receive a 20 bit object, even if the source for that object compiles to a 16 bit object under 32 bit compilation. Hence the horror.
|
# ¿ Apr 11, 2008 14:54 |
|
fansipans posted:... ... Are you making fun of me? It was a pause for dramatic effect! MrMoo posted:Technically that middleware is tied to the sending system.
|
# ¿ Apr 11, 2008 17:07 |
|
JoeNotCharles posted:Oh, god, that reminds me of one of my pet peeves: ".lenght()"
|
# ¿ May 6, 2008 16:53 |
|
Ah, the classics have a beauty to them that is unparalleled.
|
# ¿ May 6, 2008 19:15 |
|
I started working on a new project yesterday so I was reading some of the code trying to get a feel for how things are organized. I noticed two files called DirectoryFileObjects.h and two files called DirectoryFileObjects.cc. I diffed each pair to see what was up, they were the same. So I went into the revision tool and what I see is that one of them is an original and the other is just a copy that is kept in sync with changes made to the original. Like, the revision comments on one of the pair of files is something like: - added blah support And then the revision comments on the other file (for the same change) is: - synced with master Why? Because the developer needed some of the functions defined in DirectoryFileObjects.h, but he needed them somewhere else than where the original DirectoryFileObjects.h exists. And that's not mentioning the 2345 line function in DirectoryFileObjects.cc whose last 14 lines are nothing but closing braces stepping down 14 levels of indentation.
|
# ¿ Jul 2, 2008 15:10 |
|
I was trying to fix a compile issue due to an upgrade to a newer version of a vendor provided library. The code was C++. The writer of this library was sitting behind me and I was at the keyboard. I opened up one of my files that had a compile error and was fixing it when the guy behind me says: Guy: What's that syntax there? Me: Eh? Guy puts finger on screen to point at a & Guy: That. Me: Oh, I don't want to copy that object so I passed it by reference. Guy: What's that? Me: Um. It's a reference. Guy: I don't get it. Is that like a pointer or something? I usually use that to mean address-of. Me: Well... it's kinda like a pointer... but it's a reference. Guy: I don't know about that, I'd take it out to be safe. Me: Uh huh. Well. I'll take my chances. For fucks sake this guy wrote nearly 300 kloc of C++ and he doesn't know what a reference is? gently caress me.
|
# ¿ Aug 31, 2008 04:04 |
|
The library is the C++ implementation for a CORBA client using TAO. It is most assuredly C++ in every conceivable way. The guy billed himself as "The C++ Guy," not "The C Guy Who Just Happens To Use A C++ Compiler." His job description could have literally been "The Guy Who Implemented This Library In C++."
|
# ¿ Aug 31, 2008 16:30 |
|
Anonymous Name posted:unclear code code:
|
# ¿ Sep 1, 2008 05:41 |
|
floWenoL posted:The person who wrote the code may be completely familiar with the function, but maybe not the person reading the code later.
|
# ¿ Sep 1, 2008 18:44 |
|
I need to test if this number is odd. Think man, think! Hey isn't there something about odd numbers and dividing by two that I learned in kindergarten? <A couple of hours later, after three of four pages of scratch work> Oh hey, look at this, whenever I divide an odd number by 2 I get .5 on the end... regex to the rescue!
|
# ¿ Oct 8, 2008 21:43 |
|
My co-worker told me today that const-correctness isn't worth the speed hit.
|
# ¿ Dec 9, 2008 02:08 |
|
seiken posted:I've always gotten by fine, is this a horrible thing? I mostly design libraries to be used by other people and one of the primary drives for being const-correct for me is common courtesy. If I provide a method bar() const on my object foo, then users of my library know that calling it isn't going to (conceptually) mutate the object. Going back and trying to const-correctify something that wasn't designed to be const-correct from the start is painful.
|
# ¿ Dec 10, 2008 03:51 |
|
Found this code today:code:
Lexical Unit fucked around with this message at 22:57 on Feb 27, 2009 |
# ¿ Feb 27, 2009 22:54 |
|
Actually, more than 5 people have touched the file over the course of 5 years and all 5 of these people still work here. In fact, 3 of the 5 can be considered my supervisors.
|
# ¿ Feb 27, 2009 23:02 |
|
Good question. I asked my boss the same thing. He shrugged. He is one of the 5. Edit: The rabbit hole gets deeper. The program comes with a .env that should be sourced before execution. That file looks like this: code:
Lexical Unit fucked around with this message at 23:55 on Feb 27, 2009 |
# ¿ Feb 27, 2009 23:41 |
|
mr_jim posted:I really hope that the program is running under an unprivileged account, but that might be expecting too much.
|
# ¿ Feb 28, 2009 08:19 |
|
Avenging Dentist posted:If it weren't for the fact that you're setting to NULL twice, this is completely acceptable and is in fact a recommended thing to do. (Though putting the error handling in the catch statement would be even better.)
|
# ¿ Apr 9, 2009 17:14 |
|
Seth Turtle posted:This is the proper layout of a programmer's two screens... Not quite. 1. Your development machine has its screen saver up. (Who cares what windows are up on that thing?) 2. Your personal machine to your left has SA forums up with youtube hidden underneath that window in case your boss walks in.
|
# ¿ May 14, 2009 15:58 |
|
C++: Exhibit 1 code:
code:
code:
code:
Lexical Unit fucked around with this message at 21:57 on Jun 2, 2009 |
# ¿ Jun 2, 2009 21:54 |
|
In the real code there's more like 20 lines in each branch... they are exactly the same. For a good long second I didn't realize what I was looking at because I couldn't believe what I saw.
|
# ¿ Jun 3, 2009 03:59 |
|
Zombywuf posted:Well, that code will order the incoming events by uid... I didn't show it but later he takes that same vector, takes the reference of it to get a pointer to it, and passes around that pointer to other functions. If you look in the revision history you can see that in the past he was just passing around the vector by value until finally the program ground to a halt and he changed to passing around pointers to the vector to speed the program up.
|
# ¿ Jun 3, 2009 14:46 |
|
Found this in a Perl script todaycode:
|
# ¿ Jun 11, 2009 23:40 |
|
Yeah because it wouldn't run if it had it Edit: I see what you mean: s/::/ / Lexical Unit fucked around with this message at 00:59 on Jun 12, 2009 |
# ¿ Jun 11, 2009 23:44 |
|
That was surely their intention, but w/o use strict the bare text false becomes a string literal which evaluates to true
|
# ¿ Jun 12, 2009 03:27 |
|
This code is now my favorite code:code:
|
# ¿ Jul 7, 2009 18:01 |
|
Painless posted:among other crimes code:
|
# ¿ Jul 7, 2009 21:44 |
|
gibbed posted:This is nitpicking and platform specific, although the cerr thing is stupid, yes. I'm not sure about Painless's point about "creating a T instance makes the byteswap a lot less generic." The function is already too generic because it accepts things like struct foo { int i; float f; };, std::complex<float>, int a[10], ... Normally yes you might want to avoid using a default constructor unless necessary because there's no reason to enforce the type has a default constructor if you don't need to. But in this case I don't think ByteSwap() should work at all on non-integral types, which are all default-constructible (obviously). Printing an error message is unacceptable as well. There's code that attempts to call ByteSwap() on long doubles, which can exceed (and usually do) 8 bytes in size. It's evident from the history of this file that it's intended to be the end-all to byteswaping for a wide swath of our codebase. That it's intended to "just work" on floating point types. It does not. As for the runtime switching, I re-coded it as a compile-time switch by just using templates and am seeing a 4x to 16x speed improvement. There are other issues, namely: Nitpicky, but: "ByteSwap() - CamelCase" vs "swap_data() - lowercase_underscore"; just pick one. Why should a for loop calling ByteSwap() be slower than a single call to swap_data()? It shouldn't, and it doesn't have to be. Testing has shown that swap_data() is up to 10x faster than a loop over calls to ByteSwap(). The code is loving lazy. As I already said, the code is too generic. I actually had the guy who wrote the code in my office the other day and he was saying things like, "well it's a template so you can't construct what types it accepts at all! A template accepts everything, you know, that's why it's called a template." A simple application of traits types and the error message isn't necessary and ByteSwap() only compiles when it's being used correctly. Another thing, did you notice the signature of swap_data()? void swap_data(T* data, int n). What isn't immediately obvious is that n here is supposed to be the size of T * number of Ts. Why not avoid the issue entirely with a better signature? Or at least make the parameter size_t size or something for fucks sake. code:
sex offendin Link posted:There is no generalized way to byte-swap IEEE 754 numbers anywhere, they are for all intents and purposes non-portable. I'm honestly asking, wouldn't this work? Lexical Unit fucked around with this message at 04:06 on Jul 8, 2009 |
# ¿ Jul 8, 2009 04:03 |
|
So if you leveraged char* to do the swapping rather than a union hack, and for floating point types you returned an accommodating integer type rather than storing a byteswapped floating point value back into a floating point type, would you be reasonably safe then? Probably due to lovely websites found through google: quote:the compiler very probably will return the double return value in an FPU register, and if not then, at some point the value may be loaded into an FPU register. This means the swapped result is loaded into an FP register, which then means the FP unit will take a look at the number, and then the fun begins. Lexical Unit fucked around with this message at 04:29 on Jul 8, 2009 |
# ¿ Jul 8, 2009 04:20 |
|
Nevermind. I really need some sleep. What you say makes perfect sense.
Lexical Unit fucked around with this message at 05:50 on Jul 8, 2009 |
# ¿ Jul 8, 2009 05:38 |
|
code:
Edit: wow http://bytes.com/groups/cpp/621474-setting-every-bit-all-members-class-0-a This kind of shortcut had never even occurred to me... Lexical Unit fucked around with this message at 21:15 on Jul 23, 2009 |
# ¿ Jul 23, 2009 21:09 |
|
Haha, same file:code:
|
# ¿ Jul 23, 2009 21:19 |
|
pokeyman posted:
code:
|
# ¿ Aug 11, 2009 19:15 |
|
Tell me about it! That stupid code accepts things like IIII and IIV. Madness.
|
# ¿ Aug 12, 2009 01:13 |
|
code:
|
# ¿ Aug 12, 2009 18:50 |
|
code:
|
# ¿ Aug 19, 2009 20:55 |
|
|
# ¿ Apr 29, 2024 05:37 |
|
Oh the things I could draw if posts were whiteboards...
|
# ¿ Aug 19, 2009 22:36 |