CodeSOD: For Each Parallel

This post was originally published on this site

The Daily WTF

Parallel programming is hard. For all the advancements and tweaks we’ve made to our abstractions, for all the extra cores we’ve shoved into every CPU, deep down, software still carries the bias of the old uni-tasking model.

Aleksei P works on a software package that is heavily parallel. As such, when interviewing, he talks to candidates about their experience with .NET’s Task objects and the async/await keywords.

One candidate practically exploded with enthusiasm when asked. “I’ve just finshed a pretty large text processing project that reads a text file in parallel!” They whipped out a laptop, pulled up the code, and proudly showed it to Aleksei (and gave Aleksei a link to their repo for bonus points).

public async Task<IDictionary<string, int>> ParseTextAsync(string filePath, ParamSortDic dic) { if (string.IsNullOrEmpty(filePath)) { throw new ArgumentNullException(nameof(filePath)); } if (Path.GetExtension(filePath)!=”.txt”) { throw new ArgumentException(“Invalid filetype”); } Dictionary<ParamSortDic, Func<IDictionary<string, int>, IOrderedEnumerable<KeyValuePair<string, int>>>> sorting = new Dictionary<ParamSortDic,

To read the full article click on the 'post' link at the top.