什么是长线太长?

EdG*_*man 1 .net linq vb.net linq-to-objects

这工作(Visual Basic .NET),但似乎很长,所有LINQ to Object方法和就地尺寸.

For Each PNGFile As System.IO.FileInfo In New System.IO.DirectoryInfo(Server.MapPath(".\Archive")).GetFileSystemInfos("*.png", System.IO.SearchOption.AllDirectories).OrderByDescending(Function(f) f.LastWriteTimeUTC).Skip(PageSize * Page).Take(PageSize)
    'Do stuff with PNGFile
Next
Run Code Online (Sandbox Code Playgroud)

我喜欢这一切都在一条线上,我认为它甚至可以为我自己进行逻辑阅读.但我的直觉告诉我,对于下一个不得不解释我的代码的可怜的灵魂来说,这是不可能的.或者是吗?你是如何决定的?将此行拆分为多个其他标注和赋值语句是否值得?你会如何打破这个特定的阵容呢?

我是.NET的新手,但我已经编写了10年以上的代码.到目前为止,我已根据创建代码时采用的典型分辨率确定了代码中的最大行长度.这不是决定......的最好方法

Bro*_*ass 7

我通常在新的LINQ扩展方法上拆分行,对我来说看起来更干净:

For Each PNGFile As System.IO.FileInfo In New  System.IO.DirectoryInfo(Server.MapPath(".\Archive"))
   .GetFileSystemInfos("*.png",System.IO.SearchOption.AllDirectories)
   .OrderByDescending(Function(f) f.LastWriteTimeUTC)
   .Skip(PageSize * Page)
   .Take(PageSize)
      'Do stuff with PNGFile
Next
Run Code Online (Sandbox Code Playgroud)

  • 是的,现在VB允许你在大多数情况下忽略行继续字符,很少有人为这么长的行提​​供借口. (2认同)