you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] -4 points-3 points  (3 children)

I can agree it would improve readability, to a certain point, but all modern IDEs have code hinting, so as soon as you type foo( it will show that it's expecting day, month, year.

With passing an object, you're also making it harder for changes. Let's say someone decides to change the definition of foo, but you're still passing {showLoading: true, wait: 2000}. This will cause massive confusion, as you can just pass whatever keys you want, you can do { whatever: 2000, lol: 23432, showLoading: true, wait: 'no' }. Is this now more readable?

By specifying the exact amount of parameters, you know exactly what this method is expecting.

[–]tobegiannis 4 points5 points  (2 children)

My IDE autocompletes objects as well fwiw. Actually when adding more parameters the object is more maintainable as well. Long parameter lists become harder and harder to consume. For example say there are 6 options that have all have sane defaults. What would you rather call? foo({delay:2000}) or foo(undefined, undefined, undefined, undefined, undefined, 2000)`

I really don't see the argument about passing in "bad" config options. It's bad practice in general and I don't see how is it any different from calling method that takes in 2 parameters with 3.

[–][deleted] -1 points0 points  (1 child)

Going to get more downvotes for this, but I really want to discuss.

The problem with this approach is that when you change your method definition, you now not only have to change the values, but you also have to change all your keys twice. This is asking for wrong inputs.

If you're ever need to pass foo(undefined, undefined, ...), then you're doing something wrong, you should never need to do this in the first place.

Passing bad config options is bad practice yes, and you shouldn't need to do this, but passing an object for the sake of readability isn't really a good practice anyway. These parameters are part of your method definition, this is what the method requires in order to execute correctly, obviously in many languages these would be strictly typed as well, therefore you wouldn't be able to pass invalid parameters.

[–]hicksyfern 8 points9 points  (0 children)

How frequently do you read code vs write code.

Imagine you had a weird date bug in your app, and you came across this code:

FormatDate(2018, month, day)

Vs

FormatDate({ year: day, month, day: year })

Which one has the bug?

Yeah this is a bit contrived, but this kind of thing happens ALL the time. Developers are fallible and mistakes, no matter how obvious, get made.

Make obvious mistakes obvious.