Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Centripetal Horse
Nov 22, 2009

Fuck money, get GBS

This could have bought you a half a tank of gas, lmfao -
Love, gromdul

Illusive gently caress Man posted:

is there some gcc flag I can add so when he writes unreadable garbage like this, it won't compile? or am i the idiot for not being able to understand this at a glance?

This is the funniest thing I've read in this thread. I'm not entirely sure why, but the idea of this type of petty sabotage is hilarious to me. I actually laughed out loud at the thought of the poor bastard's confusion when gcc starts choking on his perfectly-fine-until-then code.

Adbot
ADBOT LOVES YOU

Jewel
May 2, 2009

You just have to enable -Wunreadable-code. Maybe -Why for good measure.

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

Jewel posted:

You just have to enable -Wunreadable-code. Maybe -Why for good measure.

The warning flag "hy" must be the sibling to the ruby library "ubygems".

Spatial
Nov 15, 2007

-fno-garbage

ahahaha

FlapYoJacks
Feb 12, 2009
Just compile it with -Ofast :colbert:

Dessert Rose
May 17, 2004

awoken in control of a lucid deep dream...
When people in later pages complain about how this thread isn't funny anymore I am going to direct them to this page.

Subjunctive
Sep 12, 2006

✨sparkle and shine✨

hackbunny is a golden god.

Bruegels Fuckbooks
Sep 14, 2004

Now, listen - I know the two of you are very different from each other in a lot of ways, but you have to understand that as far as Grandpa's concerned, you're both pieces of shit! Yeah. I can prove it mathematically.

Centripetal Horse posted:

This is the funniest thing I've read in this thread. I'm not entirely sure why, but the idea of this type of petty sabotage is hilarious to me. I actually laughed out loud at the thought of the poor bastard's confusion when gcc starts choking on his perfectly-fine-until-then code.

Get parasoft and enable all the rules and it's pretty much the same thing.

LOOK I AM A TURTLE
May 22, 2003

"I'm actually a tortoise."
Grimey Drawer
Would -Why explain the reasoning and justification behind obscure pieces of code? If it does I'd like to apply it to this if-statement (named changed slightly):

C# code:
if ((module == null && configGroup == null) ||
	(module == null && configGroup.ConfigurationGroupId ==
	config.ConfigurationGroup.ConfigurationGroupId) ||
	(configGroup == null && config.Module != null && module.ModuleId == config.Module.ModuleId) || 
	(configGroup == null && config.Module == null) ||
	(configGroup!= null && module!= null && config.Module != null && 
	configGroup.ConfigurationGroupId == config.ConfigurationGroup.ConfigurationGroupId &&
	module.ModuleId == config.Module.ModuleId) ||
	(configGroup!= null && module!= null && config.Module == null && 
	configGroup.ConfigurationGroupId == config.ConfigurationGroup.ConfigurationGroupId))
{
    // Do something.
}

PrBacterio
Jul 19, 2000

Suspicious Dish posted:

Window menus are kernel objects and are rendered in kernel mode.
Wait, is that actually true? The WndProc's for the WinAPI's builtin window classes run in kernel mode? Why on earth would they do that, I would have expected that to just live somewhere in Win32.dll or thereabouts :confused: Or is it ONLY the menus that do that, while, say, a listbox or button still runs in userland, as you would expect. But that would make even less sense, because why then isn't that also the case for menus.

Jabor
Jul 16, 2010

#1 Loser at SpaceChem

PrBacterio posted:

Wait, is that actually true? The WndProc's for the WinAPI's builtin window classes run in kernel mode? Why on earth would they do that, I would have expected that to just live somewhere in Win32.dll or thereabouts :confused: Or is it ONLY the menus that do that, while, say, a listbox or button still runs in userland, as you would expect. But that would make even less sense, because why then isn't that also the case for menus.

Large parts of the Windows UI runs inside the kernel because the performance implications of constantly mode-switching was a real concern back when it was first written.

History has proven it to be a pretty big mistake, but it's a very difficult thing to actually fix.

Illusive Fuck Man
Jul 5, 2004
RIP John McCain feel better xoxo 💋 🙏
Taco Defender

Harik posted:

