r/learnprogramming • u/tempyreddity • Dec 03 '15
PSA: Don't use the Java standard library
Hey guys,
So I was working through an advent of code challenge, and it looks like apparently there are issues that can arise from the java standard library, in particular hashset. See here: https://www.reddit.com/r/adventofcode/comments/3v8roh/day_3_solutions/cxlfuvp?context=3
I'm a newbie so I thought others would want to know about this before trying to figure out why their programs aren't working. Write your own classes!
0
Upvotes
View all comments
Show parent comment
5
u/desrtfx Dec 03 '15
The funniest part is that neither 2000 nor over 8000 are the correct answers.
Accept it: your code is wrong.
Plenty people have implemented the program with HashSet and had no issues whatsoever.
It's neither the library, nor the CPU that is wrong.
Java runs in a Virtual machine that is specifically compiled for each CPU architecture/operating system, so the CPU factor is out of the game.
The Java standard libraries have been around for so long and are used by millions of people in enterprises for mission critical systems. An error in the libraries would immediately be noticed.
Pro-Tip: Always assume that the problem is a PEBKAC (Problem Exists Between Keyboard And Chair) when working with well-established systems. The chances that there is an unnoticed bug that will exactly affect you in such a system are by far less than winning the lottery 5 times in a row.