5 ms·
Carmack has some interesting comments on this sort of coding: http://number-none.com/blow/john_carmack_on_inlined_code.html http://number-none.com/blow/john_car
by dagw 10y ago
Carmack has some interesting comments on this sort of coding:
http://number-none.com/blow/john_carmack_on_inlined_code.html http://number-none.com/blow/john_carmack_on_inlined_code.htm...
- partisan 10y ago> When it gets to be too much to take, figure out how to factor blocks out into pure functions (and don.t let them slide back into impurity!). This is a great piece of advice and one that has worked for me in the past when refactoring code like the one referenced.
- jdcarter 10y ago> "However, if you are going to make a lot of state changes, having them all happen inline does have advantages; you should be made constantly aware of the full horror of what you are doing." Nicely put. :) Thanks for the link.
- gbersac 10y agoReally interesting. I already began to inline code with a comment for each block. Didn't knew John Carmack agree with me.
- gknoy 10y agoI was quite surprised at how often copy-paste-modify operations resulted in subtle bugs that weren't immediately obvious. I now strongly encourage explicit loops for everything, and hope the compiler unrolls it properly. I found this particularly interesting
- butabah 10y agoSeeing Carmack's thoughts on programming always reminds me that I have such a long way to go. When he was my age, he had already created DOOM and DOOM 2 (along with the wtf? r_sqrt trick).
- corysama 10y agoFun story: both ID and Epic started out making 2D games. When Tim Sweeny saw Quake for the first time, he literally gave up on gamedev because he thought he wouldn't be able to keep up with game tech. But, shortly afterwards a friend of Tim wrote a Quake-like 3D renderer as a fun project. Tim figured if that guy could do it, he could do it and went on the make Unreal.
- partisan 10y agoThat is incredible. I think that with games in particular, it is very easy to feel like you will never bridge the gap between where you are and whatever current AAA game is doing. It's easy to forget that those games we compare to are made by huge teams. The smaller games that are created by individuals and small teams are the product of a lot of effort. One simply has to stay the course and understand that a game is not made overnight. Still, it can be discouraging.
- damptowel 10y agoIs this true? There's leaked Unreal alpha stuff from 1995, which was already doing almost everything Quake's bsp renderer ended up doing.
- munchbunny 10y agoOne important insight into all of this is that, while there might not have been BSP renderers until 1995, the BSP rendering algorithm was probably 10-20 years old at that point. Another good example of this is the Phong shading model. IIRC it was invented in the mid-70s, and some software rasterizers implemented it, but it didn't really make its way into graphics cards with fixed pipeline rendering until the mid-90s. Graphics tech in the 90s and even early 2000s involved a lot of hardware and software catching up to theory from the 70s and 80s because we were finally getting enough compute power to make it worthwhile to use "approximate" rasterization-based algorithms in order to get real-time rendering.
- corysama 10y ago
- barrkel 10y agoAfter many years of programming, I came round to favour more inlining than I used to (I probably wouldn't go as far as some of this function, however). Needlessly increased variable scopes - and thus increased risk of harder to follow cross-dependencies - is probably the biggest downside risk. But I've found code that executes linearly easier to read and understand when it's written linearly. When everything is factored into functions - particularly impure functions - you need to click all over the place to understand the whole. If there are higher-level primitives that can be used - filters, maps, folds, etc. - then they can reduce the verbosity overall. Some monadic styles can flatten nested code by computing a pipeline / computation rather than having lots of nested loops. But depending on the language and the problem domain, performance may suffer.
- d33 10y agoFor me, this code looks like it was decompiled. It's pretty much this amount of insanity.