We’re not going to look at code today, and instead, we’re going to talk about a code metric. Specifically, “NPath complexity”.
NPath complexity is a good metric to track, and many static analyzers will do it. Formally written, it’s defined: “The NPath complexity of a method is the number of acyclic execution paths through that method.” Or, more simply, not counting loop iterations, this is how many branches you have in a single method.
Obviously, for simplicity’s sake, this number should be small. Hell, ideally, it should be small enough that you can count it on your fingers. Ideally, small enough that you can count it on your fingers after attempting to drunkenly operate a bandsaw with no training.
But a lot of code doesn’t hit that threshold.
Nikola‘s team decided it was time to start tracking some of those metrics. The tool they were using set the default threshold where it complains at 200- 200 different code paths in a single function.
Nikola didn’t provide the code. But she did provide a telling snippet from the report:
1508 The method setStatus() has an NPath complexity of 836081572200. The configured NPath complexity threshold is 200.
Obviously, that number is so large that it must be a bug- something about the code makes the static analyzer choke and fall over. But that’s it’s own kind of complexity- so complex it can’t be meaningfully studied to extract metrics. And the function is several thousand lines long. Why is something called setStatus so complicated? No idea. But it seems like Nikola has some refactoring ahead of her.
[Advertisement] Otter – Provision your servers automatically without ever needing to log-in to a command prompt. Get started today!
Jan wrote some code that set a property, and a few lines later had to write code to read that value- and the compiler complained. Which is what drew his attention to this C# code:
publicstring ViewNodeFilter
{
protectedget
{
if (viewNodeFilter.IsNotValid())
{
return"null";
}
returnnew JavaScriptSerializer().Serialize(viewNodeFilter);
}
set { viewNodeFilter = value; }
}
Now, one of the features of properties in C# is that the getter and setter can have different access levels, which we see here. It’s odd and unexpected, and when we look at the implementation, we can see why the getter is protected: it’s not a getter, it’s a JSON serializer.
But there’s a lot more oddness in here. First, the property is a string, so when we serialize it… we’re just serializing a string. Then there’s also the IsNotValid method, which is not part of string, which implies that it’s an extension method. Extension methods are a C# bit of syntactic sugar that allows you to write a function which accepts an object as a parameter (in this case, a string), but invoke the method as if it were a member function of the object. They can be powerful and useful, but this is peak “not how you use this”- every string gets a IsNotValid() method, this way, which is likely not what we want.
This is a surprisingly common problem in the .NET languages, though. Since you can attach code to getters and setters, but access looks just like an assignment expression, people put all sorts of surprising code in there. Would you expect foo = viewNodeFilterHolder.ViewNodeFilter to serialize to JSON? I wouldn’t. But since the data is a string, does it matter? Well, it does when I get surprised by the string "null".
All in all, this is an ugly little booby trap, that represents a pattern common in Jan’s application.
[Advertisement]
Keep the plebs out of prod. Restrict NuGet feed privileges with ProGet. Learn more.
Fugitive ex-Marine claims Trump assassination attempt faked – alleges that he shot Trump months ago, but both targets were actually inflatable decoys! Other conspiracy theorists assert that whole thing pre-recorded in film studio – like the fake moon landings – with crisis actors. Question remains – if only fake Trump targeted, where is the real Trump?
Prince George‘s recent encounter with a European princess at a high-profile soccer match in Germany has taken the internet by storm.
As Britain’s future king approaches his 11th birthday on July 22, he was spotted enjoying the Euro 2024 finalbetweenEngland and Spain in Berlin on July 14.
Prince George seemed to have a memorable outing as he was accompanied by his father, Prince William, who is the president of the Football Association (FA) and an avid follower of England’s national teams.
The Euro final earlier this month was not just a sports event but also a royal gathering. Joining Prince William and Prince George in the VIP box was King Felipe VI of Spain and his younger daughter, the 17-year-old Infanta Sofíaof Spain.
Prince George had a recent encounter with Infanta Sofía of Spain that went viral on social media
Seated next to their fathers, George and Sofía watched the thrilling match that concluded with Spain’s victory over England. The final score was 2-1.
Meanwhile, Princess Charlotte and Prince Louis were watching England’s Euro 2024 final clash against Spain on TV wearing matching t-shirts, according to a picture shared by the Prince and Princess of Wales’ social media account.
“England, your teamwork, grit and determination were an inspiration to all of us, young and old. Congratulations to Spain. W & C,” read their message.
Clips of 10-year-old Prince George’s interaction with Infanta Sofía were widely shared on social media.
The footage showed both of them greeting each other with a polite handshake, a moment that quickly went viral.
The young royals met while attending the Euro 2024 final between England and Spain this month with their fathers
The brief but charming exchange between the youngsters added a touch of royal elegance to the sports event.
“They finally met,” one said following the encounter.
“Wow the Infanta Sofia must be the only young European royal that’s met Prince George,” another wrote, while a third comment said, “I love that Sofia was the first to move towards George to greet him. She is wonderful.”
One social media said of their encounter, “Shes so sweet. how she was the first who move towards George”
The interaction between the young royals has a historical significance, as the British and Spanish royal families share a distant connection through King Felipe’s great-grandmother, Queen Victoria Eugenie (Ena) of Spain. Ena, born in England, was a granddaughter of Queen Victoria.
King Felipe VI was crowned king on June 19, 2014. He succeeded to the Spanish throne in 2014 following the abdication of his father, King Juan Carlos I.
Born on January 30, 1968, King Felipe VI is married to Queen Letizia, a former journalist born on September 15, 1972. Together, they have two daughters: Princess Leonor, the heir presumptive, and Infanta Sofía. The family is known for their modern approach to royal duties, with Queen Letizia being actively involved in social issues and King Felipe VI focusing on upholding democratic values in Spain.
Princess Leonor and Princess Sofia grew from being young girls to teenagers in the public eye.
Seated next to their fathers, George and Sofía watched the thrilling match that concluded with Spain’s victory over England, with a final score of 2-1
King Juan Carlos I abdicated the Spanish throne on June 19, 2014, after a reign of nearly 39 years. His decision came amid declining popularity due to scandals and health issues, paving the way for his son, King Felipe VI, to modernize the monarchy and restore public trust.
Currently, King Felipe VI and his wife, Queen Letizia, are surrounded by allegations of infidelity.
Journalist Jaime Peñafiel claimed that the Spanish monarch was “crushed and destroyed” over Queen Letizia’s alleged affair, according to his book titled Letizia’s Silences.
The king of Spain was “aware that Letizia was cheating on him in real time” with her rumored “lover” Jaime del Burgo, her ex-brother-in-law.
Her bodyguards are required to report on her whereabouts, and they allegedly joined her on a trip to New York in 2011, during which Jaime accompanied her, according to the claims in the book.
Infanta Sofía is one of two daughters shared by King Felipe VI and his wife, Queen Letizia
Jaime was married to Letizia’s sister from 2012 to 2014. He claimed, after the release of the bombshell book, that he is still in touch with Queen Letizia.
“We have shared many years of our lives together,” he said in an interview with Clarín, as quoted by the New York Post.
“We have been a family,” he added. “As I have always said, ours was not a relationship of lovers. The lover would be him, in any case. I mean Felipe.”
Following England’s defeat to Spain in the final of Euro 2024, King Charles wrote a letter to the English team, telling them to “hold [their] heads high.”
“Although victory may have eluded you this evening, nevertheless my wife and I join all my family in urging you and your support team to hold your heads high,” the British monarch wrote in the letter.
“Wow the Infanta Sofia must be the only young European royal that’s met Prince George,” one social media user remarked
“All those who have participated in sporting activities at any level will know how utterly despairing such a result can feel when the prize was so near – and will join me in sending heartfelt sympathy, even as we congratulate Spain,” he continued.
“But please know that your success in reaching the European Championship final is a really great achievement in itself, and one that brings with it the pride of a nation which will continue to roar for the Three Lions today – and in the many triumphs which I have no doubt lie ahead,” he went on to say.
People online found it adorable to see the two young royals have an encounter at the Euro 2024 final
Adrian M. lit up this blooper for us.
“Apparently Siemens Mobility wasn’t satisfied that a mere
95-year copyright term would be enough for the brochure
about their m60-series traffic light controller. I hope
I won’t have to wait until 2029 for a green light.” See for yourself here.
Mark W. thinks Doordash needs a kiss on the boo-boo to make it all better.
“Sometimes even a major app has a little
mishap, the software equivalent of skidding on a wet floor
or fumbling shuffling a deck of cards, and all they need
is a bit of reassurance.”
An Anonymous Cheapskate pinches every penny so hard
it shatters. We should start up a GoFundYou to help him buy this.
“I got a promotion price with a trade-in for the Galaxy
Watch 7 from Samsung, but the price is still too high.
I won’t pay a cent (or as in this case, a trillionth of a cent) over $79.99!”
Will S. found a takeaway that might be trying to help with the AC’s GFY.
“One of my local restaurants has some creative revenue side dishes.”
Michael R. is miffed at some other funding platform for
not taking his card of choice, sarcastically remarking
“Thank you crowdfunder.” I just want to know why he can
be so generous with Hackney and such a tightwad when it
comes to one of our own community here. C’mon Michael,
if everyone would just chip in a measly $0.000000000000001 each
(plus a $4 transaction fee for me) we could make sure our AC is
never late for dinner. Help us feed AC!
[Advertisement]
Continuously monitor your servers for configuration changes, and report when there’s configuration drift. Get started with Otter today!
Contrary to belief, Gen Zers have not called for Eminemto be canceled amid the release of Houdini, the lead single from the rapper’s latest studio album, The Death of Slim Shady (Coup de Grâce). Despite stirring disappointment, Marshall Mathers mostly sparked a battle of the generations.
Houdini, which was released on May 31, makes a punchline out of both Megan Thee Stallion’s 2020 shooting and contemporary identity politics.
The highly anticipated track opened at Number 2 on the Hot 100 singles chart, representing Eminem’s best solo showing since 2010, The New York Times reported on Sunday (July 14).
The success of Houdini inevitably challenges the notion that famous white men are adversely affected by “cancel culture” in their careers.
Gen Zers have not called for Eminem to be canceled
Gen Z, a generation deeply engaged with social media, often drives cancel culture, a phenomenon where public figures face backlash and potential career consequences for controversial actions or statements.
Nevertheless, Eminem’s 12th album, which arrived on Friday (July 12), has not been entirely free of criticism.
Among the questionable lyrics, the 51-year-old artist raps: “My transgender cat’s Siamese, identifies as Black, but acts Chinese.”
Eminem has been mocked since the release of Houdini
Taking to his TikTok page, 22-year-old Sasha Allen, who is notable for speaking about his trans identity, reviewed the rapper’s new album in a video that amassed over 1.4 million views.
“He talks about transgender people a lot,” Sasha told his 1.3 million followers. “I think he says Caitlyn Jenner’s name like eight f*”***g time.”
In his new album’s song Habits, the Grammy Awards winner raps: “I’m ’bout as much of a boy as Bruce Jenner is, ’cause I’m not a boy, I’m a man, b*tch, man-b*tch.
“My speech is free as his choice to choose gender is (man).”
Eminem also expresses: “All these pronouns, I can’t remember (damn). They or them, theirs? (Whose?) His or him, hers?”
Houdini is the lead single from the rapper’s latest studio album, The Death of Slim Shady (Coup de Grâce)
Sasha, a Gen-Zer, continued his review: “I’m f*****g annoyed because, you know, it’s not hard to, like, make funny jokes about transgender people.
“They’re really easy to make fun of, especially with, like, little one-liners in a f*****g rap.”
Eminem mentions Caitlyn Jenner again in his song Brand New Dance, where he can be heard saying: “I’ma have everybody jumpin’ to this, Caitlyn Jenner in the front row pumpin’ her fists, with a simple little twist and a flick of the wrist.”
Caitlyn is further mentioned in The Death of Slim Shady (Coup de Grâce)’s Evil, Antichrist, and Road Rage.
Sasha added: “I’m listening to [the album], and all it is is him saying something about trans people that’s, like, not even funny.”
The TikToker went on to criticize Eminem’s constant taunting of his cancelation, as exemplified by the song Trouble, in which the lyricist spits: “You gonna cancel me, yeah? Gen Z me, bruh?”
A reminder that Generation Z typically includes individuals born from 1997 to 2012.
Many Gen Zers on TikTok expressed just how little they cared for Eminem’s music
Sasha admitted: “I was sitting there listening to [the album] so ready to hear some crazy s**t, and all he did was say Caitlyn Jenner eight times.”
The critic argued: “No one even gives a f**k about Caitlyn Jenner anymore,” before revealing: “I’m a transgender Gen Z person sitting here listening to the f*****g album, like, waiting for you to cook up some s**t. Instead, you just say Caitlyn Jenner’s name and then yell at everyone to cancel you.”
Sasha concluded: “No one’s canceling you. I f*****g hate to break it to you. No one gives a f**k.”
Some people failed to understand that Gen Zers did not care enough to cancel Eminem
A TikTok user commented: “I used to be a big Slim Shady fan and I was hoping we were gonna get some old Eminem vibes but it just wasn’t funny and wasn’t even good.
“That whole style of rap has really just gone downhill.”
A person agreed: “I feel like he’s just grasping at straws to be relevant with that genre of like edge lord millennials and boomers.”
A person wondered: “I’m trying to figure out this album concept–was he trying to cancel himself (Eminem) or was he trying to cancel (and ultimately kill) the Slim persona so people would stop saying they want Slim back?”
Languages which do type-coercion are generally setting users up for failure. At some point, you’ll make some assumption about your inputs, and then type-coercion kicks in and changes what you expect. We see this all the time in JavaScript, and of course, in PHP. PHP booleans, for example, can surprise you: 0 is false, which is a common enough assumption, but so is "0"– the string zero. As are empty arrays.
But what if you wanted more control over it? Peter sends us this PHP he found:
$trueFalse = array('false', 'true');
This creates the trueFalse array such that it holds the stringsfalse and true. These are, in PHP-land, both true. But let’s set that aside, and look at how this array gets used:
$boolStr = @trueFalse[$some->integer->property];
Yes, this is their approach to converting a boolean to a user-readable string. Which, if you don’t know much about PHP, feels necessary. If you echo a boolean, it prints out as either a “1” or nothing. You need to use the function var_export, var_dump, or do an sprintf, or a ternary, a lot of other weird workarounds. But this solution also conceals another problem: a boolean variable which is true may be any nonzero value– which would break when we try and index the array by that.
I’ll let Peter share his thoughts:
I actually cannot determine if this is brilliant™ or just plain stupid, but i do love the fact that the array is called trueFalse while the values in order are false and true… does that mean that true is false and false is true?
No, Peter, I don’t think it means that, but I also don’t think it’s plain stupid. This is, despite its simplicity, advanced stupid.
Every photograph is an immortalized moment. Through the years, they become a time capsule of a bygone era, a reminder of how life was once.
The internet is rich in resources of noteworthy images from the past, and this subreddit is an excellent example. With over three million members, it has no shortage of pictures featuring landmark events and renowned figures, whether in monochrome or full color.
As part of Bored Panda’s recurring series of articles, we’ve compiled this best-of-all-time list for you to enjoy. Whether or not you’re a history buff, prepare to be fascinated and maybe even learn something new.
When accepting user input for things like, say, accessing the filesystem, you need to do some validation. Bad or inappropriate characters could lead to surprises that no one is going to like.
So when Christian first spotted this C# method called SanitizePath, he didn’t think much of it. But then he looked at the implementation…
publicstaticstringSanitizePath(string path, char replacementchar) {
string result = "";
try {
FileInfo fi = new FileInfo(path);
string filename = FileUtilities.ReplaceInvalidFileNameChars(fi.Name, replacementchar);
string pathname = FileUtilities.ReplaceInvalidPathChars(fi.DirectoryName, replacementchar);
result = Path.Combine(pathname, filename);
} catch (Exception e) {
Logger.Log(e);
result = path;
}
return result;
}
We accept an input path, and attempt to open it using FileInfo. Now, the fun thing about this is that if the path contains any sort of invalid characters, it throws an ArgumentException. But let’s assume there weren’t any invalid characters.
If there weren’t, and FileInfo was constructed successfully, we then split it by Name and DirectoryName, and replace invalid characters according to some rules not shared here. Then we combine them back together into a full path.
Now, this isn’t a strictly useless function- what their FileUtilities class considers “invalid” may be application specific, and completely unrelated to what the filesystem allows. They may, for example, want to prevent profanity from being in a filename, a clbuttic option. Though, since it says it replaces invalid chars, I suspect it’s avoiding certain letters- it’s possible that this wants to ensure that the files remain readable on different file systems (many a C# app needs to send text files to a mainframe, even today, and they can get real picky about what characters are in those filenames).
But let’s look at the exception path. If the filename can’t be opened because it’s invalid, we… log an error and return the input value. So SanitizePath will modify the strings if they are valid file paths, but if they’re invalid file paths, it just returns the invalid file path with no meaningful information for the caller- just a log message for an admin to check eventually.
And as for how useful this method actually is, well… Christian turned it into a no-op, and nothing about the application’s behavior changed. It has since been removed entirely.
[Advertisement] Otter – Provision your servers automatically without ever needing to log-in to a command prompt. Get started today!
Donald Trump selected Ohio senator and Hillbilly Elegy author J.D. Vance to be his 2024 vice presidential running mate, choosing a 39-year-old loyalist with celebrity status among conservatives. What do you think?
“It’s nice to finally be able to put a name to the scapegoat.”