[GH-ISSUE #2] some advice #2

Closed
opened 2026-02-28 14:35:46 +03:00 by kerem · 5 comments
Owner

Originally created by @marcelloh on GitHub (Oct 12, 2023).
Original GitHub issue: https://github.com/mathenz/goffy/issues/2

YTSong is just a local var, so it shouldn't have uppercase at the beginning: replace by ytSong and it works fine.
There are probably more of those :-)

With my linter I can see that there are some functions that are candidates to refactor.
(Because they are "too complex"; everything above 12 is mentioned)

To explain a bit more:
goffy/downloader.go:78:1 - dlFromTxt has complexity: 13
complexity = 1

  • 1 (found 'if' at line: 81, complexity = 2)
  • 1 (found 'if' at line: 87, complexity = 3)
  • 1 (found 'if' at line: 93, complexity = 4)
  • 1 (found 'defer' at line: 96, complexity = 5)
  • 1 (found 'has innerfunction' at line: 103, complexity = 6)
  • 1 (found 'assign with lines >= 10' at line: 103, complexity = 7)
  • 1 (found 'for' at line: 120, complexity = 8)
    • 2 (found 'go' at line: 121, complexity = 10)
  • 1 (found 'for' at line: 125, complexity = 11)
  • 1 (found 'if' at line: 131, complexity = 12)
  • 1 (found 'if' at line: 139, complexity = 13)

goffy/downloader.go:147:1 - dlTracks has complexity: 14
complexity = 1

  • 1 (found 'range' at line: 152, complexity = 2)
  • 1 (found 'for' at line: 157, complexity = 3)
  • 1 (found 'for with lines >= 10' at line: 157, complexity = 4)
  • 1 (found 'for with lines >= 25' at line: 157, complexity = 5)
    • 2 (found 'go' at line: 159, complexity = 7)
  • 1 (found 'go with lines >= 10' at line: 159, complexity = 8)
  • 1 (found 'go with lines >= 25' at line: 159, complexity = 9)
  • 1 (found 'range' at line: 194, complexity = 10)
  • 1 (found 'range with lines >= 10' at line: 194, complexity = 11)
  • 1 (found 'range with lines >= 15' at line: 194, complexity = 12)
    • 2 (found 'if' at line: 205, complexity = 13)
    • 2 (found 'if' at line: 212, complexity = 14)

goffy/youtube.go:28:1 - Match has complexity: 27
complexity = 1

  • 1 (found 'if' at line: 29, complexity = 2)
  • 1 (found 'range' at line: 40, complexity = 3)
  • 1 (found 'range with lines >= 10' at line: 40, complexity = 4)
  • 1 (found 'range with lines >= 15' at line: 40, complexity = 5)
    • 2 (found 'if' at line: 41, complexity = 6)
  • 1 (found 'else' at line: 43, complexity = 7)
    • 2 (found 'if' at line: 47, complexity = 8)
  • 1 (found 'else' at line: 51, complexity = 9)
    • 3 (found 'if' at line: 48, complexity = 11)
    • 2 (found 'if' at line: 55, complexity = 13)
  • 1 (found 'if with lines >= 10' at line: 55, complexity = 14)
  • 1 (found 'else' at line: 65, complexity = 15)
    • 3 (found 'if' at line: 56, complexity = 17)
  • 1 (found 'else' at line: 62, complexity = 18)
    + 4 (found 'if' at line: 57, complexity = 21)
  • 1 (found 'else' at line: 59, complexity = 22)
    • 2 (found 'if' at line: 71, complexity = 23)
      • 3 (found 'if' at line: 72, complexity = 25)
  • 1 (found 'logical operator' at line: 72, complexity = 26)
  • 1 (found 'else' at line: 74, complexity = 27)

6 = files
39 = functions
27 = highest complexity
4.92 = overall average complexity

