I recently realized how useless my custom .NET method, "Sonrai.ExtRS.ReferenceDataService.GetGoogleNews(string searchTerm)", really was.
I had referenced Sonrai.ExtRS via Nuget and began trying to use it to improve the display in scrolling news links, in another application I maintain, tickertapes.net.
It was useless! I mean a complete waste of code. It returned potentially useful data related to the searchTerm parameter- data from the GoogleNews API. But that is about it. It literally returned the entire XML response. 🤦♂️
I was parsing all this XML in the tickertapes.net app (why I do not know or care to remember), and so all the work necessary to wrangle the XML response to produce the needed news link collection was on the consumer of the Sonrai.ExtRS Nuget package- not good!
What the Nuget library should do, is all the work. What it should return, to be actually useful, is something structured like a collection of strings, each one representing a single news article, with the news headline being the text for the news article link.
And so I moved back to Sonrai.ExtRS to correct this unfortunate oversight.
public static async Task<List<string>> GetGoogleNewsWithLinks(string search)
{
HttpClient client = new HttpClient();
var content = await client.GetStringAsync(string.Format("https://news.google.com/rss/search?q={0}", search));
var parser = new HtmlParser();
var document = parser.ParseDocument(content);
var newsItems = document.All.Where(m => m.LocalName == "title").ToList();
var linkItems = document.All.Where(x => x.LocalName == "link").ToList();
var newsLinkItems = new List<string>();
for (int i = 0; i < newsItems.Count; i++)
{
newsLinkItems.Add("<a href='" + linkItems[i].NextSibling!.NodeValue + "' target='_blank'>" + newsItems[i].InnerHtml + "</a>");
}
return newsLinkItems;
}
And this provides the Nuget client with something it can actually use, "turnkey"/out-of-the-box.
The moral of the story is one that is as old as business and manufacturing: you must eat your own dog food. If there are problems or areas that need attention it is best that you find this information out before your product is released into the wild and a customer discovers the bug (or in this case, the uselessness), thus sullying your reputation as a business and software provider.
Test, test, test- always unit and/or integration test every user interaction and data movement for every story/path imaginable or support-able.
But there is nothing that replaces simply using your own product the way it is used by real users. And really using it for the purpose it was made. What you discover may help you shore up previously unknown problems and/or inspire you to make something useful that you would never otherwise think of, unless you were thinking from a user's perspective.
Reference: https://www.nuget.org/packages/Sonrai.ExtRS
PS: Imagine if James Newton-King never used NewtonSoft.Json for his own de/serializations? Or if Stack Overflow never used Dapper for the SO app/site? You need to use your creations right at the ground level (as a user/client) to verify that the functionality you designed in the abstract exactly matches how things will play out in concrete reality. Thoughts.. ðŸ’
No comments:
Post a Comment