496
CompareBooleans (sh.itjust.works)
top 50 comments
sorted by: hot top controversial new old
[-] just_an_average_joe@lemmy.dbzer0.com 104 points 3 months ago

Wait areBooleanEqual returns false when they are equal?

[-] not_woody_shaw@lemmy.world 9 points 3 months ago

That's not even the worst part. What the fuck does a function named Compare_anything do? Does it return anything? It sounds like nothing but a side effect.

[-] BatmanAoD@lemmy.world 7 points 3 months ago

The unnecessary and confusing functions are horrible, yes, but I'd still say that the fact that they're wrong is the "worst" part.

load more comments (1 replies)
[-] bleistift2@sopuli.xyz 80 points 3 months ago

Don’t forget the invocation

if (CompareBooleans(a, b) == true)
[-] magic_lobster_party@fedia.io 57 points 3 months ago

if (CompareBooleans(CompareBooleans(a, b), true))

[-] TriflingToad@lemmy.world 8 points 3 months ago

I don't like this thread anymore :(

load more comments (1 replies)
[-] min@lemmy.sdf.org 4 points 3 months ago

that... actually works...

[-] MyTurtleSwimsUpsideDown@fedia.io 16 points 3 months ago

elseif(CompareBooleans(b,a) != false)

[-] becausechemistry@lemm.ee 55 points 3 months ago

Management: Gee whiz, we really have no idea how to gauge productivity to decide who gets promoted. We could manage. Or, better, we could just have someone write a script that pulls info from git on how many lines of code each person has written.

Programmers:

[-] carl_dungeon@lemmy.world 51 points 3 months ago

There’s no way, that’s so insane it has layers.

[-] Ledivin@lemmy.world 18 points 3 months ago

At first, I thought the shitty methods were the joke 😱😱😱

[-] aiden@lemm.ee 48 points 3 months ago

This is code after working 16 hours

[-] AbsoluteChicagoDog@lemm.ee 35 points 3 months ago

"You aren't writing enough lines of code!" - Management

[-] LovableSidekick@lemmy.world 7 points 3 months ago

My boss's boss, a former Ops manager who liked to keep track of system stats, once asked her why the CPU usage on the dev box had decreased that month. Weren't the devs doing any work?

[-] Grandwolf319@sh.itjust.works 27 points 3 months ago

Two wrongs don’t make a right, but sometimes in programming, two bugs can cancel each other out.

Whoever wrote this is more than capable of using it incorrectly.

[-] Acters@lemmy.world 20 points 3 months ago* (last edited 3 months ago)

Those are rookie lines of code numbers right there.
I would have done it without the ==

internal static bool AreBooleansEqual(bool orig, bool val)
{
    if(orig) 
    {
        if(val)
            return false
        return true
    }
    if(val)
        return true 
    return false
}

Don't know why their code returns false when they are equal but I'm not going to dig through old code to refactor to use true instead of false.

[-] Xanvial@lemmy.world 8 points 3 months ago

you can also use XOR operation

return (X || Y) && !(X && Y)
load more comments (1 replies)
[-] InFerNo@lemmy.ml 4 points 3 months ago

Put more curly brackets around your if (val) true statement for 4 more lines, put elses in there for more lines even.

[-] Acters@lemmy.world 7 points 3 months ago* (last edited 3 months ago)

I should have created a local variable to store the result variable and return after the if statements. I just couldn't help to make it look partially nice. My brain just doesn't think at this high caliber of LOC optimizations.

New optimized LOC version:

internal static bool AreBooleansEqual(bool orig, bool val)
{
    bool result;
    if(orig) 
    {
        if(val)
        {
            result = false;
        }
        else
        {
            result = true;
        }
    }
    else
    {
        if(val)
        {
            result = true;
        }
        else
        {
            result = false;
        }
    }
    return result;
}

My previous LOC: 12
New LOC version: 27

[-] servobobo@feddit.nl 4 points 3 months ago

Surely we could optimize the return value with a switch statement and store the result as an integer to hide the compiler warning about our clearly correct code:

internal static bool AreBooleansEqual(bool orig, bool val)
{
    int result;
    if(orig) 
    {
        if(val)
        {
            result = 0;
        }
        else
        {
            result = 1;
        }
    }
    else
    {
        if(val)
        {
            result = 1;
        }
        else
        {
            result = 0;
        }
    }
    switch (result)
    {
         case(1):
             return true;
         case(0):
             return false;
         default:
             return AreBooleansEqual(orig, val);
    }
}

