Code Design → Separator First
It is used when we have a set of some expressions, separated by some short separator, which needs to be presented to several lines.
The traditional Egyptian way of representing:
Please note that at the end of each line there is a comma, except for the last - there should not be a comma there. The problem is that when rearranging lines in places and other copy-paste accelerating the process of writing code, you need to carefully monitor the commas, and since they are not visible, this inevitably leads to an error.
Separated first:
Here all the separators go in one line and are covered by one glance, which means that if you forget to fix some separator, it will immediately catch your eye:
Now add nesting:
In the variant with separators, the fidelity of the syntax is first evaluated by a cursory glance, in contrast to the traditional version. In addition, it is easier to edit when all the delimiters are on the same level, rather than jumping randomly at the end of the line.
A similar method can be applied when calling functions:
Please note that the Egyptian notation is used to determine the callback, because the separator between the operators is the line feed character, which you can’t put at the beginning of the line. Although, if you do not break the seven-column, then you can do this:
But it’s more convenient to use the Egyptian notation and not bother with delimiters.
do not pay attention to the different tab sizes - all claims to the author of the syntax highlighter,
did anyone notice a typo in one of the Egyptian codes? ;-)
The traditional Egyptian way of representing:
- var userList= [
- { name: 'Tom', Age: 5, race: 'cat' },
- { name: 'Jerry', Age: 3, race: 'mouse' },
- { name: 'Spike', Age: 11, race: 'dog' }
- ]
* This source code was highlighted with Source Code Highlighter.Please note that at the end of each line there is a comma, except for the last - there should not be a comma there. The problem is that when rearranging lines in places and other copy-paste accelerating the process of writing code, you need to carefully monitor the commas, and since they are not visible, this inevitably leads to an error.
Separated first:
- var userList=
- [ { name: 'Tom', Age: 5, race: 'cat' }
- , { name: 'Jerry', Age: 3, race: 'mouse' }
- , { name: 'Spike', Age: 11, race: 'dog' }
- ]
* This source code was highlighted with Source Code Highlighter.Here all the separators go in one line and are covered by one glance, which means that if you forget to fix some separator, it will immediately catch your eye:
- var userList=
- , { name: 'Jerry', Age: 3, race: 'mouse' }
- [ { name: 'Tom', Age: 5, race: 'cat' }
- , { name: 'Spike', Age: 11, race: 'dog' }
- ]
* This source code was highlighted with Source Code Highlighter.Now add nesting:
- var userList= [
- {
- name: 'Tom',
- Age: 5,
- race: 'cat'
- },
- {
- name: 'Jerry',
- Age: 3,
- race: 'mouse',
- },
- {
- name: 'Spike',
- Age: 11,
- race: 'dog'
- }
- ]
-
- var userList=
- [ { name: 'Tom'
- , Age: 5
- , race: 'cat'
- }
- , { name: 'Jerry'
- , Age: 3
- , race: 'mouse'
- }
- , { name: 'Spike'
- , Age: 11
- , race: 'dog'
- }
- ]
* This source code was highlighted with Source Code Highlighter.In the variant with separators, the fidelity of the syntax is first evaluated by a cursory glance, in contrast to the traditional version. In addition, it is easier to edit when all the delimiters are on the same level, rather than jumping randomly at the end of the line.
A similar method can be applied when calling functions:
- anElement.AddEventListener
- ( 'click'
- , function( event ){
- if( event.button ) return true
- console.log( event )
- return false
- }
- , false
- )
* This source code was highlighted with Source Code Highlighter.Please note that the Egyptian notation is used to determine the callback, because the separator between the operators is the line feed character, which you can’t put at the beginning of the line. Although, if you do not break the seven-column, then you can do this:
- anElement.AddEventListener
- ( 'click'
- , function( event )
- { if( event.button ) return true
- ; console.log( event )
- ; return false
- }
- , false
- )
* This source code was highlighted with Source Code Highlighter.But it’s more convenient to use the Egyptian notation and not bother with delimiters.
do not pay attention to the different tab sizes - all claims to the author of the syntax highlighter,
did anyone notice a typo in one of the Egyptian codes? ;-)