Why is it recommended to have empty line in the end of a source file?

后端 未结 8 793
独厮守ぢ
独厮守ぢ 2020-12-02 04:44

Some code style tools recommend this and I remember seeing some unix command line tools warning about missing empty line.

What is the reasoning for having an extra e

相关标签:
8条回答
  • 2020-12-02 05:39

    Some languages define their input file in terms of input lines, where each input line is a series of characters terminated by a carriage return. If their grammar is so defined, then the last valid line of the file must be terminated by a carriage return too.

    0 讨论(0)
  • 2020-12-02 05:47

    An argument can also be made for cleaner diffs if you append to the file following the same reasoning as Why are trailing commas allowed in a list?

    The following is copied (and trimmed a bit) from the linked resource:

    Changing:

    s = [
      'manny',
      'jack',
    ]
    

    to:

    s = [
      'manny',
      'jack',
      'roger',
    ]
    

    involves only a one-line change in the diff:

      s = [
        'manny',
        'jack',
    +   'roger',
      ]
    

    This beats the more confusing multi-line diff when the trailing comma was omitted:

      s = [
        'manny',
    -   'jack'
    +   'jack',
    +   'roger'
      ]
    
    0 讨论(0)
提交回复
热议问题