Wednesday, April 24, 2019

CodeSOD: A Linking Approach

Web development has gone in a bizarre circle since the early 2000s. Whet ASP.NET launched, its “big sell” was Web Forms, which allowed developers to use a desktop model for handling interactive applications. The basic logic you used for building a desktop forms application would work for a web app, because at the time, everyone was a desktop developer.

Fast forward to today, where we bundle our applications up in web browsers and use web metaphors to build desktop applications, because everyone’s a web developer. This may be proof that developers can only ever learn a single way of doing things, and that two options is one too many.

Which brings us to some code Petr Tomanek recently inherited. The original developer, Josiah, started their career around the early 2000s. They were big advocates of the data row approach to data access. In code, they’d forget that they’d already run a query, and run it three more times just to be sure to get the data. Their approach to UI wasn’t even quite up to Web Forms standards, and was more, “mash together my personal library of snippets and Stack Overflow copy/paste”. The current incarnation of the application used the more modern ASP.NET MVC, but you wouldn’t know it to look at most of the code.

But Josiah would at least try to use the new features. For example, when they wanted the URL of a screen in the MVC application, they knew that the ActionLink method was how you created links in your view. There was also a Url.Action method which would construct just the URL. But that’s two different ways to do something, and that’s one too many. Josiah did this:

html.ActionLink(model.NextButtonText, model.RouteActionName, model.RouteControllerName, model.RouteValues, null).ToString().Split('"')[1];

The ActionLink method returns the full <a href=…>…</a>. Then we split on ", and grab the first element.

At least Josiah was consistent, and used this hammer everywhere they needed a URL.

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


To read the full article, please visit The Daily WTF

Fearless squirrel chases friendly cat

Well here’s something you don’t see everyday! Dare we say a friendship in the making?

The post Fearless squirrel chases friendly cat appeared first on Viral Viral Videos.



To read the full article, please visit Viral Viral Videos

Tuesday, April 23, 2019

Suffer Not The Virus To Live

Computer virus illustration

Not so long ago in 2015, Carl C. was asked to give a talk to an amateur radio club. The venue was a local church that rented out their meeting hall to various community groups, businesses, and even the odd academic session. The space boasted a multimedia setup with several video screens, making it a great place at which to present.

Carl prepared his talk, and a PowerPoint slide deck to go with. On the day of the presentation, he arrived at the meeting hall with plenty of time to spare. Alone in silence, he headed toward the front of the room and surveyed the technical setup. Thankfully, it was straightforward: there was a table set up in front of the projector screen, with a VGA connector resting directly on it. Carl unpacked his laptop, retrieved the HDMI-to-VGA adapter he'd brought along, and began plugging everything together.

"NOOO!"

Carl jumped, then glanced up wide-eyed like a deer in headlights. It wasn't a truck bearing down on him, but rather a flustered gentleman hugging a laptop to his chest.

"I'm the IT guru here," he introduced himself breathlessly, hurrying around the table to all but elbow Carl aside. "We don't allow outside computers to be connected to our system. That's how viruses spread! You'll have to run your presentation from our computer." He connected his own laptop to the AV system in lieu of Carl's.

"Uh ..." Carl blurted.

"Yes?" The guru fixed him with a withering stare.

I'm not joining your network, Carl thought. There's no such thing as VGA viruses! But the stare was so intense that the objections died before they left his throat.

"How, uh ... how do I get my presentation on there?" he asked instead, gesturing to the guru's laptop.

"Can you copy it to a USB stick?" the guru asked. "That's the best way."

Right. No one's ever gotten a virus from a random USB stick. Biting his lip to short-circuit a laugh, Carl dug through the side pockets on his laptop bag. "I think I've got one with me."

[Advertisement] Forget logs. Next time you're struggling to replicate error, crash and performance issues in your apps - Think Raygun! Installs in minutes. Learn more.


To read the full article, please visit The Daily WTF

Blind Pit Bull Sweetly Cuddles Kitty Best Friend

Who here believes that is impossible for cats and dogs to develop a friendship, please raise your hand. Well, we are here to prove you wrong, and we think that this video will change your mind for sure. This blind pit bull loves to cuddle with his best friend Griffin, and it’s the most adorable […]

The post Blind Pit Bull Sweetly Cuddles Kitty Best Friend appeared first on Viral Viral Videos.



To read the full article, please visit Viral Viral Videos

Monday, April 22, 2019

CodeSOD: Be True to Yourself

Ben M recently inherited some code from some Highly Paid Consultants. These consultants needed to be able to set some flags to control the behavior of the application, and for whatever reason, these flags needed to be strings. It probably wasn't a good reason, but there was some reason. The consultants wrote the module which set the flags, and guaranteed that the flags were only ever "true" or "false".

To parse those flags back into boolean values, they did it the true Highly Paid Consultant way: they used a generic "string to boolean" solution they copied from Stack Overflow instead of Boolean.Parse, the built-in C# method for turning "true" into a boolean value.

private bool ConvertBoolean(string value, bool defaultValue = false) { bool returnValue = defaultValue; if (value == null) { return returnValue; } if ("y".Equals(value, StringComparison.OrdinalIgnoreCase) || "yes".Equals(value, StringComparison.OrdinalIgnoreCase) || "true".Equals(value, StringComparison.OrdinalIgnoreCase) || "1".Equals(value, StringComparison.OrdinalIgnoreCase) || "on".Equals(value, StringComparison.OrdinalIgnoreCase)) { returnValue = true; } else if ("n".Equals(value, StringComparison.OrdinalIgnoreCase) || "no".Equals(value, StringComparison.OrdinalIgnoreCase) || "false".Equals(value, StringComparison.OrdinalIgnoreCase) || "0".Equals(value, StringComparison.OrdinalIgnoreCase) || "off".Equals(value, StringComparison.OrdinalIgnoreCase)) { returnValue = false; } return returnValue; }
 

Finally, this tells us the true value of FILE_NOT_FOUND, which is to say, whatever we passed in for our defaultValue, because that's what happens if this code doesn't understand how to parse the string.

[Advertisement] Utilize BuildMaster to release your software with confidence, at the pace your business demands. Download today!


To read the full article, please visit The Daily WTF