[swift-evolution] Proposal: Require functions to have a cyclomatic complexity of <= 10.

Jonathan Tang jonathan.d.tang at gmail.com
Sun Jan 31 17:01:55 CST 2016


This would also be very restrictive on a lot of common & not-unreasonable
patterns.  A 5-way switch-case with a guard statement in each case has a
complexity of 10, but few people would find it unreadable.  Implementing
the HTML5 spec, even if you break each state up into its own function,
often requires case statements with 20-30 branches, and the adoption agency
algorithm itself has cyclomatic complexity > 10.  An autogenerated lexer
can have hundreds of branches within a function, but since it is generated
by code and the programmer just looks at a bunch of regexps, nobody cares.

I would love to see some of the compiler information (token stream, parse
tree, type analysis, and CFG) exposed as libraries, though, for linters and
other semantic analysis tools to use.

On Sun, Jan 31, 2016 at 11:40 AM, Developer via swift-evolution <
swift-evolution at swift.org> wrote:

> I agree. It would be awesome to have a code linter that takes this into
> account though, but I don't see it as a full-fledged sema phase.
>
> ~Robert Widmann
>
> 2016/01/31 12:34、David Turnbull via swift-evolution <
> swift-evolution at swift.org> のメッセージ:
>
> The language doesn't have to evolve to make this part of the code
> analyzer. I don't need cyclomatic complexity analysis in the language or
> the regular build process. Better to compile faster.
>
> -david
>
> On Sun, Jan 31, 2016 at 8:45 AM, Amir Michail via swift-evolution <
> swift-evolution at swift.org> wrote:
>
>> I think that this one metric built into the language would have a huge
>> impact on Swift development and for the better.
>> _______________________________________________
>> swift-evolution mailing list
>> swift-evolution at swift.org
>> https://lists.swift.org/mailman/listinfo/swift-evolution
>>
>
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution
>
>
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160131/993ee8b1/attachment.html>


More information about the swift-evolution mailing list