Article 58WCM CodeSOD: A Long Time to Master Lambdas

CodeSOD: A Long Time to Master Lambdas

by
Remy Porter
from The Daily WTF on (#58WCM)

At an old job, I did a significant amount of VB.Net work. I didn't hate VB.Net. Sure, the syntax was clunky, but autocomplete mostly solved that, and it was more OR
less feature-matched to C# (and, as someone who needed to handle XML, the fact that VB.Net had XML literals was handy).

Every major feature in C# had a VB.Net equivalent, including lambdas. And hey, lambdas are great! What a wonderful way to express a filter condition.

Well, Eric O sends us this filter lambda. Originally sent to us as a single line, I'm adding line breaks for readability, because I care about this more than the original developer did.

Function(row, index) index <> 0 AND(row(0).ToString().Equals("DIV10106") ORrow(0).ToString().Equals("326570") ORrow(0).ToString().Equals("301100") ORrow(0).ToString().Equals("305622") ORrow(0).ToString().Equals("305623") ORrow(0).ToString().Equals("317017") ORrow(0).ToString().Equals("323487") ORrow(0).ToString().Equals("323488") ORrow(0).ToString().Equals("324044") ORrow(0).ToString().Equals("317016") ORrow(0).ToString().Equals("316875") ORrow(0).ToString().Equals("323976") ORrow(0).ToString().Equals("324813") ORrow(0).ToString().Equals("147000") ORrow(0).ToString().Equals("326984") ORrow(0).ToString().Equals("326634") ORrow(0).ToString().Equals("306039") ORrow(0).ToString().Equals("307021") ORrow(0).ToString().Equals("307050") ORrow(0).ToString().Equals("307603") ORrow(0).ToString().Equals("307604") ORrow(0).ToString().Equals("307632") ORrow(0).ToString().Equals("307704") ORrow(0).ToString().Equals("308184") ORrow(0).ToString().Equals("308531") ORrow(0).ToString().Equals("309930") ORrow(0).ToString().Equals("104253") ORrow(0).ToString().Equals("104532") ORrow(0).ToString().Equals("104794") ORrow(0).ToString().Equals("104943") ORrow(0).ToString().Equals("105123") ORrow(0).ToString().Equals("105755") ORrow(0).ToString().Equals("106075") ORrow(0).ToString().Equals("108062") ORrow(0).ToString().Equals("108417") ORrow(0).ToString().Equals("108616") ORrow(0).ToString().Equals("108625") ORrow(0).ToString().Equals("108689") ORrow(0).ToString().Equals("108851") ORrow(0).ToString().Equals("108997") ORrow(0).ToString().Equals("109358") ORrow(0).ToString().Equals("109551") ORrow(0).ToString().Equals("110081") ORrow(0).ToString().Equals("111501") ORrow(0).ToString().Equals("111987") ORrow(0).ToString().Equals("112136") ORrow(0).ToString().Equals("11229") ORrow(0).ToString().Equals("112261") ORrow(0).ToString().Equals("113127") ORrow(0).ToString().Equals("113266") ORrow(0).ToString().Equals("114981") ORrow(0).ToString().Equals("116527") ORrow(0).ToString().Equals("121139") ORrow(0).ToString().Equals("121469") ORrow(0).ToString().Equals("142449") ORrow(0).ToString().Equals("144034") ORrow(0).ToString().Equals("144693") ORrow(0).ToString().Equals("144900") ORrow(0).ToString().Equals("150089") ORrow(0).ToString().Equals("194340") ORrow(0).ToString().Equals("214950") ORrow(0).ToString().Equals("215321") ORrow(0).ToString().Equals("215908") ORrow(0).ToString().Equals("216531") ORrow(0).ToString().Equals("217151") ORrow(0).ToString().Equals("220710") ORrow(0).ToString().Equals("221265") ORrow(0).ToString().Equals("221387") ORrow(0).ToString().Equals("300011") ORrow(0).ToString().Equals("300013") ORrow(0).ToString().Equals("300020") ORrow(0).ToString().Equals("300022") ORrow(0).ToString().Equals("300024") ORrow(0).ToString().Equals("300026") ORrow(0).ToString().Equals("300027") ORrow(0).ToString().Equals("300050") ORrow(0).ToString().Equals("300059") ORrow(0).ToString().Equals("300060") ORrow(0).ToString().Equals("300059") ORrow(0).ToString().Equals("300125") ORrow(0).ToString().Equals("300139") ORrow(0).ToString().Equals("300275") ORrow(0).ToString().Equals("300330") ORrow(0).ToString().Equals("300342") ORrow(0).ToString().Equals("300349") ORrow(0).ToString().Equals("300355") ORrow(0).ToString().Equals("300363") ORrow(0).ToString().Equals("300413") ORrow(0).ToString().Equals("301359") ORrow(0).ToString().Equals("302131") ORrow(0).ToString().Equals("302595") ORrow(0).ToString().Equals("302621") ORrow(0).ToString().Equals("302649") ORrow(0).ToString().Equals("302909") ORrow(0).ToString().Equals("302955") ORrow(0).ToString().Equals("302986") ORrow(0).ToString().Equals("303096") ORrow(0).ToString().Equals("303249") ORrow(0).ToString().Equals("303753") ORrow(0).ToString().Equals("304010") ORrow(0).ToString().Equals("304016") ORrow(0).ToString().Equals("304047") ORrow(0).ToString().Equals("304566") ORrow(0).ToString().Equals("305347") ORrow(0).ToString().Equals("305486") ORrow(0).ToString().Equals("305487") ORrow(0).ToString().Equals("305489") ORrow(0).ToString().Equals("305526") ORrow(0).ToString().Equals("305568") ORrow(0).ToString().Equals("305769") ORrow(0).ToString().Equals("305773") ORrow(0).ToString().Equals("305824") ORrow(0).ToString().Equals("305998") ORrow(0).ToString().Equals("306039") ORrow(0).ToString().Equals("307021") ORrow(0).ToString().Equals("307050") ORrow(0).ToString().Equals("307603") ORrow(0).ToString().Equals("307604") ORrow(0).ToString().Equals("307632") ORrow(0).ToString().Equals("307704") ORrow(0).ToString().Equals("308184") ORrow(0).ToString().Equals("308531") ORrow(0).ToString().Equals("309930") ORrow(0).ToString().Equals("322228") ORrow(0).ToString().Equals("121081") ORrow(0).ToString().Equals("321879") ORrow(0).ToString().Equals("327391") ORrow(0).ToString().Equals("328933") ORrow(0).ToString().Equals("325038")) AND DateTime.ParseExact(row(2).ToString(), "dd.MM.yyyy", System.Globalization.CultureInfo.InvariantCulture).CompareTo(DateTime.Today.AddDays(-14)) <= 0

That is 5,090 characters of lambda right there, clearly copy/pasted with modifications on each line. The original developer, at no point, paused to think a moment about whether or not this was the way to achieve their goal?

If you're wondering about those numeric values, I'll let Eric explain:

The magic numbers are all customer object references, except the first one, which I have no idea what is.

proget-icon.png [Advertisement] ProGet's got you covered with security and access controls on your NuGet feeds. Learn more. TheDailyWtf?d=yIl2AUoC8zAYGCfqmZ19zk
External Content
Source RSS or Atom Feed
Feed Location http://syndication.thedailywtf.com/TheDailyWtf
Feed Title The Daily WTF
Feed Link http://thedailywtf.com/
Reply 0 comments