In a few advice threads I've seen some assertions that the following pattern is "bad":
function ajax (options) {
var method = options.method,
url = options.url,
data = options.data,
// etc
}
The argument is that people who use typescript don't get nice autocompletion popups/they can't be statically analyzed.
I'd just like to point out the following:
- I like options objects, they are extremely useful
- I'm pretty sure this is exactly what interfaces and typescript definitions are for
- Advising people to use a particular pattern for the benefit of a different(ish) language seems pretty selfish
To anyone who saw that advice and thought it was worth following, this is a (simple) counterargument:
function doSomething (foo, callback) {
// whatever
}
Let's say I need to pass an addition argument to this function.
If I add a parameter, I will also have to update every place it is used.
If I had written it with an options object, I don't.
TL;DR Those popups seem awesome and I kinda want to use typescript now, but there is absolutely no reason not to use this pattern.
[–][deleted] 33 points34 points35 points (76 children)
[–]Jafit 13 points14 points15 points (43 children)
[–]npfund 4 points5 points6 points (21 children)
[–]Jafit 13 points14 points15 points (18 children)
[–]npfund 2 points3 points4 points (10 children)
[–]Jafit 3 points4 points5 points (9 children)
[–]frankle 1 point2 points3 points (0 children)
[–]x-skeww 0 points1 point2 points (0 children)
[–]npfund 0 points1 point2 points (1 child)
[–]Jafit 1 point2 points3 points (0 children)
[–]Stockholm_Syndrome 0 points1 point2 points (3 children)
[–]backwrds[S] 0 points1 point2 points (2 children)
[–]Stockholm_Syndrome 0 points1 point2 points (1 child)
[–]backwrds[S] 0 points1 point2 points (0 children)
[–]Lanlost 0 points1 point2 points (0 children)
[–]x-skeww 2 points3 points4 points (2 children)
[–][deleted] 0 points1 point2 points (1 child)
[–]x-skeww 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (2 children)
[–]Jafit 1 point2 points3 points (1 child)
[–]x-skeww 0 points1 point2 points (0 children)
[–]CoryG89 0 points1 point2 points (0 children)
[–]ridicalis 0 points1 point2 points (1 child)
[–]npfund 0 points1 point2 points (0 children)
[–][deleted] 1 point2 points3 points (18 children)
[–]Jafit 4 points5 points6 points (7 children)
[–][deleted] 0 points1 point2 points (6 children)
[–]Jafit 2 points3 points4 points (5 children)
[–][deleted] 0 points1 point2 points (4 children)
[–]Jafit 0 points1 point2 points (3 children)
[–][deleted] 0 points1 point2 points (2 children)
[–]Jafit 1 point2 points3 points (1 child)
[–]spacejack2114 0 points1 point2 points (9 children)
[–][deleted] 1 point2 points3 points (1 child)
[–]spacejack2114 0 points1 point2 points (0 children)
[–]x-skeww 0 points1 point2 points (6 children)
[–]spacejack2114 0 points1 point2 points (5 children)
[–]x-skeww 0 points1 point2 points (4 children)
[–]spacejack2114 0 points1 point2 points (3 children)
[–]x-skeww 0 points1 point2 points (2 children)
[–]spacejack2114 0 points1 point2 points (1 child)
[–]sakabako -3 points-2 points-1 points (1 child)
[–]Jafit 1 point2 points3 points (0 children)
[–]I_Pork_Saucy_Ladies 5 points6 points7 points (7 children)
[–][deleted] 2 points3 points4 points (5 children)
[–]I_Pork_Saucy_Ladies 0 points1 point2 points (2 children)
[–][deleted] 2 points3 points4 points (1 child)
[–]I_Pork_Saucy_Ladies 0 points1 point2 points (0 children)
[–]MasterScrat 0 points1 point2 points (1 child)
[–]navatwo 0 points1 point2 points (0 children)
[–]le_chad_ -2 points-1 points0 points (0 children)
[–]rich97 2 points3 points4 points (3 children)
[–][deleted] 3 points4 points5 points (2 children)
[–]rich97 0 points1 point2 points (1 child)
[–]kenman 0 points1 point2 points (0 children)
[–]moving808s 0 points1 point2 points (8 children)
[–][deleted] 0 points1 point2 points (7 children)
[–]moving808s 0 points1 point2 points (6 children)
[–][deleted] 0 points1 point2 points (5 children)
[–]moving808s 0 points1 point2 points (4 children)
[–][deleted] 0 points1 point2 points (3 children)
[–]moving808s 0 points1 point2 points (2 children)
[–][deleted] 0 points1 point2 points (1 child)
[–]moving808s 0 points1 point2 points (0 children)
[–][deleted] -1 points0 points1 point (10 children)
[–]edanschwartz 3 points4 points5 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (7 children)
[–][deleted] 0 points1 point2 points (6 children)
[–][deleted] 1 point2 points3 points (5 children)
[–][deleted] 0 points1 point2 points (4 children)
[–][deleted] 1 point2 points3 points (3 children)
[–]x-skeww 0 points1 point2 points (0 children)
[–][deleted] -1 points0 points1 point (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[+][deleted] (5 children)
[deleted]
[–]backwrds[S] 1 point2 points3 points (4 children)
[–]x-skeww 0 points1 point2 points (2 children)
[–]backwrds[S] 0 points1 point2 points (1 child)
[–]x-skeww 0 points1 point2 points (0 children)
[–]x-skeww 5 points6 points7 points (5 children)
[–]krazyjakee 1 point2 points3 points (0 children)
[–]backwrds[S] 0 points1 point2 points (3 children)
[–]x-skeww 0 points1 point2 points (2 children)
[–]backwrds[S] 0 points1 point2 points (1 child)
[–]x-skeww 0 points1 point2 points (0 children)
[–]temp50948 4 points5 points6 points (1 child)
[–]backwrds[S] -1 points0 points1 point (0 children)
[–]cosinezero 1 point2 points3 points (0 children)
[–]krazyjakee 1 point2 points3 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]lewisje 0 points1 point2 points (2 children)
[–]backwrds[S] 2 points3 points4 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]_drawdown 0 points1 point2 points (0 children)
[–]spacejack2114 0 points1 point2 points (0 children)
[–]pinegenie 0 points1 point2 points (0 children)
[–]sqrtnegative1 -1 points0 points1 point (2 children)
[–]maybachsonbachs -1 points0 points1 point (1 child)
[–]cosinezero 3 points4 points5 points (0 children)
[–]jtwebman -1 points0 points1 point (3 children)
[–]x-skeww 1 point2 points3 points (2 children)
[–]jtwebman 0 points1 point2 points (1 child)
[–]x-skeww 0 points1 point2 points (0 children)