Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
@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. -
I'd rather collect them into an array and loop over it. And possibly define it as the == operator instead of a separate function.
-
@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..
-
hack64144yreturn Object.keys(l).findIndex(key => l[key] !== r[key]) === -1;
I think I am a js guy 🤷♂️ -
p100sch14464y@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); -
p100sch14464y@0x0000FFFF that's a possible solution to your problem. Just delete the comment after highlight created the image for you.
-
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. -
@p100sch Yeah this is already way better. it was also about the indentation. how stupid it looked with 10+ nested if statements.
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);
rant
if if if if if statment dev c++ code fuck ups