9

IsIdentical(object l, object r {
if (l.m_Lorum == r.m_Lorum)
if (l.m_Lorum2 == r.m_Lorum2)
if (l.m_Lorum3 == r.m_Lorum3)
if (l.m_Lorum4 == r.m_Lorum4)
if (l.m_Lorum5 == r.m_Lorum5)
if (l.m_Lorum6 == r.m_Lorum6)
if (l.m_Lorum7 == r.m_Lorum7)
if (l.m_Lorum8 == r.m_Lorum8)
if (l.m_Lorum9 == r.m_Lorum9)
return true;
return false;
}

//FML..

Just do this:

return (l.m_Lorum1 == r.m_Lorum1 &&
l.m_Lorum2 == r.m_Lorum2 &&
l.m_Lorum3 == r.m_Lorum3 &&
l.m_Lorum4 == r.m_Lorum4 &&
l.m_Lorum5 == r.m_Lorum5 &&
l.m_Lorum6 == r.m_Lorum6 &&
l.m_Lorum7 == r.m_Lorum7 &&
l.m_Lorum8 == r.m_Lorum8 &&
l.m_Lorum9 == r.m_Lorum9);

Comments
  • 7
    FFS... CODE FORMATING DEVRANT!!!! We NEED this!
  • 9
    Even better don't do it at all...

    Hashing?
  • 8
    @0x0000FFFF There is no code formatting on devRant on purpose.
    devRant is a place for developers to rant and hang out discussing the quirks of beeing a developer.
    With code formating newbies would storm in and ask to fix their CS homework. And for that there is StackOverflow.

    However there is a bot from a devRanter (Skayo) which fetches the rant and generates an image of a rant as formated code.
  • 2
    I'd rather collect them into an array and loop over it. And possibly define it as the == operator instead of a separate function.
  • 0
    @0x0000FFFF Or check what is not equal and return false on first non equal match? // cases when equality isn't determined along all properties, so hash checking is not an option.. crazy case, car is the same if name, model, engine etc match, but color can be different or sth..
  • 2
    return Object.keys(l).findIndex(key => l[key] !== r[key]) === -1;

    I think I am a js guy 🤷‍♂️
  • 0
    r.hashCode == r.hashCode
  • 3
    @highlight
    IsIdentical(object l, object r {
    if (l.m_Lorum == r.m_Lorum)
    if (l.m_Lorum2 == r.m_Lorum2)
    if (l.m_Lorum3 == r.m_Lorum3)
    if (l.m_Lorum4 == r.m_Lorum4)
    if (l.m_Lorum5 == r.m_Lorum5)
    if (l.m_Lorum6 == r.m_Lorum6)
    if (l.m_Lorum7 == r.m_Lorum7)
    if (l.m_Lorum8 == r.m_Lorum8)
    if (l.m_Lorum9 == r.m_Lorum9)
    return true;
    return false;
    }

    //FML..

    //Just do this:

    return (l.m_Lorum1 == r.m_Lorum1 &&
    l.m_Lorum2 == r.m_Lorum2 &&
    l.m_Lorum3 == r.m_Lorum3 &&
    l.m_Lorum4 == r.m_Lorum4 &&
    l.m_Lorum5 == r.m_Lorum5 &&
    l.m_Lorum6 == r.m_Lorum6 &&
    l.m_Lorum7 == r.m_Lorum7 &&
    l.m_Lorum8 == r.m_Lorum8 &&
    l.m_Lorum9 == r.m_Lorum9);
  • 1
  • 1
    @0x0000FFFF that's a possible solution to your problem. Just delete the comment after highlight created the image for you.
  • 3
    The question is... why are the member variables numbered? It seems both objects should have some kind of fixed-length vector.

    I believe std::vector implements == in C++, so you can just do a single comparison for the whole vector, without the need for a loop.
  • 0
    @p100sch Yeah this is already way better. it was also about the indentation. how stupid it looked with 10+ nested if statements.
  • 0
Add Comment