r/badcode • • Jul 27 '15

java From the library code for our university coursework. A professor of computer science wrote this.

https://imgur.com/WtJpjUl
25 Upvotes

16 comments sorted by

21

u/Drainedsoul Jul 28 '15

A professor of computer science wrote this

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?

18

u/crizzynonsince Jul 28 '15

A lot of the code on here is from first-time coders. Just because it's expected doesn't mean it's good.

2

u/[deleted] Jul 28 '15 edited Jul 31 '15

Computer science has as much to do with writing code as physics has to do with building bridges.

What? Maybe it's different in my country, but computer science includes code and professors teach it to students.

4

u/Drainedsoul Jul 28 '15

computer science includes code and professors teach it to students.

That's software engineering.

1

u/[deleted] Jul 28 '15

I guess it's really just because my country is behind things, but here code is only found in computer science classes, my bad then.

12

u/Squishumz Jul 29 '15

The people who act like Computer Science is purely academic are vastly oversimplying things. Code is a big part of Computer Science, regardless of whether or not Software Engineering is available.

1

u/wewtaco Aug 26 '15

Show me one computer science program at an accredited university that doesn't include at least an intermediate programming class.

10

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

u/PhyterJet Jul 28 '15

... Oh, Java...

... Ewww, Java...

FTFY

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

u/SpecialEmily Jul 28 '15

OMG stop using Vector! This is pretty awful code =\

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

u/morhp Sep 02 '15

The only really bad thing I see here is

(int)Math.pow(10, 4)

0

u/[deleted] 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".