News for hackers. Stuff that matters.
Re:CryEngine out on GitHub by kidmenot on Tuesday May 24, 2016 @10:11AM (#11761617)
14 levels of indentation across 811 lines. Wow indeed.

I refactor as soon as my code gets past 3 levels, I don't know how one is supposed to readily understand this block of code.

The lack of comments isn't what troubles me. Comments get old and, when they do, they get completely misleading and downright dangerous. As soon as you feel the need to add a comment, it's often because that particular chunk of code should be extracted into its own function/method/whatever and given an intelligent name. Comments should be reserved for really important stuff, like when the code does something totally non-obvious.

Re:CryEngine out on GitHub by webkike on Tuesday May 24, 2016 @11:59AM (#11762606)
This code is not actually that _complex_, it is just _complicated_, and there are probably several people within the company that understand it completely. If you actually go through the code, I bet you will understand the majority of it. Step functions are annoying and complicated and need to be _fast_, less than half a frame long. And you need to do a lot in them, and all of those things are tightly coupled.
Re:CryEngine out on GitHub by damptowel on Tuesday May 24, 2016 @06:41PM (#11766144)
Re:CryEngine out on GitHub by zubspace on Wednesday May 25, 2016 @05:44AM (#11768654)
Wow.

Question regarding index access: There are tons of for loops with player[k] occurrences and similar. Personally I would create a local variable and prevent further index-retrievals.

Is this worthwhile or would a compiler optimize the array-index access away? Or maybe subsequent uses of the same index are cached by the cpu? Does someone know?

Re:CryEngine out on GitHub by tehrei on Wednesday May 25, 2016 @09:54AM (#11769747)
That's a micro-optimisation that's absolutely worthless. Even if you do pay the cost of indexing an array every single time, that's just a single instruction to fetch the address. The compiler is absolutely capable of caching the indexing for you, either in a register or on the stack, if it deems it worthwhile.

One reason you might want to use a separate variable would be to prevent indexing mistakes, like using i instead of k by mistake in a context where i is a nested loop's counter. But apart from this and other "to make it easier on the human" reasons, there's no point in caching that in a variable. Now, if you were writing Python on the other hand...

Re:CryEngine out on GitHub by ensiferum on Wednesday May 25, 2016 @06:38AM (#11768826)
Holy batman. Now this is officially the worst piece of code I've ever seen in my 15 years of programming. This has to be generated... right?? I can't believe any human wrote this.

Grabs the eye bleach

Re:CryEngine out on GitHub by webkike on Wednesday May 25, 2016 @11:37AM (#11770513)
It was written by a highschooler who made a 3D video game with decent physics and you're... criticizing him? Man, I'd like to see what YOU wrote in highschool.
Re:CryEngine out on GitHub by PeCaN on Tuesday May 24, 2016 @08:40PM (#11766800)
On top of that, in a step function you really want to see what's being modified (that's kinda the point...). I suspect that monstrosity is easier to maintain than having state updates scattered around and having to jump to definitions and back to step() to understand the thing.
Re:CryEngine out on GitHub by saiya-jin on Tuesday May 24, 2016 @10:41AM (#11761922)
i think they don't use static code analysis on this part :)

generally agree on commenting, but it's also about discipline - method-level commands are rarely updated, but if there is some particular algorithm within method, I don't see a reason to describe it beforehand on a line or two.

General rule - if method is longer than my screen, it's time to refactor. very rarely this isn't a good idea.

Re:CryEngine out on GitHub by shermanyo on Thursday May 26, 2016 @10:06PM (#11783398)
maybe the author got a 4k monitor and set it up in portrait? :P
Re:CryEngine out on GitHub by clux on Tuesday May 24, 2016 @02:22PM (#11764183)
There are also 3 gotos in that function.
Re:CryEngine out on GitHub by khedoros on Tuesday May 24, 2016 @04:37PM (#11765257)
Goto should be used in the (admittedly rare) cases where it makes program flow cleaner. The original complaint was that people weren't moving to structured programming constructs as they became available. That really isn't a problem any more.