|
HappyHippo posted:For 11,000 lines. This is in C#. Ignoring problems with the program's structure, I was able to turn this into about 5 lines of code with reflection. Then you better start posting your own code too, bub.
|
# ? Sep 8, 2008 03:15 |
|
|
# ? May 13, 2024 23:02 |
|
HappyHippo posted:Hmm
|
# ? Sep 8, 2008 15:36 |
|
Just ran across this while adding on some functionality to a project...code:
So that line grabs the user's third-party ID from the CGI request. Nothing weird, but then 20 lines below that in the same method... code:
|
# ? Sep 8, 2008 18:40 |
|
Victor posted:Wait, so you have a class with 5,500 fields? I'm hoping it's more than one class and he could make into a single method that works for everything.
|
# ? Sep 8, 2008 18:47 |
|
ashgromnies posted:Just ran across this while adding on some functionality to a project... code:
|
# ? Sep 8, 2008 20:03 |
|
Jethro posted:I don't know much Perl, but doesn't the my in front of $id and $user hide those variables within the scope of the if statement? So if you were commenting this, it might go something like: Yeah, it does redefine $id lexically but it's still ridiculous and unmaintainable because at one point $id refers to the third-party ID then in the same method they change it lexically to point to our ID. And they already have an instance of the user - they call get_user_id() on the currently instantiated user, then grab him again.
|
# ? Sep 8, 2008 20:15 |
|
Victor posted:Wait, so you have a class with 5,500 fields? Correct. They have a script to make this file. For those interested, my solution was something like this code:
|
# ? Sep 8, 2008 21:08 |
|
Use Type.GetField(), don't use Type.GetFields() and loop through (possibly) all 5500 of them.
|
# ? Sep 8, 2008 21:16 |
|
Mustach posted:Use Type.GetField(), don't use Type.GetFields() and loop through (possibly) all 5500 of them. Now that I think about it, that's probably what I did. I was trying to remember without actually having the code to look at. Edit: VVV Thanks :P HappyHippo fucked around with this message at 00:48 on Sep 9, 2008 |
# ? Sep 8, 2008 21:57 |
|
HappyHippo posted:Now that I think about it, that's probably what I did. I was trying to remember without actually having the code to look at. Nice save.
|
# ? Sep 8, 2008 22:49 |
|
code:
|
# ? Sep 9, 2008 15:29 |
|
I've been reluctant to post in here, since most of the things I see would take too much explaining to be funny. But this one takes the cake, and I have to share it:code:
This code is almost equivalent: code:
|
# ? Sep 9, 2008 19:03 |
|
This is one of my own. It was a file system for a disk simulator written in C for an operating systems class. I was writing a function that would copy disk blocks from cache to a buffer, and it was baffling me because no matter how big the block being copied was, the buffer would only end up with 4 bytes of data in it. I agonized over it for ages before realizing I was allocating the buffer like so:code:
|
# ? Sep 10, 2008 04:08 |
|
^^^^^ Probably because code:
Zhentar posted:
What language is that?
|
# ? Sep 11, 2008 09:47 |
|
RegonaldPointdexter posted:
it's sizeof in C, case sensitive...
|
# ? Sep 11, 2008 14:19 |
|
I almost never write C
|
# ? Sep 11, 2008 14:44 |
|
RegonaldPointdexter posted:What language is that? MUMPS
|
# ? Sep 11, 2008 15:25 |
|
Trying to understand even one line of this code base makes me cry. I think I need a shrink. Hmm, I wonder what's going on here? code:
code:
code:
code:
code:
code:
code:
code:
code:
I've been trying to wrap my head around this one line of code for hours and I still have no idea. And none of it is commented, in case you feel that ifpf67_ptr, FP_MCOM_CSMSST or FP_MCOM_MSOFBF aren't descriptive enough names for you.
|
# ? Sep 11, 2008 16:01 |
|
meba rhodium posted:
Calling Nebby here to ILLUSTRATE TO YOUR PLEBE BRAIN how SUPERIOR HUNGARIAN NOTATION is.
|
# ? Sep 11, 2008 16:57 |
|
deimos posted:Calling Nebby here to ILLUSTRATE TO YOUR PLEBE BRAIN how SUPERIOR HUNGARIAN NOTATION is. Obviously we just don't see the light here. HUNGARIAN WILL SAVE YOU FROM THE DEVIL.
|
# ? Sep 11, 2008 17:22 |
|
code:
Mustach fucked around with this message at 18:01 on Sep 11, 2008 |
# ? Sep 11, 2008 17:59 |
|
meba rhodium posted:I've been trying to wrap my head around this one line of code for hours and I still have no idea. What does it look like if you just view the preprocessed code?
|
# ? Sep 11, 2008 18:02 |
|
It looks like what I posted above you. All on one line, of course.
|
# ? Sep 11, 2008 18:06 |
|
Mustach posted:
Sure thing, let's see... code:
Vanadium posted:What does it look like if you just view the preprocessed code? I still haven't managed to properly run this source file through just the preprocessor without getting an endless amount of include problems. Working on that. meba rhodium fucked around with this message at 18:15 on Sep 11, 2008 |
# ? Sep 11, 2008 18:10 |
|
Going bottom up, ive tried to seperate what this does.php:<? //Input: p_msdes //1. Calulate an index int index=(p_msdes->mstb[0]).ofbf; //2. Access p_msdes->heap (a byte array apparently) via that index A=(&((byte *)p_msdes->heap)[index]; //3. First cast: pointer to Fp_mcom_bfhd Fp_mcom_bfhd * B=(Fp_mcom_bfhd *)A; //4. Dereference pointer, add sizeof(Fp_mcom_bfhd) and interpret as pointer to void(?) void * C=((void *)&B[1]); //5. Second cast: pointer to FP_msghdr FP_msghdr * D=(FP_msghdr *)C; //6. Dereference pointer, add sizeof(FP_msghdr) and interpret as pointer to Msg_hd (?) Msg_hd * E=((Msg_hd *)&D[1]); //7. If E->st_of (maybe a pointer?) contains anything but 0, cast E to (char *) (???) and add that, if(E->st_of != 0) int F=(char *)E + E->st_of; //or set 0 else int F=0; //8. Finally, last Cast: pointer to Ifpf_0067. Ifpf_0067 * ifpf67_ptr = (Ifpf_0067 *)F; //If E->st_of is 0 then this is the nullpointer.?> Gotta love inherently obfuscating programming.
|
# ? Sep 11, 2008 19:01 |
|
From reddit:quote:It's just a parser of four levels of message headers, where the start of the payload is either at the end of the header, or at some offset specified by the header.
|
# ? Sep 11, 2008 20:04 |
|
Whoever wrote MH_ADDR_ST() is an rear end in a top hat for writing a macro that re-evaluates its argument three times. "Who needs functions or temporary variables? I know what I'm doing! It's a macro, it'll be efficient no matter what!" Beaten, but whatever I figured it out without having a clue so I'm posting this diagram: code:
|
# ? Sep 11, 2008 20:21 |
|
Ugh... why is this page taking forever to load?!?!? Click here for the full 800x587 image. oh ..... dammit.
|
# ? Sep 11, 2008 20:48 |
|
fansipans posted:Ugh... why is this page taking forever to load?!?!? I am in awe.
|
# ? Sep 11, 2008 21:16 |
|
Awesome, thanks everyone for the help. One more line down, only a few thousand to go!
|
# ? Sep 12, 2008 13:40 |
|
So at my work we use an internal software, called cataloguer. It takes in a single file or folder and a metadata file, that contains a whole bunch of information about the file or folder. Then writes this information to an Oracle server. Simple right? Well the guy who developed it, left around a year ago. The whole software is only about... 250k lines of C code. The code has 0 comments, and all the variable names have no vowels. And are generally abbreviated, if there is something already with the same abbrevated name. Then he adds a number next to it. So lets say: buffer becomes! bffr then instead of using lets say a DIFFERENT loving NAME, he uses, bffr001 further away. Now okay, so we just need to make a small change... right? So we shouldnt have to mess with the code. Theres alot of wonderful hex address attached to variables, and a little bit of ASM code here and there. Why are we doing (void ***)rspu.sttmnt = {0, 0, 0, 0, 0, 1, ........ } What the I dont know what that does. Period. Okay whatever. Huh, looks like thats supposed to be the SQL statement you want to execute, i'm confused. The statement, is an array of, unsigned ints...? Well thats retarded, we should just see how this connects to the SQL server, i guess and write some sort of workaround. Then we all realized. What SLCT_OFFST = "0x0fb8d2b" does. We realized why we need to install the specific build of the oracle client(7i)... The system, basically reads the username and password from a plain textfile, starts the oracle client GUI software. Does a shitton, of random memory hacks, and injects the SQL statement we want into the client interface and then it shoves it on the SQL server. I don't know who this man was, but he is a horrible horrible jerk. We're upgrading to Oracle 11, in two weeks, and the whole work environment rests on this software. This is why the software does extremely werid poo poo, when i try to run it using oracle 11 and just doesn't work. We can't push back the deadline, and i know its our fault. But gently caress.
|
# ? Sep 15, 2008 22:44 |
|
I was digging through a 130k line device driver (yeah, wtf) today, and found this gemcode:
|
# ? Sep 16, 2008 01:16 |
|
Well this is certainly an interesting method of flow controlcode:
|
# ? Oct 2, 2008 06:58 |
|
This line made me laugh and scratch my head at the same time:code:
|
# ? Oct 2, 2008 09:44 |
|
Now your code is compatible with the Neutral Zone. Congratulations ! Not a code sample, but I just read our company's coding standards: code:
|
# ? Oct 2, 2008 20:26 |
|
That just means don't use full Hungarian with i for integers and sz for null-terminated strings and useless stuff like that, but do note whether something is a pointer or a reference.
|
# ? Oct 2, 2008 20:43 |
|
I understand that, but obviously they realize that descriptive variable names are a good thing, so why stop with pointers/references ? If it's beneficial to know that something's a pointer, then it's just as useful to know that something is an unsigned integer. pSomeText would be okay, but szSomeText wouldn't? Weirdness!
|
# ? Oct 2, 2008 21:33 |
|
Cross_ posted:I understand that, but obviously they realize that descriptive variable names are a good thing, so why stop with pointers/references ? If it's beneficial to know that something's a pointer, then it's just as useful to know that something is an unsigned integer. pSomeText would be okay, but szSomeText wouldn't? Weirdness! Uh, no. Pointers, references and plain old variables have different semantics and are accessed differently. The difference between an unsigned integer and a signed integer is often accidental - if you just automatically make an int, but you know it'll never get a value less than 0, you might want to change it to an unsigned int later to get more range. Now you either have to rename your iWhatever variable to uiWhatever, or the name no longer matches the type.
|
# ? Oct 2, 2008 21:49 |
|
So would you prefix a smart pointer object variable with p?
|
# ? Oct 2, 2008 22:11 |
|
|
# ? May 13, 2024 23:02 |
|
JoeNotCharles posted:Uh, no. Pointers, references and plain old variables have different semantics and are accessed differently. quote:Now you either have to rename your iWhatever variable to uiWhatever, or the name no longer matches the type.
|
# ? Oct 2, 2008 22:33 |