Matt inherited some C# code that reads from a JSON config file.

public ServerJsonLoader(string configFile)
{
	using (StreamReader reader = File.OpenText(configFile))
	{
		JObject config = ... 

		if (config.GetValue("inputs") != null)
		{
			this.mixedConfig = config;

			
			var inputs = ... 

			
			if (config.GetValue("outputs") != null)
			{
				var outputs = ... 
			}                
		}
		else
		{                 
			if(config.GetValue("inputs") != null)
				this.serverConfig = config;

			if (config.GetValue("outputs") != null)
				this.clientConfig = config; 
			
		}                    
	}
}

We open the file as a stream, and then hand it off to a JObject, which handles the parsing for us. Then, if it has a value "inputs", we store the config as mixedConfig, and handle the inputs. Then, if it also has "outputs", we also process the outputs.

If we don’t have an "inputs", we go down the else path, where we check: if we have "inputs", we store the config in serverConfig, and if we have "outputs", we store the config in clientConfig.

It pains me to say that this convoluted logic isn’t useless. It may not even be wrong. In the case where there are no "inputs", but there are "outputs", we’ll store the config in clientConfig.

What we have here is a terrible way to write a simple concept: if we have only outputs, we must be a client. I suspect that they once wanted it to also be true that if you had only inputs, you were a server. And if you had both, you were “mixed”. Then, something changed about their rules or their config, and the server-only configuration became a little vestigial branch off this chain of ifs, never to be executed again.

[Advertisement] ProGet’s got you covered with security and access controls on your NuGet feeds. Learn more.

Remy Porter

Source link

You May Also Like

Shoplifter? – People Of Walmart

The post Shoplifter? appeared first on People Of Walmart. alexandtim Source link

Child’s Diary Completely Devoid Of Any Useful Dirt On Other Parent

HUNTINGTON BEACH, CA—Sighing as she shoved the journal back under their daughter’s…

New Gen MoHawk! – People Of Walmart

My new hair style effective immediately. The post New Gen MoHawk! appeared…

r/funny – Saw this covid shield at work today. Kalitta Air has class and a sense of humor.

A message to all users: Please be aware that spreading misinformation regarding…