That's some ugly-rear end workarounds for type punning, I think. I've played games like that when dealing with structured data on the wire, but I try to isolate it to a single function that's very clearly unpacking a char* buf into a C-struct.

I think it's doing this:
C code:
unsigned char offset;
memcpy(&offset, (unsigned char *)padded_src +i + current_block*4, 1);
memcpy((unsigned char *)&temp+3-i, byte_conversion+offset, 1);        
None of that explains why the mess is doing what it's doing, but at least the different steps are somewhat easier to follow. It's still awful and there's no excuse for it in 1990, much less 2014. It'd probably be easier to just explain what the code is actually doing:

C code:
/* <coworker> has volunteered to maintain this mess forever. */

oh, i know what it's supposed to be doing, and it is actually doing it correctly. It's just annoying because whenever I'm debugging and I see code like this I have to double check that this is true.

It's actually a multi-horror. This is part of a library to communicate through shared memory with a piece of hardware. Somebody wired up a fpga backwards or some poo poo, so we have to bitwise reverse every byte. Also we have to swap the endianness of each 4 byte word. Why he didn't just use be32toh() for the second part, I don't know. Here's the whole function.

C code:
const unsigned char byte_conversion[256] = {
        0x00, 0x80, 0x40, 0xc0, 0x20, ...

...

// TODO clean up all code
/**
 * The BUTTCHIP reads and writes 32-bit blocks in reverse order, so the byte 0x1a would read 0x58 on the BUTTCHIP.
 *
 * This method reverses ceiling('len'/4) 32-bit words in 'src' and places them in 'dest'.
 */
void reverse_32_bytes(void *dest, void *src, size_t len) {

    size_t current_block = 0;               // stores index of the 32 bit block we are reversing
    size_t i = 0;                           // stores index of the byte in the 32 bit block we are reversing
    void *padded_src;                       // stores contents at 'src' plus any necessary padding so that we convert only 32 bit blocks
    size_t padded_len = ((len+3)/4)*4;      // round up 'length' to nearest multiple of 4
    uint32_t temp = 0;                      // stores reversed word to be written to the 'dest' buffer

    if(!src || !dest || dest == src) {
        logerror("Invalid input");
        return;
    }

    if(len % 4 != 0) {
        logdbg("Length is not divisible by 4, will padd the end with '0' bytes");
    }

    // Allocate a pointer with space for padded_length bytes, copy into it the contents
    //  	of ptr word by word and clear any extra bytes
    if(!(padded_src = xalloc(padded_len))) {
        logerror("Failed to allocate %zu bytes of memory", padded_len);
        return;
    }
    my_memcpy(padded_src, src, padded_len/4);
    memset(((char *)padded_src)+len, 0, padded_len-len);

    // For each 32 bit block in the input, reverse it and place it at the end of the output buffer
    while(current_block < padded_len/4) {
        i = 0;
        while(i < 4) {
            *(((unsigned char *)(&temp))+3-i) = *(byte_conversion+(*((unsigned char *)padded_src+i+(current_block*4))));
            i++;
        }
        *((uint32_t *)dest+(current_block)) = temp;
        current_block++;
    }
    xfree(padded_src);
}

I think "TODO clean up all code" says it all. i'm 80% sure that padding poo poo is never used. i feel like this whole function could be replaced with
C code:
unsigned char *cdest = (unsigned char *) dest;
unsigned char *csrc = (unsigned char *) src;
uint32_t *wdest = (uint32_t *) dest;
int n_words = len / 4;

for (int i = 0; i < len; i++)
    cdest[i] = byte_conversion[csrc[i]];
for (int i = 0; i < n_words; i++)
    wdest[i] = be32toh(wdest[i]);

Illusive Fuck Man fucked around with this message at 14:43 on Oct 29, 2014

qntm
Jun 17, 2009

LOOK I AM A TURTLE posted:

Would -Why explain the reasoning and justification behind obscure pieces of code? If it does I'd like to apply it to this if-statement (named changed slightly):

C# code:
if ((module == null && configGroup == null) ||
	(module == null && configGroup.ConfigurationGroupId ==
	config.ConfigurationGroup.ConfigurationGroupId) ||
	(configGroup == null && config.Module != null && module.ModuleId == config.Module.ModuleId) || 
	(configGroup == null && config.Module == null) ||
	(configGroup!= null && module!= null && config.Module != null && 
	configGroup.ConfigurationGroupId == config.ConfigurationGroup.ConfigurationGroupId &&
	module.ModuleId == config.Module.ModuleId) ||
	(configGroup!= null && module!= null && config.Module == null && 
	configGroup.ConfigurationGroupId == config.ConfigurationGroup.ConfigurationGroupId))
{
    // Do something.
}

I don't know of any way to automagically explain or simplify that condition, but provided C# doesn't have any weirdness, it's equivalent to:

C# code:
if (
	(
		module == null ||
		config.Module == null ||
		module.ModuleId == config.Module.ModuleId
	) &&
	(
		configGroup == null ||
		configGroup.ConfigurationGroupId == config.ConfigurationGroup.ConfigurationGroupId
	)
) {
    // Do something.
}

LOOK I AM A TURTLE
May 22, 2003

"I'm actually a tortoise."
Grimey Drawer

qntm posted:

I don't know of any way to automagically explain or simplify that condition, but provided C# doesn't have any weirdness, it's equivalent to:

C# code:
if (
	(
		module == null ||
		config.Module == null ||
		module.ModuleId == config.Module.ModuleId
	) &&
	(
		configGroup == null ||
		configGroup.ConfigurationGroupId == config.ConfigurationGroup.ConfigurationGroupId
	)
) {
    // Do something.
}

Hey, nice! That actually makes some sort of sense now.

Illusive Fuck Man
Jul 5, 2004
RIP John McCain feel better xoxo 💋 🙏
Taco Defender
uuugggh i just realized everything is worse than i thought and he's literally reversing the endianness of everything the cpu sends to the microcontroller, even if it doesn't need reversing. The things that didn't need reversing in the first place are then reversed again in the code he wrote for the microcontroller. Also this is all done in a completely non-architecture safe way, which is a problem because this code will at some point need to run on different architectures.

with most of the operations it's literally:
cpu reverses every 4 bytes of a string of bytes and sends to microcontroller.
microcontroller reverses every 4 bytes of input and does stuff
microcontroller reverses every 4 bytes of output and sends back to cpu.
cpu reverses every 4 bytes of the output.

when we release, people are going to see this code. what the gently caress

Subjunctive
Sep 12, 2006

✨sparkle and shine✨

qntm posted:

I don't know of any way to automagically explain or simplify that condition, but provided C# doesn't have any weirdness, it's equivalent to:

C# code:

if (
	(
		module == null ||
		config.Module == null ||
		module.ModuleId == config.Module.ModuleId
	) &&
	(
		configGroup == null ||
		configGroup.ConfigurationGroupId == config.ConfigurationGroup.ConfigurationGroupId
	)
) {
    // Do something.
}

A tool that did such simplification automatically would print money.

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

Subjunctive posted:

A tool that did such simplification automatically would print money.

ReSharper does that in the .NET world, and yes, it prints money.

[edit]
Okay, it doesn't handle that particular monstrosity. But in general it can simplify expressions.

New Yorp New Yorp fucked around with this message at 16:25 on Oct 29, 2014

LOOK I AM A TURTLE
May 22, 2003

"I'm actually a tortoise."
Grimey Drawer

Ithaqua posted:

ReSharper does that in the .NET world, and yes, it prints money.

[edit]
Okay, it doesn't handle that particular monstrosity. But in general it can simplify expressions.

I suppose it would be dangerous to do the rewrite in the general case since the expression contains property accesses that could have side effects, and I'm guessing the rewritten version doesn't always access the properties the same number of times as the original.

BigPaddy
Jun 30, 2008

That night we performed the rite and opened the gate.
Halfway through, I went to fix us both a coke float.
By the time I got back, he'd gone insane.
Plus, he'd left the gate open and there was evil everywhere.


ReSharper is nice for lazy .Net devs (like me). Now if there was something like it for Apex then I would never need to think about writing neat code again.

Sedro
Dec 31, 2008

Subjunctive posted:

Allocating in hashCode sounds like a horror to me.
I just found out the hard way that java.net.URL's equals and hashCode make DNS lookups. What the hell were they thinking?

Sebbe
Feb 29, 2004

Sedro posted:

I just found out the hard way that java.net.URL's equals and hashCode make DNS lookups. What the hell were they thinking?

In case you haven't seen it, here's a relevant video about that.

Brain Candy
May 18, 2006

Illusive gently caress Man posted:

code:
    // For each 32 bit block in the input, reverse it and place it at the end of the output buffer
    while(current_block < padded_len/4) {
        i = 0;
        while(i < 4) {
            *(((unsigned char *)(&temp))+3-i) = *(byte_conversion+(*((unsigned char *)padded_src+i+(current_block*4))));
            i++;
        }
        *((uint32_t *)dest+(current_block)) = temp;
        current_block++;
    }
}

