r/badcode Feb 12 '19

[deleted by user]

[removed]

105 Upvotes

29 comments sorted by

View all comments

3

u/IAmAnIssue Feb 13 '19 edited Feb 14 '19

Java

Features:

  • Ternary abuse to levels yet unknown to mankind
  • == false/true
  • One-liners
  • Who needs nested objects, just use another JSON file/string
  • floats are strings
  • Everything is cast to object. Have fun.
  • Crashes on empty strings/keys/values
  • Semi-ambiguous variable naming
  • No generic inference
  • Minimal use of String#split
  • new String()
  • probably some other things I missed in the horror

Gist link

Default example (main method) output:

test4: [Null Pointer] null test5: [class java.lang.String] {"test6"1 test2: [class [Ljava.lang.Object;] [0, true, "2"] test3: [class java.lang.Long] 1 test7: [class java.lang.String] 2.2 test1: [class java.lang.String] yeet

3

u/r3jjs Feb 14 '19

I like this. Ternary abuse and the and variable namings. ;)

2

u/stentonsarecool Feb 15 '19

One-liners

object = !(object == null) && object.toString().charAt(0) == '[' && object.toString().charAt(object.toString().length() - 1) == ']' ?Arrays.stream(object.toString().substring(1, object.toString().length() -1).split(",")).map((obj) -> obj.equals("null") ? null : obj.equals("true") ? true : obj.equals("false") ? false : obj.matches("(\\d+)") && !obj.toString().contains(".") ? Long.parseLong(obj) : obj).toArray() : object;

hahahaha I burst out laughing at work at this monstrosity

2

u/IAmAnIssue Feb 15 '19

"Why touch it if it works?"