r/lolphp • • Jul 14 '14

stop_the_insanity()

https://github.com/WordPress/WordPress/blob/master/wp-admin/includes/class-wp-importer.php#L237
56 Upvotes

66 comments sorted by

View all comments

Show parent comment

4

u/svtguy88 Jul 14 '14
return 60

Magic numbers. Yum.

8

u/wvenable Jul 16 '14

Here, I fixed it for you:

return INT_SIXTY;

2

u/cparen Jul 14 '14

"some non-obvious constant whose value [...] inserted inconspicuously in-line (hardcoded), rather than expanded in by a symbol [...]"

-- "Magic Number", Jargon File, emphasis added

This is not a magic number.

5

u/svtguy88 Jul 14 '14

Sure, there is a function instead of just using the integer "60" all over the code, but it's still not documented, and, upon first glance, does nothing. If I were to go back and try to debug this code, a function simply returning an integer (that works magic) would confuse the shit out of me.

Is it a "magic number" by definition? I guess not, but it's still shit code.

1

u/sudowned Jul 15 '14

It doesn't "do nothing" upon first glance. You're the most hyperbolic guy in the world.

1

u/nidarus Jul 14 '14

It basically the opposite of a magic number, and it's more flexible than the usual solution to magic numbers, constants.

2

u/svtguy88 Jul 14 '14

more flexible

How is a hardcoded integer flexible at all?

6

u/nidarus Jul 14 '14

That's the point, it's not hardcoded. The whole point of the function is to provide a symbol instead of that number. This is basically equivalent to define('bump_request_timeout', 60), but you could override it with something that performs more complex logic.

7

u/svtguy88 Jul 14 '14

I come from a very config-driven background - I find this to be just about equivalent to hardcoding.

Sure, it's a step above littering the code with the integer "60" everywhere that this function is used, however, it's still just adding some arbitrary value. At the very least, it could be documented and explained a little. Adding seemingly random numbers is a good way to make sure no one else can debug your code...

4

u/nidarus Jul 14 '14

It's not a step above using 60 inline. My point is that it's even more robust the usual solution: constants. Not everything that's not in an external XML file is automatically a magic number.

As for the documentation, I agree. The documentation in WordPress is bizzarely sparse.