Originally created by @marcelloh on GitHub (Oct 12, 2023). Original GitHub issue: https://github.com/mathenz/goffy/issues/2 YTSong is just a local var, so it shouldn't have uppercase at the beginning: replace by ytSong and it works fine. There are probably more of those :-) With my linter I can see that there are some functions that are candidates to refactor. (Because they are "too complex"; everything above 12 is mentioned) To explain a bit more: goffy/downloader.go:78:1 - dlFromTxt has complexity: 13 complexity = 1 + 1 (found 'if' at line: 81, complexity = 2) + 1 (found 'if' at line: 87, complexity = 3) + 1 (found 'if' at line: 93, complexity = 4) + 1 (found 'defer' at line: 96, complexity = 5) + 1 (found 'has innerfunction' at line: 103, complexity = 6) + 1 (found 'assign with lines >= 10' at line: 103, complexity = 7) + 1 (found 'for' at line: 120, complexity = 8) + 2 (found 'go' at line: 121, complexity = 10) + 1 (found 'for' at line: 125, complexity = 11) + 1 (found 'if' at line: 131, complexity = 12) + 1 (found 'if' at line: 139, complexity = 13) goffy/downloader.go:147:1 - dlTracks has complexity: 14 complexity = 1 + 1 (found 'range' at line: 152, complexity = 2) + 1 (found 'for' at line: 157, complexity = 3) + 1 (found 'for with lines >= 10' at line: 157, complexity = 4) + 1 (found 'for with lines >= 25' at line: 157, complexity = 5) + 2 (found 'go' at line: 159, complexity = 7) + 1 (found 'go with lines >= 10' at line: 159, complexity = 8) + 1 (found 'go with lines >= 25' at line: 159, complexity = 9) + 1 (found 'range' at line: 194, complexity = 10) + 1 (found 'range with lines >= 10' at line: 194, complexity = 11) + 1 (found 'range with lines >= 15' at line: 194, complexity = 12) + 2 (found 'if' at line: 205, complexity = 13) + 2 (found 'if' at line: 212, complexity = 14) goffy/youtube.go:28:1 - Match has complexity: 27 complexity = 1 + 1 (found 'if' at line: 29, complexity = 2) + 1 (found 'range' at line: 40, complexity = 3) + 1 (found 'range with lines >= 10' at line: 40, complexity = 4) + 1 (found 'range with lines >= 15' at line: 40, complexity = 5) + 2 (found 'if' at line: 41, complexity = 6) + 1 (found 'else' at line: 43, complexity = 7) + 2 (found 'if' at line: 47, complexity = 8) + 1 (found 'else' at line: 51, complexity = 9) + 3 (found 'if' at line: 48, complexity = 11) + 2 (found 'if' at line: 55, complexity = 13) + 1 (found 'if with lines >= 10' at line: 55, complexity = 14) + 1 (found 'else' at line: 65, complexity = 15) + 3 (found 'if' at line: 56, complexity = 17) + 1 (found 'else' at line: 62, complexity = 18) + 4 (found 'if' at line: 57, complexity = 21) + 1 (found 'else' at line: 59, complexity = 22) + 2 (found 'if' at line: 71, complexity = 23) + 3 (found 'if' at line: 72, complexity = 25) + 1 (found 'logical operator' at line: 72, complexity = 26) + 1 (found 'else' at line: 74, complexity = 27) 6 = files 39 = functions 27 = highest complexity 4.92 = overall average complexity
kerem closed this issue 2026-02-28 14:35:46 +03:00
Author
Owner

@mathenz commented on GitHub (Oct 12, 2023):

Thank you for the suggestions. I'm going to look at them in more detail.

<!-- gh-comment-id:1760137714 --> @mathenz commented on GitHub (Oct 12, 2023): Thank you for the suggestions. I'm going to look at them in more detail.
Author
Owner

@marcelloh commented on GitHub (Oct 13, 2023):

If you need some help, let me know

<!-- gh-comment-id:1760997107 --> @marcelloh commented on GitHub (Oct 13, 2023): If you need some help, let me know
Author
Owner

@mathenz commented on GitHub (Oct 19, 2023):

I improved some of the code in certain functions and methods. There were other functions that I didn't consider important enough to refactor (e.g., ToZip). I refactored the code in significant parts such as dlTracks() and Match(). Thank you for introducing me to the concept of complexity; I hadn't been considering it.

<!-- gh-comment-id:1770147240 --> @mathenz commented on GitHub (Oct 19, 2023): I improved some of the code in certain functions and methods. There were other functions that I didn't consider important enough to refactor (e.g., ToZip). I refactored the code in significant parts such as dlTracks() and Match(). Thank you for introducing me to the concept of complexity; I hadn't been considering it.
Author
Owner

@marcelloh commented on GitHub (Oct 19, 2023):

For me, running my linter against this, was a piece of cake. You did all the hard work :-)
I'm thinking about writing some stuff about it and how it can help people in writing more maintainable software.
I'll let you know.

<!-- gh-comment-id:1770163359 --> @marcelloh commented on GitHub (Oct 19, 2023): For me, running my linter against this, was a piece of cake. You did all the hard work :-) I'm thinking about writing some stuff about it and how it can help people in writing more maintainable software. I'll let you know.
Author
Owner

@marcelloh commented on GitHub (Oct 19, 2023):

https://dev.to/marcello_h/solve-code-complexity-in-go-56hg

<!-- gh-comment-id:1770332604 --> @marcelloh commented on GitHub (Oct 19, 2023): https://dev.to/marcello_h/solve-code-complexity-in-go-56hg
Sign in to join this conversation.
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/goffy#2
No description provided.