Skip to main content

CodeSOD: Find the First Function to Cut

1 month 1 week ago

Sebastian is now maintaining a huge framework which, in his words, "could easily be reduced in size by 50%", especially because many of the methods in it are reinvented wheels that are already provided by .NET and specifically LINQ.

For example, if you want the first item in a collection, LINQ lets you call First() or FirstOrDefault() on any collection. The latter option makes handling empty collections easier. But someone decided to reinvent that wheel, and like so many reinvented wheels, it's worse.

public static LoggingRule FindFirst (this IEnumerable<LoggingRule> rules, Func<LoggingRule, bool> predicate) { foreach (LoggingRule rule in rules) { return rule; } return null; }

This function takes a list of logging rules and a function to filter the logging rules, starts a for loop to iterate over the list, and then simply returns the first element in the list, thus exiting the for loop. If the loop doesn't contain any elements, we return null.

From the signature, I'd expect this function to do filtering, but it clearly doesn't. It just returns the first element, period. And again, there's already a built-in function for that. I don't know why this is exists, but I especially dislike that it's so misleading.

There's only one positive to say about this: if you did want to reduce the size of the framework by 50%, it's easy to see where I'd start.

[Advertisement] BuildMaster allows you to create a self-service release management platform that allows different teams to manage their applications. Explore how!
Remy Porter

Chemical In Plastics Linked To 350,000 Heart Disease Deaths

1 month 1 week ago
An anonymous reader quotes a report from The Hill: Daily exposure to certain chemicals used to manufacture household plastics may be connected to more than 356,000 cardiovascular-related deaths in 2018 alone, a new analysis has found. These chemicals, called phthalates, are present in products around the world but have particular popularity in the Middle East, South Asia, East Asia and the Pacific -- regions that collectively bore about 75 percent of the global death total, according to the research, published on Tuesday in the Lancet eBioMedicine. Phthalates, often used in personal care products, children's toys and food packaging and processing materials, are known to disrupt hormone function and have been linked to birth defects, infertility, learning disabilities and neurological disorders. The NYU Langone Health team focused in the analysis on a kind of phthalate called di-2-ethylhexyl phthalate (DEHP), which is used to make items like food containers and medical equipment softer and more flexible. Scientists have already shown that exposure to DEHP can trigger an overactive immune response in the heart's arteries, which over time can be linked to increased risk of heart attack or stroke. In the new analysis, the researchers estimated that DEHP exposure played a role in 356,238 global deaths in 2018, or nearly 13.5 percent of heart disease mortality among men and women ages 55 through 64. [...] These findings are in line with the team's previous research, which in 2021 determined that phthalates were connected to more than 50,000 premature deaths each year among older Americans -- most of whom succumbed to heart conditions. But this latest analysis is likely the first global estimate of cardiovascular mortality resulting from exposure to these environmental contaminants [...]. In a separate report from the New York Times, author Nina Agrawal highlights some of the caveats with the data. First of all, the study relies heavily on statistical modeling and assumptions, drawing from prior research that may include biases and confounding factors like diet or socioeconomic status. It also uses U.S.-based risk estimates that may not generalize globally and focuses only on one type of phthalate (DEHP). Additionally, as Agrawal points out, this is an observational study, showing correlation rather than causation. As such, more direct, long-term research is needed to clarify the true health impact of phthalate exposure.

Read more of this story at Slashdot.

BeauHD