Live data from Hacker News

Anyone who looks at this code instantly becomes insane

github.com

51–60 of 81 posts

Re: Anyone who looks at this code instantly becomes insane

#51
post #48
post #16

Earlier quoted context omitted.

This kind of thing in particular is really interesting: public static void print(String text) { System.out.println(text); } This person cares enough about brevity to make little wrapper functions like this, but at the same time everything is very procedural and monolithic. This gives a vague, weird sense of refined taste, despite some obvious problems with the artifact as a whole. I'm going to go out on a limb and gu…

I can understand that slightly. Back in college when I was doing a lot of Java if the IDE hadn't had a shortcut to auto complete System.out.println() I probably would have either made it as a macro or defined a function like that in a library (or in a block I would paste in every single project if we're being completely honest).

Does Java have macros now?

Re: Anyone who looks at this code instantly becomes insane

#52
I've seen tons of code, including code at companies famous for rigorous coding-interview processes to weed out weak programmers, that was far far worse than this. For all its bad properties, this code at least doesn't succumb to over-abstraction, obscure control flows or object-lifecycle rules, or desperate attempts to use every possible combination of language features in a (failed) attempt to look smart. Those things will kill readability and maintainability far more effectively than a bit of linearity or bad variable naming.

Re: Anyone who looks at this code instantly becomes insane

#53
post #5

https://github.com/raxod502/TerrariaClone/blob/master/src/Te... You may not like it, but this is peak programming. A level of perfection attainable only by undergoing the rite of writing a single if statement with 100+ conditions.

Honestly what would you do if you need to switch hundreds of distinct cases? Hundreds of classes implementing an interface?

The way I'm reading this code is that the cases aren't that distinct. Look at lines 4367 to 4390 and you see 23 distinct cases that could be handled by a range and Mod 3.

Re: Anyone who looks at this code instantly becomes insane

#54
post #49
post #5

https://github.com/raxod502/TerrariaClone/blob/master/src/Te... You may not like it, but this is peak programming. A level of perfection attainable only by undergoing the rite of writing a single if statement with 100+ conditions.

I'm a second-year CS student that is still learning in this realm. Is there a general way that most developers would rewrite lines 5261-5284? My assumption is I would look to find some rules I can apply to simplify the code but I'm also aware a CS course is a bit of a bubble and what I've learnt so far might not be the way things are handled in industry. For example, line 5284 has a 8 inequality operators checking ev…

> Why is there no comments? Is this common?

It's frighteningly common, and more likely if only 1 developer is working on something. CS students comment far too much, but I would expect a monstrous chain like this to have at least -some- documentation.

Re: Anyone who looks at this code instantly becomes insane

#55
post #51
post #48

Earlier quoted context omitted.

I can understand that slightly. Back in college when I was doing a lot of Java if the IDE hadn't had a shortcut to auto complete System.out.println() I probably would have either made it as a macro or defined a function like that in a library (or in a block I would paste in every single project if we're being completely honest).

Does Java have macros now?

No a macro in my editor. Most text editors will have some capability to do user defined text replacements.

Re: Anyone who looks at this code instantly becomes insane

#57
post #16

Earlier quoted context omitted.

This kind of thing in particular is really interesting: public static void print(String text) { System.out.println(text); } This person cares enough about brevity to make little wrapper functions like this, but at the same time everything is very procedural and monolithic. This gives a vague, weird sense of refined taste, despite some obvious problems with the artifact as a whole. I'm going to go out on a limb and gu…

I'd bet they made that function so they had a single place to intervene on text being written, not necessarily for the brevity/aesthetics.

Given the extreme lack of abstraction elsewhere, I highly doubt it.

Re: Anyone who looks at this code instantly becomes insane

#59

About 12 years ago I was working at a company in which a developer had recently left, and left behind some code that had a bug in it that needed fixing, the code was processing some XML and I knew a lot about XML so I was called over to look at this code. The code was actually very simple, it consisted of for loops over a bunch of element nodes in which child nodes had to be compared with child nodes in other element…

Reminded of a time I took the code of our Data Scientists (2 physicists that "coded". They decided to make their own ORM in Ruby (called "Mondongo") instead of using one available. No wonder, the code was a real mess...

For example, they needed to get a numeric value from a dropdown box that got several text options. The way they did it was:

fieldVal = textField.gsub('text string 1',0).gsub('another string 2',1).gsub('anotherstring3',3).....

and so on with all the options. And in theory they looked for a 0, 1, 2... etc.

Another WTF was that, when we told them we would be upgrading from Ruby 1.8 to 2.0, they told us that they were not sure, because 2.0 did not work that well... As it happens, at some point in the code they were using the .object_id property of a boolean value and testing it == 2 or 0. Well... ruby 2.0 made true.object_id == 20 , so things did not work as expected.

Post reply on HN