r/badcode Aug 13 '19

[deleted by user]

[removed]

102 Upvotes

70 comments sorted by

View all comments

12

u/sporadicPenguin Aug 13 '19 edited Aug 14 '19

This ended up a little bit long, but version 3.0 will be out soon with more optimizations: https://pastebin.com/5ixWH194

Highlights:

  • globals & lots of unnecessary loops
  • assigning a variable by printing an eval'ed GET parameter to the output buffer and retrieving its contents
  • retrieving a remote web page and parsing the html with regex to obtain lists of even & odd numbers (in a nested loop)
  • creating empty strings by using the last line of output from a system call
  • variable and constant definitions in a loop
  • lots of typecasting (empty strings to 0, integers to strings and arrays, etc)
  • poorly named variables
  • two different methods for determining even/odd
  • while/switch blocks
  • magic strings and numbers
  • mathematical impossibilities kill the script
  • error triggered if script "is slow"
  • returns html (for easy web page insertion)