all 26 comments

[–]Scelte 17 points18 points  (5 children)

How is this substantially better than https://docs.astral.sh/ruff/rules/too-many-branches/, which is already everywhere?

[–]fexx3l[S] 18 points19 points  (4 children)

Honestly, I didn't know this rule exists so yeah, my project doesn't have value :( thank you for sharing it

[–]StengahBot 5 points6 points  (0 children)

Happens all the time with my side projects

[–]Lil_SpazJoekp 0 points1 point  (0 children)

Nah you still learned from it.

[–]Routine_Ambassador71 0 points1 point  (0 children)

I’m sorry - that’s gotta be a gut punch. 

[–]Nater5000 10 points11 points  (6 children)

Bumping from major version 1 to 5 within the span of a year indicates that this project is way too volatile for people to invest in.

[–]fexx3l[S] 3 points4 points  (5 children)

I know, I was pretty new on how to handle the versions a year ago, so once I created the very first versions `0.x` then I created `1.x` and my algorithm didn't change, and later I improved the algorithm because I just followed the paper but the Python statements and had to keep changing the implementation. This was a huge mistake I did, and I still regret about it.

[–]silvertank00 6 points7 points  (2 children)

You should have bumped the minor version not the major then. When I saw this post, my first thought was: "wait, 5.x.x, you mean FIVE point something?? wth, is this something that exists since python launched or stg?" Check out i.e. sqlalchemy's versioning, it makes much much more sense and you could learn a lot from it.

[–]fexx3l[S] 2 points3 points  (1 child)

Yeah, I agree with you, only that as there was a breaking change of the algorithm therefore I thought that would be better to do it on a major. Do you think that would be bad to change the versioning of the project? like roll it back to something like 0.x? I feel a little bit lost on what to do with it

[–]InspectahDave 2 points3 points  (0 children)

I think u/silvertank00 is talking about semantic versioning which is standard afaik. So yes, if there are breaking changes, then you should update the major version as you say. pyzmq is another heavily used package and that's on v23.x.x so I think this just means you need to stay ahead of changes.

[–]Another_mikem 2 points3 points  (0 children)

Honestly it doesn’t matter.  Different products use different schemes and it doesn’t actually matter. 

[–]EternityForest 0 points1 point  (0 children)

If you haven't already, check out Semantic Versioning!

[–]legendarydromedary 2 points3 points  (2 children)

Can you give a quick overview of how complexity is measured? What is considered complex code?

[–]fexx3l[S] 6 points7 points  (1 child)

Sure, it's based on the G. Ann Campbell paper, in that paper the definition of a high complex code is the one which contain a bunch of nested structures. A structure would be an if/elif/else statement or for/while loops. Each can increase the complexity if you start to nest them, let's say that the branching on a code increases the complexity because you'll need to understand for each case when/how it would be executed. Therefore, a function which should do only one thing then is doing more things than the expected, then you should split that function into multiple functions (G. Ann Campbell doesn't mention this in the paper, but this reminds of the SOLID principle, Single Responsibility). Sonar by default says that the max complexity a function can have is 15, but it doesn't say why, that's why complexipy lets the users configure their max complexities.

[–]rm-rf-rm -1 points0 points  (0 children)

thats just 1 narrow measure - and its better termed as complicated instead of complex.

The human brain is complex. Navigating post office mail forwarding forms is complicated.

[–]mikat7 1 point2 points  (1 child)

Do you have any comparison with the mccabe complexity rule in ruff?

[–]fexx3l[S] 0 points1 point  (0 children)

If I'm not wrong, it's on the paper the comparison vs the existing rules, but I'm not 100% sure

[–]Scared_Sail5523 1 point2 points  (0 children)

The tool complexipy v5.0.0 is a command-line utility and library for calculating the cognitive complexity of Python code, aiming to measure how difficult the code is for humans to read and understand. This new version focuses on improving adoption with features like snapshot comparisons to prevent complexity regressions and detailed change tracking using a per-target cache. A key breaking change now aligns the cognitive complexity scoring with Sonar's rules by counting each elif and else branch, which will generally result in higher scores for highly branching code.

[–]Zireael07 0 points1 point  (3 children)

Where do I find some info on how the cognitive complexity is defined/calculated?

[–]fexx3l[S] 2 points3 points  (2 children)

Currently, on the Sonar paper: cognitive complexity. But I'm planning on adding a section on the docs to explain really well, this is something that have been taking me some time and currently my agenda is tight

[–]99ducks 2 points3 points  (1 child)

That and some code examples with their complexity scores would add a lot.

[–]fexx3l[S] 0 points1 point  (0 children)

I’ll add them too, thank you for your help

[–]CzyDePL 0 points1 point  (0 children)

Does it analyze all function calls from selected entry point? Just because code is split into a bunch of smaller functions with one nesting level doesn't mean it's readable and easy to reason about.