Article 572NE CodeSOD: A Shallow Perspective

CodeSOD: A Shallow Perspective

by
Remy Porter
from The Daily WTF on (#572NE)

There are times where someone writes code which does nothing. There are times where someone writes code which does something, but nothing useful. This is one of those times.

Ray H was going through some JS code, and found this useful" method.

mapRowData (data) { if (isNullOrUndefined(data)) return null; return data.map(x => x);}

Technically, this isn't a do nothing" method. It converts undefined values to null, and it returns a shallow copy of an array, assuming that you passed in an array.

The fact that it can return a null value or an array is one of those little nuisances that we accept, but probably should code around (without more context, it's probably fine if this returned an empty array on bad inputs, for example).

But Ray adds: Where this is used, it could just use the array data directly and get the same result." Yes, it's used in a handful of places, and in each of those places, there's no functional difference between the original array and the shallow copy.

buildmaster-icon.png [Advertisement] Utilize BuildMaster to release your software with confidence, at the pace your business demands. Download today! TheDailyWtf?d=yIl2AUoC8zAsOLuJKQc2gs
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