Apparently, your coworker is vunerable to for-loops.

pigdog
Apr 23, 2004

by Smythe

Sebbe posted:

In case you haven't seen it, here's a relevant video about that.

That is a good click.

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug
In a client's codebase:
code:
public enum LastProcessStatuses
{
    success,
    fail,
    budget
}
It's almost as good as the classic DailyWTF entry of "True, False, FileNotFound"

1337JiveTurkey
Feb 17, 2005

Ithaqua posted:

In a client's codebase:
code:
public enum LastProcessStatuses
{
    success,
    fail,
    budget
}
It's almost as good as the classic DailyWTF entry of "True, False, FileNotFound"

Perfect for a microtransaction-filled future where your procedure will return once you pay 50 IntelPoints.

Bognar
Aug 4, 2011

I am the queen of France
Hot Rope Guy

1337JiveTurkey posted:

Perfect for a microtransaction-filled future where your procedure will return once you pay 50 IntelPoints.

Otherwise, it throws an OutOfMoneyException.

Scaramouche
Mar 26, 2001

SPACE FACE! SPACE FACE!

It's me, I'm the horror. I wrote:
code:
Math.Truncate(((CDec(strWeight) - 0.1) * 10) / 10)
This results in zero. Always.

I meant:
code:
(Math.Truncate((CDec(strWeight) - 0.1) * 10) / 10)

