r/badcode • • Sep 20 '19

php So what's being activated?

Post image
702 Upvotes

26 comments sorted by

203

u/somehowyellow Sep 20 '19

Looks like a placeholder for future functionality

80

u/[deleted] Sep 20 '19

It might even be a class that implements an interface that requires this function, like a free tier or something. Probably not, and still not the best implementation, but context never goes astray.

The worst thing about it is that this file has more than 1600 lines of code

27

u/MeatyLabia Sep 20 '19

Or a class used for testing and in deployment another class is used.

9

u/Tynach Sep 20 '19

I find it weird that they document the $license_key parameter, but not the $ig parameter. That might be explained if it is implementing an interface, and the interface changed (thus the parameter being added) but they didn't go through and update all the documentation comments.

5

u/PersianMG Sep 21 '19

The function stub was probably updated and the original documentation was autogenerated by an IDE based on the original stub.

3

u/jimmpony Sep 21 '19

I think it's worse that it's returning some magic string that isn't even put in a constant

2

u/Exnixon Sep 20 '19

It's clearly not, it's not indented.

8

u/Exnixon Sep 20 '19

It's pretty dumb that the return value is a string, though.

11

u/TheSpiffySpaceman Sep 20 '19

I mean it's not like there's a two-state data type out there.

15

u/Cutlesnap Sep 20 '19

I mean, couldn't you say that about all production code?

1

u/[deleted] Oct 05 '19

exactly, doesn't look like bad code to me?

46

u/javarouleur Sep 20 '19

Meh... actual validation is a different user story... this is just mid-sprint code... right? Right?

But comment inaccurate and missing `@param`. PR declined.

2

u/filyr Sep 20 '19

comment inaccurate

who could have thought

11

u/HattyJetty Sep 20 '19

WinRAR way

5

u/whizvox int getRand() { return 4; } Sep 20 '19

looks like someone forgot a TODO

5

u/andiconda Sep 20 '19

Remind me of some x509 cert authorization code I wrote for a client. It just returned true no matter what. It was actually low risk and the call for encryption was political.

But they asked "hey when you get <other vendor>'s certificate, what do you do?"

And I say, "I authorize it"

Technically correct, the best kind of correct.

1

u/[deleted] Sep 20 '19

This could be a mock used for unit testing

1

u/waiting4op2deliver Sep 20 '19

This is actually just used to trigger the maintainer.

1

u/Lachance Sep 20 '19

the validation might be done before he even gets into this function

1

u/AleAndrade Sep 20 '19

I mean, I can not be implemented, but can't be changed to an exception for Reasons

1

u/jesse_7777 Sep 20 '19

i love the if statement in the middle

-1

u/Gydo194 Sep 20 '19

Windows

0

u/[deleted] Sep 20 '19

[deleted]

1

u/c3534l Sep 21 '19

7

u/Teknikal_Domain Sep 21 '19 edited Sep 21 '19

That one has a reason though.

For example, playing back demo files or keeping things consistent client/server.

You have randomness within the game, but each instance is the same, in effect it's a RNG with a preset, constant seed.

From the wiki page:

Each call to the function P_Random advances the index by one (wrapping around to zero after 255) and returns the table entry at that index.

There is another function, M_Random, that is identical except that it uses its own independent index. P_Random is used in play simulation situations, such as calculating hit damage. M_Random is used otherwise.

The reason for the existence of two individual indexes is to maintain multiplayer synchronisation: for example, M_Random is used to apply a random pitch variation to sounds. As two players may not hear the same sound effect (they may be in different parts of the level), using a single index would cause the game to become desynchronised. To use a model-view-controller analogy, P_Random is used for random number generation at the 'model', while M_Random is used for random number generation at the 'view'.

The function M_ClearRandom resets both functions' indexes to zero. It is called during initialization of each new level so that demos will be the same each time they are played, and so that multiplayer games are synchronised.

Although the table is 256 bytes long, it does not contain all of the numbers between 0 and 255 inclusive. For example, 0 appears twice and 1 does not appear at all; 145 appears five times, more than any other number. Thus the values are not uniformly distributed, but in fact they are nearly so. The mean value is 128.852, whereas it would be 127.500 if all values were equally likely. All of this suggests that the table was generated using a conventional pseudorandom number generator of reasonable quality.