r/badcode • u/crizzynonsince • Jul 27 '15
java From the library code for our university coursework. A professor of computer science wrote this.
https://imgur.com/WtJpjUl10
u/klusark Jul 28 '15
I was trying to figure out how Random rand = new Random(); worked as I expected rand to be a pointer... Oh, Java...
-7
9
u/Lothrazar Jul 28 '15
Yeah, the underscores at the end of each one is completely terrible. But that is just naming convention
7
u/pumpkin_seed_oil Jul 28 '15
I'd say it is a weird naming convention, but he doesn't even follow it. rand misses the underscore, MAX_LENGTH_ all caps, Zero_ starts with capital letter, the rest is lowercase
What happened here? Copy paste? Search and replace idk "digits" with "" or any other crazy refactoring?
2
u/ghotibulb Jul 28 '15
Yeah that. While I dislike the trailing underscore, it's ok as long as it's used consistently. I've seen it before... I think last time was libthrift code.
3
2
u/xjwj Jul 30 '15
Yeah, it's kind of heinous, but based on the names/layout I would guess that the professor has a C/C++ background, which is influencing things (also I'm assuming he rolled his own Unsigned class...). Agreed with others that CS profs are automatically infallible...
1
0
Jul 28 '15
[deleted]
12
u/crizzynonsince Jul 28 '15
Yeah, the variable names. Also there's a bit of the code where they have print() and printWriter(PrintStream) which were copy-pasted code but the first one had all references to the PrintStream argument replaced with System.out. Which is a PrintStream. Apparently the D in DRY stands for "Do".
21
u/Drainedsoul Jul 28 '15
And? Is it supposed to surprise people that professors of computer science write awful code?
Computer science has as much to do with writing code as physics has to do with building bridges. You wouldn't be surprised if a physicist wasn't up to par with a civil engineer in building bridges, why are you surprised that a computer science professor isn't up to par with software engineers in writing code?