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

科技回声

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

GitHubTwitter

首页

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

资源链接

HackerNews API原版 HackerNewsNext.js

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

Clang-expand: Expand function invocations into current scope

58 点作者 6keZbCECT2uB超过 1 年前

8 条评论

gpderetta超过 1 年前
Very very nice. But it should really be an action in clangd instead of its own tool, for simple integration with LSP.<p>Also instead of always replacing the text, it could also be an overlay, where the function call is temporarily expanded in your IDE while in some special mode.
评论 #37588664 未加载
kevincox超过 1 年前
rust-analyzer has this as well. I&#x27;ve never actually used it though. In most cases where I would have found it useful the function was so simple that I just did it manually without thinking. This also seems to do a better job cleaning up the resulting code than rust-analyzer does for example.<p><pre><code> let cell = self.cell_mut(pos); </code></pre> Becomes:<p><pre><code> let cell = { let ref mut this = self; &amp;mut this.board[usize::from(pos)] }; </code></pre> Instead of:<p><pre><code> let cell = &amp;mut self.board[usize::from(pos)]; </code></pre> It did manage to simplify the argument (maybe because it was the same name?) but had to rename `self`.
munro超过 1 年前
wow seriously cool idea here, i think it could be expanded on.<p>currently my only tool is &quot;jump to definition&quot; &amp; docstr tooltips, but if i could expand those definitions in place... i&#x27;d imagine i could grok the code much faster, because i could expand multiple functions and even nested functions, and read the code in one linear flow.
ahaferburg超过 1 年前
Makes me think of these two emails by John Carmack.<p><a href="http:&#x2F;&#x2F;number-none.com&#x2F;blow&#x2F;john_carmack_on_inlined_code.html" rel="nofollow noreferrer">http:&#x2F;&#x2F;number-none.com&#x2F;blow&#x2F;john_carmack_on_inlined_code.htm...</a><p>&gt; The real enemy addressed by inlining is unexpected dependency and mutation of state, which functional programming solves more directly and completely. 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. 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!).
CrendKing超过 1 年前
I sincerely don&#x27;t understand when is this useful. It basically removes all the existing abstractions in the code, and replaces with inline code. Those abstractions were created by someone for some reasons. Blindly destroying them in the name of &quot;refactoring&quot; is just wrong. Refactoring should be process that involves intellectual creativity, involves deeply understanding the intricacy of dependencies and references, not mechanically expanding functions and call it done.<p>Of course, just like rust-analyzer&#x27;s &quot;Expand macro recursively&quot; command, this could be used as an analysis utility, even better if it works not only on functions but also C&#x2F;C++ macros.
评论 #37596406 未加载
评论 #37595191 未加载
MauranKilom超过 1 年前
Maybe I&#x27;m the only one, but... why?<p>What about by-hand-inlining `std::find` makes the code better?
评论 #37593167 未加载
评论 #37591666 未加载
评论 #37594705 未加载
评论 #37594665 未加载
TeMPOraL超过 1 年前
Thank you! It&#x27;s a tool I dreamed of having for years, but couldn&#x27;t arse myself to try and write.<p>The output seems nice enough it should be possible to integrate it with Emacs to show as overlay, vs. actually replacing code - though in practice, I&#x27;d probably want a mix of both.
smasher164超过 1 年前
This is so cool! I want this for every language now.