Many IDEs support the ability to fold "regions" of code. Regions can be denoted by three opening (left) curly braces ( {{{ ), followed by a label, and then closed with three closing (right) curly braces ( }}} ). Example:
/* {{{ myFunction */
function myFunction ($param1, $param2) {
print $param1;
return $param2;
}
/* }}} */
|
The area in the example above between the {{{ and the }}} would be considered a region and, when collapsed, the "myFunction" area just after the {{{ would serve as the collapsed region's label (which would be the visible text inside the
collapsed code box. Another idea to implement this behavior (considering PHP's language syntax for comments) would be:
//region This function does nothing, really
function myFunction ($param1) {
return $param1;
}
//endregion
|
In that case, the region is denoted by
//region and
//endregion with "
This function does nothing, really" serving as the label. The idea stems from VisualStudio, in which this:
#region Private Properties
private DictionaryEntry[] _wamDictItems;
private Int32 _itemsInUse = 0;
private bool _isFixedSize = false;
private bool _isReadOnly = false;
private bool _isSynchronized = false;
#endregion
|
would be a collapsible region.
Using collapsible regions, it allows developers even more options for folding large areas of (related) code to save space in the code window. Consider this:
<?php
//region Functions
function func1 () {
print 'I am func1.';
}
function func2 () {
print 'I am func2.';
}
//endregion
//region Variables
$var1 = 'I am var 1';
$var2 = array(
'Value 1',
'Value 2',
'Value 3',
100 => 'Value 100'
);
$var3 = print_r($var2, true);
//endregion
//region Logic
if ($var1 == 'I am var 4') {
print '$var1 is var 4';
}
elseif ($var1 == 'I am var 1') {
print '$var1 is var 1';
}
//endregion
?> |
With all default collapsible areas collapsed, the user still sees 21 distinct lines of code. However, if you had
regions in the list of collapsibles, the user would only see 7 lines of code. That's one-third the lines![/i]