Live data from Hacker News

A Missing IDE Feature

matklad.github.io

21–30 of 54 posts

Re: A Missing IDE Feature

#21
post #3

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.

That's probably a secondary issue. The suggestion is to change how code folding is done. Most IDEs can do some type of code folding, but in this case the author is asking for it to work in a certain way.

I don't think the example is all that good, because it's not the same code in both screenshots. The suggestion, as I read it, is that folding the "impl Body" shouldn't collapse the entire thing to impl Body { ... }, but instead collapse all the functions inside it, because that's actually more useful. So you'd get

    impl Body {
      fn new(db: &dyn DefDatabasse) { ... }
      pub fn shrink_to_fit(&mut self) { ... }
    }
It this was Python and you collapsed a class, then rather than getting

    class User(AbstractUser): ... 
you'd get:

    class User(AbstractUser):
      def is_manager(self): ...
      def get_username(self): ...
It would perhaps even be a little neat if you could have a class collapsed and you'd be shown only public methods, if the language has the concept of public and private methods.

To build on the "hiding awful code", I think this could help show awful API/interface design. If you have a class with a few hundred lines of code and a number of methods, then you rarely get to see all your methods listed, their signature just drowns in a sea of code. The also add doc strings, then you now have a documentation view of your own code in the IDE.

Re: A Missing IDE Feature

#22
post #5

The IDE isn't the root cause though, hiding code complexity is a patch. 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't need colors to make sense of it.

I don’t see this as hiding code complexity or an alternative to writing cleaner code. It seems the argument is that when we come to a file/class/etc., that we should be initially presented with the outline rather than both the outline and details. It’s an approach to orienting oneself to a grouping of functionality, made first class by the IDE. It’s almost like opening a book and starting with the table of contents before diving into any specific chapter’s details. Allowing the reader to get a sense of what’s covered by this grouping of functionality before diving into the details. I haven’t tried this approach myself but it seems like an interesting exercise at the least.

Re: A Missing IDE Feature

#23
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.

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.

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.

Re: A Missing IDE Feature

#25
post #16

https://github.com/zenozeng/yafolding.el has been around for at least a decade -- and that is basically helper code on top of functionality that's been available for longer than a fair few people reading this have been alive.

From the linked post: > First, only method bodies are folded. This is a syntactic check — we are not folding the second level.

i’m also entirely sure you could do this “properly” with tree sitter and some small fiddling

edit: by way of https://github.com/mickeynp/combobulate/issues/27, it's been done: https://github.com/emacs-tree-sitter/ts-fold

Re: A Missing IDE Feature

#28
VSCode has extensive control over folding, including custom fold sections. AFAIK auto-folding after opening a file isn't implemented, but there's extensions for that, like: https://marketplace.visualstudio.com/items?itemName=bobmagic....

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 should make sense). If your code requires code folding to be readable, it's really better to restructure your code to be more readable (and often it is better to not hide complexity because you can see immediately where the gnarly parts are - and by hiding those you're not doing anybody a favour).

Re: A Missing IDE Feature

#30
I don't want folding. I want to see text as-is, and such symbol lookup should be a seprate view.

In neovim, I prefer aerial's telescope extension: https://github.com/stevearc/aerial.nvim?tab=readme-ov-file#t...

I don't like folding because toggling folding state is clunky with keyboard only. I'm okay with fold/unfold all, but doing it manually fells like a chore.

Post reply on HN