Live data from Hacker News

John Carmack on inlined code (2014)

number-none.com

261–270 of 402 posts

Re: John Carmack on inlined code (2014)

#261
post #2

When I first heard the maxim that an intelligent person should be able to hold two opposing thoughts at the same time, I was naive to think it meant weighing them for pros and cons. Over time I realized that it means balancing contradictory actions, and the main purpose of experience is knowing when to apply each. Concretely related to the topic, I've often found myself inlining short pieces of one-time code that mad…

I often Bang on about “software is a new form of literacy”. And this I feel is a classic example - software is a form of literacy that not only can be executed by a CPU but also at the same time is a way to transmit concepts from one humans head to another (just like writing) And so asking “will AI generated code help” is like asking “will AI generated blog spam help”? No - companies with GitHub copilot are basically…

> is a way to transmit concepts from one humans head to another (just like writing)

That's almost its primary purpose in my opinion... the CPU does not care about Ruby vs Python vs Rust, it's just executing some binary code instructions. The code is so that other people can change and extend what the system is doing over time and share that with others.

Re: John Carmack on inlined code (2014)

#262
post #168

Earlier quoted context omitted.

What is the benefit of such a yikes? Or do you consider it a yikes language as a whole? Personally I like that functions can be inside functions, as a trade off between inlining and functional seperation in C++. The scope reduction makes it easier to track bugs while it has the benefits of separation of concern.

> What is the benefit of such a yikes? Or do you consider it a yikes language as a whole? None, it was just a simple joke based on the typo in the post I replied to. I like Python, and have in fact been happily using it as my main language for over 20 years.

Ahhh, now I (top level author) get it :)

Re: John Carmack on inlined code (2014)

#263

Earlier quoted context omitted.

To be fair, back in 2014 that was one frame at 60Hz or slower for some titles. At 80-120Hz, 3-5 frames is comparatively similar time.

I don't think high frame rates are common outside of PC gaming yet. Wikipedia indicates the Switch maxes out at 1080p60, and the newest Zelda only at 900p30 even when docked https://en.m.wikipedia.org/wiki/Nintendo_Switch

I play Fortnite and Call of Duty at 120Hz VRR on Xbox Series X.

Re: John Carmack on inlined code (2014)

#264

> That was a cold-sweat moment for me: after all of my harping about latency and responsiveness, I almost shipped a title with a completely unnecessary frame of latency. In this era of 3-5 frame latency being the norm (at least on e.g. the Nintendo Switch), I really appreciate a game developer having anxiety over a single frame.

> In this era of 3-5 frame latency being the norm (at least on e.g. the Nintendo Switch)

Which titles is this true for? Have you or anyone else measured?

Re: John Carmack on inlined code (2014)

#265

Here are some information theoretic arguments why inlining code is often beneficial: https://benoitessiambre.com/entropy.html In short, it reduces scope of logic. The more logic you have broken out to wider scopes, the more things will try to reuse it before it is designed and hardened for broader use cases. When this logic later needs to be updated or refactored, more things will be tied to it and the effects will b…

Of course all this needs to be weighed against maintainability and readability of the code. If the code base is not mainly about something very performance critical and this kind of thing shows to be a bottleneck, then changing things away from more readable towards performance optimized implementation would require a very good justification. I doubt, that this kind of optimization is justified in most cases. For that reason I find the wording "prematurely breaking out code" to be misleading. In most cases one should probably prioritize readability and maintainability and if breaking code out helps those, then it cannot be premature. It could only be premature from a performance limited perspective, which might have not much to do with the use case/purpose of the code.

It is nice, if a performance optimization manages to keep the same degree of readability and maintainability. Those concerns covered, sure we should go ahead and make the performance optimization.

Re: John Carmack on inlined code (2014)

#266

Earlier quoted context omitted.

To be fair, back in 2014 that was one frame at 60Hz or slower for some titles. At 80-120Hz, 3-5 frames is comparatively similar time.

Why would you even bother running at a game at 120Hz if the user's response to what's being drawn is effectively 24-30 FPS?

You’re still getting more information, which allows you to be more accurate with your inputs e.g. tracking a moving target.

Re: John Carmack on inlined code (2014)

#267

Earlier quoted context omitted.

C++ has lambdas and local classes. Local classes have some annoying arbitrary limitations, but they are otherwise useful.

After spending a lot of time writing idiomatic React components in es6, I've found my love of locally declared lambdas to really grow. If I give the lambdas really good names, I find that the main body of my component is very, very readable, even more so than if I'd used a more traditional style liberally sprinkled with comments.

Giving your lambdas names defeats part of their purpose though.

Re: John Carmack on inlined code (2014)

#268

His overall solution highlighted in the intro is that he's moved on from inlining and now does pure functional programming. Inlining is only relevant for him during IO or state changes which he does as minimally as possible and segregates this from his core logic. Pure functional programming is the bigger insight here that most programmers will just never understand why there's a benefit there. In fact most programme…

That most wont get it is due to the fact that most are kind of "industrial programmers", who only learn and use mainstream OOP languages amd as such never actually use a mainly FP language a lot. Maybe on HN the ratio is better than on the whole market though.

Re: John Carmack on inlined code (2014)

#269

Earlier quoted context omitted.

To be fair, back in 2014 that was one frame at 60Hz or slower for some titles. At 80-120Hz, 3-5 frames is comparatively similar time.

I've heard that a good reaction time is around 200 ms, some experiments seem to confirm this figure [1]. At 60Hz, a frame is displayed every 17 ms. So it would take a 12 frames animation and a trained gamer for a couple of frames to make a difference (e.g. push the right button before the animation ends and the opponent's action takes effect). [1] https://humanbenchmark.com/tests/reactiontime/statistics

https://www.researchgate.net/publication/266655520_In_the_bl...

this is for a stylus, but people can detect input latency as low as 1ms (possibly lower)

with VR, they use the term "motion to photon latency", and if it's over ~20ms, people start getting dizzy. at 200ms, nobody is going to be keeping their lunch down

google noticed people making fewer searches if they delayed the result by 100ms

edit: if you want an easy demo, open up vim/nano over ssh, and type something. then try it locally

Re: John Carmack on inlined code (2014)

#270
post #254
post #249

Related: John Carmack on Inlined Code - https://news.ycombinator.com/item?id=39008678 - Jan 2024 (2 comments) John Carmack on Inlined Code (2014) - https://news.ycombinator.com/item?id=33679163 - Nov 2022 (1 comment) John Carmack on Inlined Code (2014) - https://news.ycombinator.com/item?id=25263488 - Dec 2020 (169 comments) John Carmack on Inlined Code (2014) - https://news.ycombinator.com/item?id=18959636 - Jan 201…

There is a longer version of this thought-provoking post, also including Carmack's thoughts in 02012, at https://cbarrete.com/carmack.html . But maybe that version has not also had threads about it.

It doesn't seem to have, since https://news.ycombinator.com/from?site=cbarrete.com is empty.

Should we change the top link to that URL?

Post reply on HN