Bognar
Aug 4, 2011

I am the queen of France
Hot Rope Guy
http://stackoverflow.com/questions/1006923/automating-office-via-windows-service-on-server-2008/1680214#1680214

To summarize, if you want to use PowerPoint automation through Interop in a Windows Service, you have to create a magic folder deep in the bowels of system32 - otherwise your program will just hang.

ATM Machine
Aug 20, 2007

I paid $5 for this

Sebbe posted:

In case you haven't seen it, here's a relevant video about that.

The more I learn about Java, the more I scream

pigdog
Apr 23, 2004

by Smythe

ATM Machine posted:

The more I learn about Java, the more I scream

As the video says though, FindBugs does report all of those issues.

Soricidus
Oct 21, 2010
freedom-hating statist shill

ATM Machine posted:

The more I learn about Java, the more I scream
Here's the fun part: the same kinds of gotchas certainly also exist in every language you like. You probably just don't know yet, because only a handful of languages, including Java, are sufficiently widely used and well understood for many people to be aware of such flaws.

thathonkey
Jul 17, 2012
Why is it that mediocre programmers think that writing mediocre code will grant them job security? Im so sick of hearing people say this "jokingly" when faced with criticisms (then they keep doing the same mediocre poo poo).

Internet Janitor
May 17, 2008

"That isn't the appropriate trash receptacle."

Soricidus posted:

Here's the fun part: the same kinds of gotchas certainly also exist in every language you like. You probably just don't know yet, because only a handful of languages, including Java, are sufficiently widely used and well understood for many people to be aware of such flaws.

Also in Java those gotchas exist predictably across platforms, rather than being related to the particular compiler, runtime library, computer architecture and phase of the moon under which your code was compiled and run.

HappyHippo
Nov 19, 2003
Do you have an Air Miles Card?

Subjunctive posted:

A tool that did such simplification automatically would print money.

You're in luck. http://www.wolframalpha.com/input/?...6+c+%26%26+d%29

With
code:
a: module == null
b: configGroup == null
c: config.Module == null
d: configGroup.ConfigurationGroupId == config.ConfigurationGroup.ConfigurationGroupId
e: module.ModuleId == config.Module.ModuleId

itskage
Aug 26, 2003


thathonkey posted:

