Hi,
Looking at that last method, I counted seven «return null».
Is there a PMD for replacing «return null» with Optional?

Ian, Java has also changed a bit the last 20 years.

Best regards,

Roar Brænden

lør. 12. jun. 2021 kl. 12:02 skrev Ian Turton <ijtur...@gmail.com>:

>
>
> On Sat, 12 Jun 2021 at 10:54, Andrea Aime <andrea.a...@geo-solutions.it>
> wrote:
>
>> Hi all,
>> PMD recently released version 6.35, with a new check borrowed from the
>> Sonar family called
>> "Cognitive complexity".
>>
>> In short, it's an improvement over cyclomatic complexity that accounts
>> for the difficulty in understanding
>> code rather than just counting the decision points in a method.
>> You can read a short paper about it here:
>> https://www.sonarsource.com/docs/CognitiveComplexity.pdf
>> (10 pages excluding the appendixes, well worth it IMHO).
>>
>> I took this new check for a spin... it measures the cognitive complexity
>> of methods, with a threshold
>> of 15. That's a non-starter, we have way too many methods above that
>> threshold.
>> I've then tried out 50 and 100, still way too many (oh my gosh!).
>>
>> Pumping it up to 200 (!!!) provides a list of candidates that seems a bit
>> more reasonable to attack.
>> For example, gt-main only has two methods above that threshold. Here they
>> are (brace for cognitive impact!)
>>
>>    - "Conditionals hurricane with love for chained property calls" in
>>    DefaultTemporalPrimitive
>>    
>> <https://github.com/geotools/geotools/blob/f66689b5305eaf381e21dc2feec8011138d4cb24/modules/library/main/src/main/java/org/geotools/temporal/object/DefaultTemporalPrimitive.java#L79>
>>    - "Gonna fit my entire program in a single method" in FilterDOMParser
>>    
>> <https://github.com/geotools/geotools/blob/14d27a2db448454c64e8f38e9977565cc400d52b/modules/library/main/src/main/java/org/geotools/filter/FilterDOMParser.java#L113>
>>
>>
> I think I recognise that method :-) but in my defence I've learned a lot
> in the last 20 years!
>
> This is different from considering just method length, for example, some
>> time ago Gabriel was proposing
>> to look PMD maximum method length check, which flagged only a few
>> methods, including "reproject" which
>> is a 400 lines long method... but only has a cognitive complexity of
>> little above 100, I believe thanks to
>> its flatter structure.
>>
>> So, what do you think? Do you mind having this kind of check as part of
>> the ones performed by PMD?
>> We can start with a score of 200 and go down little by little, until time
>> and interest are exhausted.
>>
>>
> +1
>
> Ian
>
> _______________________________________________
> GeoTools-Devel mailing list
> geotools-de...@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/geotools-devel
>
_______________________________________________
Geoserver-devel mailing list
Geoserver-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geoserver-devel

Reply via email to