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

科技回声

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

GitHubTwitter

首页

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

资源链接

HackerNews API原版 HackerNewsNext.js

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

A Missing IDE Feature

47 点作者 aiono6 个月前

31 条评论

chromanoid6 个月前
IMO this depends on the reading style.<p>&quot;Fold Method Bodies by Default&quot; is something I deactivate immediately. After two decades of reading code, I am optimized to read syntax-highlighted code pretty hard. This just hides the stuff I am looking for - I read code because I want to know what it does.<p>For an overview I look at the outline. With wide screens, I think it is a much better place for a structural overview. I would be more happy to see advancements there.
seanhunter6 个月前
In what sense is this missing? You can absolutely do this in vim so it must (by the principle of duality) also be present in emacs. Since he shows it in IntelliJ it’s obviously not missing from there so I’m assuming vscode has it also.<p>Automatic folding is something I almost always disable because I hate it when an editor tries to hide information from me. I strongly prefer to choose when I want things folded but by default to have things be as close as possible to the native text format just with syntax highlighting.<p>This is particularly true for PRs and diffs, where the details of implementation really matter and I would consider reviewing anything which was folded to be potentially extremely risky.
评论 #42041993 未加载
scoopr6 个月前
I find my self disagreeing quite strongly, I would hate that default :&#x2F;<p>I find all kind of code folding massively throws off my spatial sense of the code. And if I&#x27;m browsing random code, then I often need to see the body too, to see if this is the place the work is done, or is it behind some abstraction down the line.<p>Perhaps I don&#x27;t need it as much on c++ codebases, as the headers in a sense are that already. And Rust codebases I&#x27;ve dabbled in haven&#x27;t been quite that big or overwhelming.<p>The outlineview&#x2F;(the popup on top of buffer in many editors that lists the outline) is enough to finding my place in a file I feel lost. And if just looking how to use a lib, there is often some API documentation that helps along finding the right things (even if just barebones doxygen or rustdoc).<p>I&#x27;m sure this is as much of a habit thing as other editor preferences. Still I find it surprising how many people like code-folding :)
评论 #42042611 未加载
OhMeadhbh6 个月前
FWIW... LSE (Language Sensitive Editor) on OpenVMS (an operating system probably older than most readers) did this in the 1980s.<p>I think what this article is getting at but doesn&#x27;t quiet explicitly say is people look at code for different reasons. If you&#x27;re fixing a defect and you think you know where the problem lies, you may want everything to come up folded so you can get to the function you think you want to look at quickly. If you&#x27;re trying to get a handle on what the code in the file does, you may want everything to come up unfolded. Or maybe you want to unfold all functions that take a particular data structure as a parameter.<p>The global settings at my installation for the LSE (Language Sensitive Editor) I mentioned earlier were set to fold all .c files. I initially found it annoying, but quickly learned the &quot;unfold everything&quot; key sequence. And then the &quot;unfold this function once&quot; which didn&#x27;t unfold the contents of loops or ifs and the &quot;unfold everything in this function.&quot; I was able to quickly get used to it and spent a year replicating the functionality in emacs.<p>But... I completely agree with people saying this should be a configurable setting.<p>And... if you implement this, please allow selective unfolding of different parts of the code.
000ooo0006 个月前
Controlled by foldexpr in Neo&#x2F;Vim IIRC, and I think VS proper has a shortcut Ctrl+M,Ctrl+O from memory. To round it out, VS Code has Ctrl+K+,Ctrl+2 where 2 is your level of folding of choice. Despite using these 3 editors every day and knowing the folding shortcut, I still don&#x27;t collapse bodies as a matter of routine and I think I&#x27;d find it annoying if I had to toggle each open just to find relevant code.<p>There&#x27;s also something to be said for the idea that code has a 2D shape to it and recognising parts visually can make navigating it a little easier if you&#x27;re bouncing between a couple of areas for a particular change. I wouldn&#x27;t want to obscure that, not by default anyway. But to each their own!
aithrowawaycomm6 个月前
I am a grownup and therefore have no problem with &quot;fold methods by default&quot; being a toggle-able option, but this argument seemed odd to me:<p>&gt; I think it is pretty obvious how awesome this actually is. Code is read more often than written, and this is one of the best multipliers for readability. Most of the code is in method bodies, but most important code is in function signatures. Folding bodies auto-magically hide the 80% of boring code, leaving the most important 20%.<p>I see where they&#x27;re coming from, especially for codebases you already understand. But my workflow for new codebases is to at least visually inspect the method implementation before deciding whether or not to hide it. Does it actually look like boilerplate? Does it invoke any functions I haven&#x27;t seen before? If it seems nontrivial, read it! Does the computation basically match my English-language description of the signature, or is there something deeper I missed? If everything was hidden by default I would either waste time un-hiding everything, or make lazy mistakes by saying &quot;eh I&#x27;m pretty sure that&#x27;s boilerplate.&quot; Coding by gluing together function signatures without reading the implementation is a recipe for making business-logic bugs.<p>My problem is similar to why I don&#x27;t like using LLMs: taking the 80-20 thing at face value, you don&#x27;t know which 20% of methods have nontrivial internal semantics which aren&#x27;t conveyed by the type system, unless you already have a solid understanding of the code. (Note that Rust&#x27;s type system does actually evade mutability &#x2F; concurrency issues. But not incorrect business logic: it is not yet Lean or Idris.) I just don&#x27;t like rolling the dice on this stuff - business logic bugs are horrible! They are difficult to suss out, especially if you weren&#x27;t fully diligent in understanding the logic in the first place. Why would you roll a d5 on that?<p>Part of my aversion is that I am lucky enough to not be in a hurry. At my last job - 70 hrs&#x2F;week of R and Python, reading papers, and writing emails - I would have been much more tempted for these &quot;multipliers for readability,&quot; especially ChatGPT. But when you&#x27;re not in a hurry, you are more sensitive to these multipliers also multiplying laziness and misconceptions.
unkiwii6 个月前
Hiding those awful nested statements makes you think that perhaps the code is ok when it should probably be changed to make it more readable.
评论 #42041539 未加载
Cthulhu_6 个月前
The IDE isn&#x27;t the root cause though, hiding code complexity is a patch.<p>Write cleaner code or use a higher level language that allows for more readable code. For example, some Go developers (...mainly Rob Pike, granted) eschew even syntax highlighting, as readable code shouldn&#x27;t need colors to make sense of it.
评论 #42041545 未加载
评论 #42041520 未加载
评论 #42041501 未加载
mrkeen6 个月前
Depending on your language you might be able to have it both ways - summary at the top, and implementation details down below. And it&#x27;s just in the text itself, so it&#x27;s as readable in Github as it is in an IDE.<p><pre><code> -- Top of file: data Indexer = Indexer { indexDocuments :: !(CollectionName -&gt; [Doc] -&gt; IO (Either String Int)) , indexLocalWarcFile :: !(CollectionName -&gt; FilePath -&gt; IO (Either String ())) , deleteDocument :: !(CollectionName -&gt; String -&gt; IO (Either String ())) , isDocDeleted :: !(CollectionName -&gt; String -&gt; IO (Either String (Map Text Int))) } -- Further down: indexDocumentsImpl env writer metadataApi compactor registry collectionName unsortedDocs = do let ds = sort unsortedDocs let nDocs = length ds ... newLocalWarcFileIndex env warcFileReader writer metadataApi compactor registry collectionName warcFile = batchedRead warcFileReader warcFile newIndexify where newIndexify :: Vector WarcEntry -&gt; IO () newIndexify ds = do ... etc.</code></pre>
flohofwoe6 个月前
VSCode has extensive control over folding, including custom fold sections. AFAIK auto-folding after opening a file isn&#x27;t implemented, but there&#x27;s extensions for that, like: <a href="https:&#x2F;&#x2F;marketplace.visualstudio.com&#x2F;items?itemName=bobmagicii.autofoldyeah" rel="nofollow">https:&#x2F;&#x2F;marketplace.visualstudio.com&#x2F;items?itemName=bobmagic...</a>.<p>I try folding from time to time but never really can get used to it (even though I work on massively big source files where folding function bodies actually <i>should</i> make sense). If your code requires code folding to be readable, it&#x27;s really better to restructure your code to be more readable (and often it <i>is</i> better to not hide complexity because you can see immediately where the gnarly parts are - and by hiding those you&#x27;re not doing anybody a favour).
hprotagonist6 个月前
<a href="https:&#x2F;&#x2F;github.com&#x2F;zenozeng&#x2F;yafolding.el">https:&#x2F;&#x2F;github.com&#x2F;zenozeng&#x2F;yafolding.el</a><p>has been around for at least a decade -- and that is basically helper code on top of functionality that&#x27;s been available for longer than a fair few people reading this have been alive.
评论 #42041466 未加载
corytheboyd6 个月前
I love the JetBrains code folding, but I would hate it being on by default. Lots of arguments here about “you shouldn’t need this feature, just write better code”, which is fair, but unrealistic for massive projects you’re doing surgery on. It’s in those cases that I may use code folding to make a terrible file visually scannable again (only collapse bodies, as author mentions), then selective unfold bodies (potentially nested) as I need to see them. It’s not the most important feature TBH, but it’s nice that it’s there. I prefer it to the hierarchy tree because I don’t have to leave the editor part of the UI, and can use only keyboard shortcuts for selecting and folding code.
dpkirchner6 个月前
Hard disagree but it&#x27;d be fine to have it as an option, of course. The author mentioned an outline -- if we could have that as a separate page, easily toggled with a key combination, that&#x27;d be sweet.<p>Code folding by default triggers thoughts of the annoying, mostly useless TypeScript d files that VSCode dumps you in to when you ctrl&#x2F;cmd click into a function. The only reason I do that is to see implementation details so I can figure out why something&#x27;s not working. If third-party library d files were replaced by pre-folded source, I guess that&#x27;d be OK.
invalidname6 个月前
I was recently using IntelliJ to write some HTML. I suddenly noticed a wayward &amp; character. It was blue so I assumed that was syntax highlighted... I quickly changed that to a valid entity and committed without really reviewing the code (i know I&#x27;m an idiot).<p>Turns out that JetBrains format the entity as the resulting character... a feature that was meant to make code readable had confused me. I had similar issues with clion which presents weird notations on the code with no indication of their purpose. This is a double edged sword.
righthand6 个月前
Has existed in Sublime Text for a very long time, no plugin required.
评论 #42041723 未加载
ivanjermakov6 个月前
I don&#x27;t want folding. I want to see text as-is, and such symbol lookup should be a seprate view.<p>In neovim, I prefer aerial&#x27;s telescope extension: <a href="https:&#x2F;&#x2F;github.com&#x2F;stevearc&#x2F;aerial.nvim?tab=readme-ov-file#telescope">https:&#x2F;&#x2F;github.com&#x2F;stevearc&#x2F;aerial.nvim?tab=readme-ov-file#t...</a><p>I don&#x27;t like folding because toggling folding state is clunky with keyboard only. I&#x27;m okay with fold&#x2F;unfold <i>all</i>, but doing it manually fells like a chore.
HelloNurse6 个月前
I&#x27;d expect short, important method bodies that should be visible by default to vastly outnumber long and uninteresting method bodies that should be folded away by default.<p>This is, of course, my experience with mostly unexciting Java and Python; there should be options, maybe per language or per project, or even heuristics (e.g. fold long methods, by character count and&#x2F;or line count, and recognized getters and setters but not other short methods).
throwaway3133736 个月前
It is unclear what is the condition of automatic folding of the second level and below.<p>If you are using &quot;Go to...&quot; a struct declaration or impl in Rust (or a class in other languages) it actually makes a lot of sense. If I&#x27;m going to a struct&#x2F;impl&#x2F;class I don&#x27;t know yet which method do I won&#x27;t to see. If you are just opening a file that you haven&#x27;t open before though... I&#x27;m not so sure.
flerchin6 个月前
Why is the author not using Jetbrains? I don&#x27;t Rust, but it looks like they have RustRover. I love Jetbrains, and gladly pay for ultimate.
评论 #42041350 未加载
anotherpaulg6 个月前
This is exactly how aider shares code context with LLMs using a “repo map”. It uses tree sitter to collapse relevant files into this sort of folded version, showing function signatures but eliding their bodies.<p><a href="https:&#x2F;&#x2F;aider.chat&#x2F;docs&#x2F;repomap.html" rel="nofollow">https:&#x2F;&#x2F;aider.chat&#x2F;docs&#x2F;repomap.html</a>
jallasprit6 个月前
I really wish something like this was available in VSCode or jetbrains IDEs: <a href="https:&#x2F;&#x2F;github.com&#x2F;hoschi&#x2F;yode-nvim">https:&#x2F;&#x2F;github.com&#x2F;hoschi&#x2F;yode-nvim</a><p>I tried to build it but the extension API is just not there for it. I’d happily pay $$$ for something like this if anyone feels nerd sniped.
kernc6 个月前
What you appear to be missing is a &quot;symbols view &#x2F; pane&quot;. Most IDEs have that!<p><a href="https:&#x2F;&#x2F;www.google.com&#x2F;search?q=ide+symbols+pane&amp;tbm=isch" rel="nofollow">https:&#x2F;&#x2F;www.google.com&#x2F;search?q=ide+symbols+pane&amp;tbm=isch</a>
评论 #42042605 未加载
评论 #42041856 未加载
exabrial6 个月前
Would definitely deactivate and probably write a rant about it.
addicted6 个月前
VIM already basically does this and can be configured to do it automatically with folding as the default, while providing pretty fine grained manual control on folding.
rqtwteye6 个月前
Instead of folding I much prefer a separate window that shows the structure of the file with functions, methods and member variables.
theodorejb6 个月前
This is such a nice feature in PhpStorm. I hope VSCode and other editors will add support for it too.
评论 #42041824 未加载
olejorgenb6 个月前
Sounds like the author would like Eclipse Mylyn (if it&#x27;s still maintained :&#x2F;)
评论 #42042018 未加载
cynicalsecurity6 个月前
This feature has existed in NetBeans for ages.
throwaway3133736 个月前
I think that people who suggest to &quot;just write cleaner code&quot; are missing the point entirely.<p>Of course, we all are trying to write clear code. It doesn&#x27;t mean that your tool should make working with less than perfect codebases unbearable.
mamcx6 个月前
That is called pascal!
frizlab6 个月前
I mean it’s a single shortcut away (in Xcode anyway, don’t know about the rest); not sure a new setting is useful for this…