Is The Fold Method Bodies by Default a Missing IDE Feature ? (matklad.github.io)
from lascapi@jlai.lu to programming@programming.dev on 17 Oct 2024 10:35
https://jlai.lu/post/11533872

#programming

threaded - newest

Carighan@lemmy.world on 17 Oct 2024 11:33 next collapse

I read this and I kept thinking at first “There’s no way I haven’t seen this in IntelliJ bef…”… oh. Of course that’s the one positive example. 😅

Two thumbs up Jetbrains. And yeah, I think all IDEs for all languages should allow this as a modified view type. Maybe even bidirectional for special cases.

bear@lemmynsfw.com on 17 Oct 2024 11:39 next collapse

No. The most basic task is just reading. I’d rather look at the full text by default because it’s easier to scroll and read than have to keep clicking and playing hide and seek. And it’s too easy to miss a very important part because everything looks the same and is equally hidden.

eager_eagle@lemmy.world on 17 Oct 2024 21:21 collapse

Also, folding encourages 1000+ line files and several indentation levels, like in their example.

xigoi@lemmy.sdf.org on 17 Oct 2024 13:31 next collapse

Betteridge’s law of headlines…

thingsiplay@beehaw.org on 17 Oct 2024 14:08 next collapse

I don’t think folding code parts is a default feature that everyone needs. Vim has folding already and I never use it. To me it is kind of pointless. If the code is messy, then you probably should split it up into several files. There is also a better way to me, through listing jump points on the side (such as function definitions). But its good to have extensions to provide that functionality if you rely on.

The second option is clearly superior

No, the first option is clearly superior. I don’t like collapsed code, its hiding stuff and doesn’t help in anything to me. Its better to see the entire context. The same list of function definitions can be displayed in a more useful jump list on the side (in my opinion).

But maybe its a question of implementation. I would like to see advancements in this field, to see if it is more useful than the current features we have to fold methods and functions.

thingsiplay@beehaw.org on 17 Oct 2024 14:37 collapse

I just found nvim-ufo - “The goal of nvim-ufo is to make Neovim’s fold look modern and keep high performance.

nous@programming.dev on 17 Oct 2024 15:04 next collapse

Honestly I think function folders is the wrong solution here. I see two different modes of exploring the code here - a high level over view of what is available and a detailed look at the actual code. Code folding to switch between these two modes is not, I think, the best way to do this. Just the easiest thing to replicate in most editors.

A better solution would be a separate view for these - maybe a side bar or overlay that you can popup when you want to navigate the code.

Rust docs has this - a summary of the methods and other symbols on the side with full descriptions in the main view.

Helix has a nice symbol picker which with some tweaks could be a much nicer way to do this:

<img alt="" src="https://programming.dev/pictrs/image/02fb8bab-15f6-4c30-910b-e5b6d32972ae.png">

If it did not strip so much info from the symbols it would basically show the collapsed view along side the code with the ability to search and jump to the code you are interested in. I want to see more refinement on features like this and not just have code folding which I tend to find more annoying and limiting - having to constantly collapse and expand sections when what I really want is to jump around the code base.

zygo_histo_morpheus@programming.dev on 17 Oct 2024 15:37 next collapse

Vim sort of already has this feature via set foldmethod=syntax. This doesn’t work exactly like the author suggests but you can also use set foldmethod=expr and then set foldexpr to a more complicated expression to only get nested function/method bodies, via tree sitter for example if you’re on neovim.

Treeniks@lemmy.ml on 17 Oct 2024 17:57 next collapse

I’ll never get over how cool animated code folding looked when I first saw it. I love my terminal but man that’s sexy. Reminds me of some of the original demos of Dion. I feel there is definitely room to reinvent how we view and edit code.

[deleted] on 17 Oct 2024 21:27 next collapse

.

Kache@lemm.ee on 18 Oct 02:07 collapse

IMO folding to hide is about equivalent to moving all contents to another file/private function:

def bad_function(args):
    return _hide_elsewhere(args)

i.e. does nothing. Real solution to pyramids of doom is to fix the code.