|
||||||||
What is Code FoldingCode folding allows to hide a group of lines in a text file and to show only a descriptive headline instead. This allows to hide the details and to show the structure of a text file, like the summary of a book. Folding methodsThere is several methods to specify which lines are to be folded. 1. Syntax-based foldingThe editor analyses the source code and selects the lines that can be folded, usually it allows to fold classes, functions, if-then-else statements, ... Syntax-based folding tends to create too many folds without added value: folding every 'if' and 'while' blocks does not help navigation or readability, except may be, huge 'while' blocks, but anyway, creating such blocks is a very bad programming practice. 2. Indentation-based foldingThe indented blocks of code can be folded. 3. Marker-based foldingAlso referred to as explicit folding in jEdit. The editor allows to insert markers in the text file to delimit the beginning and the end of the section of text to hide. These markers are usually embedded into comments to prevent a compiler to interpret them. This method is the most flexible, you can fold any group of lines and specify any descriptive headline instead of just showing the first line. It also works with any kind of source file allowing comments, and fortunately, it is the case with almost all programming languages and markup languages. But this method is also the most painful to use because you must select manually the regions of text to be folded and enter a headline for each one. However the extra effort worth it. Navigation methodsWhen some text is folded in a folding editor, there is two way to get it. 1. ExpandingThe collapsed section is expanded, so you can edit text and collapse the section again when finished. Collapsing and Expanding is usually performed with shortcuts or a button in the left margin.
This is the most common method used by almost 99% of text editors having folding capability. 2. Changing contextInstead of collapsing and expanding sections, this method keeps always folded section collapsed and if you want to view such a section, the current text is replaced by the collapsed text. This approach transforms a long flat text file into a hierarchy of smaller text blocks. ExampleThis is a small example in C...
The fact() functions is now folded with just a headline displayed.
The implementation detail of the function is hidden an there is only a descriptive
headline visible.
There is markers in comments at the beginning and at the end of the
function, so, for the compiler, it is a perfectly valid source code.
Folding in Code BrowserCode Browser supports only the marker-based folding. This method is far more flexible than indentation-based or syntax-based folding but it requires more manual work by the user. Almost all text editors that implement folding use a collapse and uncollapse method to show the folded content. Code Browser uses a different mechanism, the content is displayed in a different page: you can 'enter' or 'leave' a folded section. When there is only one page, the current page is replaced by the new one, and it is possible to return to the previous page with the 'Back' command. The behavior is very similar to navigation on the WEB with a browser.
Code Browser can show the same structured text file with different layouts.
Advantages of FoldingThe code structure is easier to view Faster navigation Scope of search Better programming practices See also
|
||||||||