Why is it that mediocre programmers think that writing mediocre code will grant them job security? Im so sick of hearing people say this "jokingly" when faced with criticisms (then they keep doing the same mediocre poo poo).

Yeah this is the worst kind of poo poo. I had a guy like that once. But he also had this philosophy of "I will write better code when I get paid better." Why not show that you can actually write good code in the first place and thus deserve better pay? I had zero evidence that he was capable of performing better. How dumb would I need to be?

Eventually fired him.



Also I ran into this today:

code:
Error executing code: object does not have method 'consturct'.
:negative:

QuarkJets
Sep 8, 2008

thathonkey posted:

Why is it that mediocre programmers think that writing mediocre code will grant them job security? Im so sick of hearing people say this "jokingly" when faced with criticisms (then they keep doing the same mediocre poo poo).

If they were capable of writing good code, they'd be doing that already.

Hughlander
May 11, 2005

Internet Janitor posted:

Also in Java those gotchas exist predictably across platforms, rather than being related to the particular compiler, runtime library, computer architecture and phase of the moon under which your code was compiled and run.

Count yourself lucky if you never came across a platform specific jvm issue. Not even talking about oracle vs open. We have a test suite of 2000+ tests that pass on OSX and hang on a deadlock in the test runner on Linux. Guess what our prod environment is.

FamDav
Mar 29, 2008

Hughlander posted:

Count yourself lucky if you never came across a platform specific jvm issue. Not even talking about oracle vs open. We have a test suite of 2000+ tests that pass on OSX and hang on a deadlock in the test runner on Linux. Guess what our prod environment is.

why are you developing not in a VM of your prod environment.

pigdog
Apr 23, 2004

by Smythe

Hughlander posted:

Count yourself lucky if you never came across a platform specific jvm issue. Not even talking about oracle vs open. We have a test suite of 2000+ tests that pass on OSX and hang on a deadlock in the test runner on Linux. Guess what our prod environment is.

That's plausible, but in such case my money would be on a bug in multithreaded code (unsafe publishing, race condition, etc) that may manifest itself differently on different platforms, but is a code bug nonetheless.

Adbot
ADBOT LOVES YOU

ijustam
Jun 20, 2005

Ithaqua posted:

I did two days of unit testing training with one of my clients last week. It was pretty great, they went from not understanding the difference between a unit test and an integration test to actively discussing the pros and cons of methods of IOC and how they're going to tackle isolating their dependencies going forward.

However, they had a consultant go in and write them a shitload of "unit" tests 4 or 5 years ago. The consultant didn't understand unit testing, they didn't understand unit testing, and no one really cared about the results enough to run them, anyway. They have about 800 tests, 300 fail because of database dependencies. They do have some unit tests in there, though, and some of them are theoretically valuable. They asked me to take a look at their tests and ferret out the real unit tests and see if any of the integration tests are salvageable. It's a worthless task, but hey, it's billable work. :shrug:

Not surprisingly, most are not. However, I came across one little corner of the application where someone chose to use Spring .NET for IOC. I was shocked! They wrapped Spring .NET up in a factory, so you can request an object, and Spring gives you back the appropriate implementation as defined in an XML file. I'm pretty much totally unfamiliar with Spring .NET, but the approach seemed solid.

Their factory class is a singleton. In the constructor, they use the following logic to determine where to read the configuration XML from:

code:
            string[] paths = new string[1];

            string handlerLocation = SiteSettings.HandlerLocation;

            if (handlerLocation.StartsWith("/"))
            {
                if (HttpContext.Current != null)
                {
                    paths[0] = HttpContext.Current.Server.MapPath(handlerLocation);
                }
                else
                {
                    paths[0] = SiteSettings.GetString("WebRootPath") + handlerLocation;
                }
            }
            else
            {
                paths[0] = handlerLocation;
            }

            _ctx = new XmlApplicationContext(paths);
SiteSettings is their custom wrapper around Commerce Server, which is some sort of eCommerce solution that I know nothing about, but requires a full application installation and database in order to function.

So their IOC container is tightly coupled to a database and an installation of some software on the machine where the tests are going to run. Minimum.

I ran into "tests" the other day that required a MongoDB instance, a web service, and some local console app :psyduck:

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply