Too Spicy For My Hat

by in Error'd on

My plate has been full this week, but not as full as Walter's!

"Maybe hold the cheese?" suggests Walter T. regarding a pepper and steak grinder. "Seen at Reading (MA) House of Pizza on Jul 24 2024." If you decide to search around to try to understand the different names for this kind of sandwich, you will undoubtedly discover someone trying to claim that really, the hoagie is a different sandwich from a submarine, which is different from a grinder and so on. They are wrong, and this is how we know: if they truly were different kinds of sandwiches, then somewhere on this planet would be a shop selling examples of each of the different variants for your dining pleasure. There is not*. Q.E.D any consistent regional variation in bread choice, or dressing, or fillings, is simply that: a regional variation of the same thing, not an entirely different category.
*Until someone can show me the existence of such a sandwich shop, I assert that it does not exist, thus my proof holds.


Reflections on Privacy

by in CodeSOD on

Jaco's team had a problems with making an embedded web server shut down properly. Something about the shutdown process was deadlocking, so one of their "ninja Yoda coders" rockstarred their way to a solution.

private void stopServer() {
	try {
		if (webServer != null) {
			logger.debug("Shutdown webserver");
			// This goes into a dead lock, therefore I've replaced it with
			// some voodoo stuff.
			logger.debug("Get listener field from web server.");
			Field listenerField = WebServer.class.getDeclaredField("listener");
			listenerField.setAccessible(true);
			Thread listener = (Thread) listenerField.get(webServer);
			listenerField.set(webServer, null);
			logger.debug("Interrupt the listener thread.");
			listener.interrupt();
			webServer = null;
			logger.debug("Shutdown webserver complete");
		} else {
			logger.debug("No webserver to shutdown");
		}
	} catch (Exception e) {
		logger.error(LoggerCodes.RPC_SERVER_SHUTDOWN_FAILURE, e, LoggerUtility.parameters("class",
			e.getClass().getSimpleName(), "message", e.getMessage()));
	}
}

How to Validate an IP Address

by in CodeSOD on

Andy has some concerns about future proofing. In this case, he sends us some C# code that's supposed to validate an IP address.

string[] address = StringTools.splitStr(IP, '.');
if (address.length < 4) {
        throw new Exception("Bad IP format : " + IP);           }

NPath Complexity

by in Feature Articles on

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.


Serial Properties

by in CodeSOD on

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:

public string ViewNodeFilter
{
        protected get
        {
                if (viewNodeFilter.IsNotValid())
                {
                        return "null";
                }
                return new JavaScriptSerializer().Serialize(viewNodeFilter);
        }
        set { viewNodeFilter = value; }
}

Pennies From Heaven

by in Error'd on

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.


False True is True False

by in CodeSOD on

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:


Sanitary Paths

by in CodeSOD on

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…


Archives