TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Show HN: A 2D game engine in under 1000 lines of C

98 点作者 ryanpcmcquen超过 5 年前

3 条评论

jsd1982超过 5 年前
Looking at your `init` function, I would refactor it to not be so nested with if statements. Try logically inverting the if checks and returning early up near the top of the method and remove the else branches. Keep repeating this kind of refactoring on all your if statements. Eventually, you&#x27;ll find that the &quot;happy path&quot; ends up at the bottom of the method and can return a success status without being so far indented. This style makes it easier to reason about what conditions are possible at various points in the method, i.e. you don&#x27;t have to mentally compose the boolean logic conditions of all the nested if&#x2F;else statements.<p>Here&#x27;s an example I did: <a href="https:&#x2F;&#x2F;gist.github.com&#x2F;JamesDunne&#x2F;a94782bc39d95515f7dcc8516a18c5cb#file-init-refactor-c-L113" rel="nofollow">https:&#x2F;&#x2F;gist.github.com&#x2F;JamesDunne&#x2F;a94782bc39d95515f7dcc8516...</a><p>Also, I would generally move all implementation code out of header .h files into standard .c files. Header files are traditionally just meant to contain forward-declarations of types and methods.
评论 #22215649 未加载
评论 #22215566 未加载
评论 #22214675 未加载
caymanjim超过 5 年前
What&#x27;s with the majority of the code being in header files?
评论 #22215891 未加载
评论 #22216784 未加载
评论 #22214914 未加载
评论 #22215661 未加载
评论 #22214592 未加载
评论 #22216537 未加载
kazinator超过 5 年前
There is no need for this nonsense:<p><pre><code> #if defined(__WIN32__) || defined(__WINRT__) || defined(_WIN64) fopen_s(&amp;file_to_read, path, &quot;rb&quot;); #else file_to_read = fopen(path, &quot;rb&quot;); #endif</code></pre>
评论 #22268987 未加载