Ask HN: Does Anyone Use Code Folding?

2 points by eugenhotaj ↗ HN
Does anyone use code folding? If so, what do you feel are the biggest benefits it gives you?

Also curious to see if anyone has any strong reasons against it?

The main benefit I can see is that you can use the folded code as an outline of the classes/functions in the file.

6 comments

[ 3.3 ms ] story [ 20.4 ms ] thread
I use it constantly. It helps visualize code flow in larger files by collapsing branches of loops or conditionals.
I use code folding in Xcode to quickly check if a method is being used in the code base. Code folding allows me to shrink down the amount of scrolling I need to do. Code folding allows me to access the methods I'm checking on that might be "below the fold."
Code folding is awesome for Lisp. Once a function is working, you rarely have to look at it again. Seeing just the first part, eg: +(defun squared (x) tells just about everything you need to know for reference. If not, the documentation string can easily start on that line, too.

Of course a fold that pops up the documentation string on mouse-over would be the cream on top.

I use code folding when editing the TXR man page, because it's close to 69000 lines long. I developed some custom Vim folding rules for that. Here is what it looks like fully folded:

  +--353 lines: .\" t '\" vim:set syntax=groff:-----------------------------------------------------------------
  +--  3 lines: .SH* NAME---------------------------------------------------------------------------------------
  +--  5 lines: .SH* SYNOPSIS-----------------------------------------------------------------------------------
  +-- 54 lines: .SH* DESCRIPTION--------------------------------------------------------------------------------
  +--563 lines: .SH* ARGUMENTS AND OPTIONS----------------------------------------------------------------------
  +-- 47 lines: .SH* STATUS AND ERROR REPORTING-----------------------------------------------------------------
  +--2290 lines: .SH* BASIC TXR SYNTAX--------------------------------------------------------------------------
  +--7519 lines: .SH* DIRECTIVES--------------------------------------------------------------------------------
  +--2238 lines: .SH* TXR LISP----------------------------------------------------------------------------------
  +--47280 lines: .SH* LISP OPERATOR, FUNCTION AND MACRO REFERENCE----------------------------------------------
  +--4613 lines: .SH* FOREIGN FUNCTION INTERFACE----------------------------------------------------------------
  +--1306 lines: .SH* LISP COMPILATION--------------------------------------------------------------------------
  +--1114 lines: .SH* INTERACTIVE LISTENER----------------------------------------------------------------------
  +-- 98 lines: .SH* SETUID/SETGID OPERATION--------------------------------------------------------------------
  +--149 lines: .SH* STAND-ALONE APPLICATION SUPPORT------------------------------------------------------------
  +--  4 lines: .SH* DEBUGGER-----------------------------------------------------------------------------------
  +--852 lines: .SH* COMPATIBILITY------------------------------------------------------------------------------
  +--315 lines: .SH* APPENDIX-----------------------------------------------------------------------------------
Then if we open, say, the FOREIGN FUNCTION INTERFACE section, that looks like this:

  .SH* FOREIGN FUNCTION INTERFACE

  +--- 35 lines: On platforms where it is supported, \*(TX provides a feature called the------------------------
  +--- 21 lines: .SS* Cautionary Notes--------------------------------------------------------------------------
  +--- 79 lines: .SS* Key Concepts------------------------------------------------------------------------------
  +--- 53 lines: .SS* The FFI Type System-----------------------------------------------------------------------
  +---428 lines: .SS* Simple FFI Types--------------------------------------------------------------------------
  +---1091 lines: .SS* Parametrized FFI Type Operators----------------------------------------------------------
  +--- 12 lines: .SS* Additional Types--------------------------------------------------------------------------
  +--- 69 lines: .SS* Endian Types------------------------------------------------------------------------------
  +--- 95 lines: .SS* Bitfield Allocation Rules-----------------------------------------------------------------
  +--- 44 lines: .SS* FFI Call Descriptors----------------------------------------------------------------------
  +---491 lines: .SS* Foreign Function Type API-----------------------------------------------------------------
  +---544 lines: .SS* Foreign Function Macro Language-----------------------------------------------------------
  +---157 lines: .SS* Zero-filled Object Support----------------------------------------------------------------
  +---177 lines: .SS* Foreign Unions----------------------------------------------------------------------------
  +--- 91 lines: .SS* FFI-type-driven I/O Functions------------------------------------------------------...