New LOC: 35

load more comments (2 replies)
[-] Omega_Jimes@lemmy.ca 20 points 3 months ago

Is this part of Elons "How many lines of choice have you written?" interview?

[-] Elgenzay@lemmy.ml 17 points 3 months ago
[-] Jerkface@lemmy.world 7 points 3 months ago
load more comments (1 replies)
[-] RogueBanana@lemmy.zip 5 points 3 months ago

I can definitely understand why they did that but it's still very funny

load more comments (8 replies)
[-] magic_lobster_party@fedia.io 16 points 3 months ago

My guess to why there’s two functions is because it was originally only internal, and the programmer realized they needed public as well, but changing internal to public is too scary so they created a new method instead.

load more comments (1 replies)
[-] mlg@lemmy.world 16 points 3 months ago

"We need to obfuscate our code to prevent reverse engineering"

The obfuscation in question:

[-] zarkanian@sh.itjust.works 16 points 3 months ago

If this were a Node module, I wouldn't even be surprised.

[-] marx2k@lemmy.world 13 points 3 months ago

Clearly it should be return orig == val

Duh

[-] offspec@lemmy.world 34 points 3 months ago

To match the current behavior it should be orig != val

[-] marx2k@lemmy.world 4 points 3 months ago

You're hired. Can your start on Monday?

[-] Moah 13 points 3 months ago

I'm a bit disappointed there isn't a call to GetBooleanValue in there

[-] gwilikers@lemmy.ml 10 points 3 months ago

This is your brain when you OD on OOP.

[-] Moah 17 points 3 months ago

There's literally nothing related to OOP in this snippet.

[-] davidagain@lemmy.world 5 points 3 months ago* (last edited 3 months ago)

You're right, this is just not oop AT ALL.

For the correct OOP solution, you would need consider whether this can be thought of as a kind of stateless leaf method, and therefore implement it as an abstract (singleton) factory, but on the other hand, if you're using a context object with the registry pattern, you should probably do this properly with IoC containers. Of course, if your object graph isn't too complex or entangled, you could always just do constructor injection but you risk manging your unit tests, so I would go cautiously if I were looking in that direction.

[-] collapse_already@lemmy.ml 5 points 3 months ago

Shouldn't there be a call to the boolean comparison microservices server in there somewhere? Also, we should consider the possibility that booleans and their operators could be overloaded to do something else entirely. We might need a server farm to handle all of the boolean comparison service requests.

[-] davidagain@lemmy.world 4 points 3 months ago

You're so right, I didn't think of that. Maybe I'm not cut out to be a manager in IT.

load more comments (1 replies)
[-] nova_ad_vitum@lemmy.ca 5 points 3 months ago

I love how OOP devolves into shoving code up it's own ass.

[-] Omgpwnies@lemmy.world 4 points 3 months ago

I was just thinking it needed more factories

load more comments (1 replies)
load more comments (1 replies)
[-] j4k3@lemmy.world 10 points 3 months ago

!NOT

Who's there?

!!Naughty Knots

[-] thenextguy@lemmy.world 8 points 3 months ago

Where are the unit tests?

[-] DmMacniel@feddit.org 8 points 3 months ago

But how do you test for FILE_NOT_FOUND?

[-] Treczoks@lemmy.world 7 points 3 months ago

Straight from the famous book "Making LOCs for Dummies"

[-] LovableSidekick@lemmy.world 6 points 3 months ago
[-] angrystego@lemmy.world 6 points 3 months ago

I misread it as CompareBolians. No more Star Trek memes for me today.

[-] WhiskyTangoFoxtrot@lemmy.world 5 points 3 months ago

Many Bolians died bringing us this information.

[-] kaffiene@lemmy.world 5 points 3 months ago

WTAF? Is this written by a hallucinating AI?

load more comments (3 replies)
[-] 1stTime4MeInMCU@mander.xyz 5 points 3 months ago

Thanks I hate it

load more comments
view more: next ›
this post was submitted on 28 Oct 2024
496 points (100.0% liked)

Programming Humor

2863 readers
1 users here now

Related Communities !programmerhumor@lemmy.ml !programmer_humor@programming.dev !programmerhumor@kbin.social !programming_horror@programming.dev

Other Programming Communities !programming@beehaw.org !programming@programming.dev !programming@lemmy.ml !programming@kbin.social !learn_programming@programming.dev !functional_programming@programming.dev !embedded_prog@lemmy.ml

founded 2 years ago
MODERATORS