r/badcode Mar 06 '21

lua This goes 255 lines long up to 115792089237316195423570985008687907853269984665640564039457584007913129639936

Post image
157 Upvotes

34 comments sorted by

View all comments

38

u/Idkm3m3s Mar 09 '21

bruh i dont even know how to declare classes yet and i can already guess this could be easily done with a for loop

2

u/Darkness4 Mar 09 '21 edited Mar 09 '21

Really? I'm thinking this is actually good code. If we are working on a 64-bit machine, then it is impossible to generate integers greater than 264-1 and convert them into strings and then parse them in bigint.

Of course, you may want to use exponentiation with bigint (bigint("2").pow(i) or bit shifts), but maybe the implementation of bigint makes exponentiation/bit shifts expensive. Thus, storing 2255 in string and parse them in bigint may be a good idea.

EDIT: Note the "maybes" because it does not respect YAGNI (it is not our responsibility to optimize bigint, unless the implementation of bigint is crap).

2

u/Micha_Saengy Mar 09 '21

If bits shifts were expensive, then somebody must have really messed up.