How To Write Clean Code With The Help Of Static Code Analysis

แชร์
ฝัง
  • เผยแพร่เมื่อ 16 ก.ย. 2024

ความคิดเห็น • 64

  • @MilanJovanovicTech
    @MilanJovanovicTech  ปีที่แล้ว +4

    Want to master Clean Architecture? Go here: bit.ly/3PupkOJ
    Want to unlock Modular Monoliths? Go here: bit.ly/3SXlzSt

  • @nandkishorsonwale
    @nandkishorsonwale ปีที่แล้ว +4

    Short but sweet information about Clean Code. Thank you.

  • @danielegiovanetti9258
    @danielegiovanetti9258 ปีที่แล้ว +8

    I didn't know about these nuget packages. Thanks Milan for sharing this topic. Writing and mantein clean code is very important and these helps are very important.

    • @MilanJovanovicTech
      @MilanJovanovicTech  ปีที่แล้ว +1

      This is super helpful in large teams to maintain code quality

  • @codewithguillaume
    @codewithguillaume ปีที่แล้ว +3

    I am currently writing an article on Clean Code and I guess this video will help me! I’ll mention you ;)

    • @MilanJovanovicTech
      @MilanJovanovicTech  ปีที่แล้ว

      Just spread the good word about static code analysis, and I'll be more than happy 😁

  • @avecesar
    @avecesar ปีที่แล้ว +3

    Thank you!!... Your videos has been a great source of knowledge, quality, discovering and goodness.

  • @MarcusKaseder
    @MarcusKaseder ปีที่แล้ว +5

    Very good topic! I usually provide the analyzers with its own .editorconfig. It's a bit tricky but it enforces all rules and allows rule updates via a own nuget package.
    The nuget provides its own *.props file on build. In that case, developers are not able to suppress errors they don't like because the .editorconfig is overridden on each build 😁 And they can't uninstall the analyzer nuget packages.
    Also, it's useful to have different analyzer rules for test projects.
    In normal projects its for example not allows to use "magic strings" but in test projects you're allowed to.
    That nuget approach is very useful on distributed systems where you usually have a lot small solutions with n projects.
    If someone is interested in that solution, just ask 🙂

    • @MilanJovanovicTech
      @MilanJovanovicTech  ปีที่แล้ว +2

      I think you can just place an .editorconfig under the /tests folder, and that should solve it. You have a great point there Marcus!

    • @MarcusKaseder
      @MarcusKaseder ปีที่แล้ว

      @@MilanJovanovicTech Thanks and yes, that would work 🙂

    • @kenank7053
      @kenank7053 ปีที่แล้ว

      Could you somehow share your solution

    • @MarcusKaseder
      @MarcusKaseder ปีที่แล้ว +1

      @@kenank7053 Sure, I'll prepare something on Tuesday.

    • @NextProgrammer
      @NextProgrammer ปีที่แล้ว

      @@MarcusKaseder can you please share it too? thank you

  • @kudesnikreal
    @kudesnikreal ปีที่แล้ว +1

    This is a good introduction, thank you. I would only try to mention one more thing in such introduction. With .editorconfig it is possible to change the severity level of a rule. But it is also possible to configure the rule's internals, for example for the rule that checks line lengths, it is possible to configure the maximum allowed length, or for the rule that checks nestings - maximum nesting level and so on. A different way is needed to provide such configuration, specific to each nuget package, but usually, it is something similar to an XML file with a predefined name.

    • @MilanJovanovicTech
      @MilanJovanovicTech  ปีที่แล้ว

      Have any documentation source for that?

    • @kudesnikreal
      @kudesnikreal ปีที่แล้ว

      @@MilanJovanovicTech There is some documentation in StyleCop and Sonar analyzers projects, but it looks like I can't provide those links, comments just get deleted.

  • @mesutdemirci7933
    @mesutdemirci7933 ปีที่แล้ว +1

    Thanks for the video ,good work milan

  • @hamadsalahud-din3617
    @hamadsalahud-din3617 ปีที่แล้ว +1

    Great video with full of the info

  • @subashbarik
    @subashbarik ปีที่แล้ว +1

    Thanks for the video ,really helpful.

  • @E_G_
    @E_G_ ปีที่แล้ว +3

    New video, new things to learn :)

  • @com0oan
    @com0oan 2 หลายเดือนก่อน

    amazing video!

  • @JoeMeyer8998
    @JoeMeyer8998 ปีที่แล้ว +1

    That was interesting!

    • @MilanJovanovicTech
      @MilanJovanovicTech  ปีที่แล้ว

      Thank you, hopefully you can add it to your project 😁

  • @Nashmar
    @Nashmar ปีที่แล้ว +2

    Hey. Very interesting topic with short helpful introduction into the topic ! Just a question. Are you using both static analyzers (StyleCop SonarAnalyzer) at the same time or they have same features and using just one of them should be enough ?

    • @MilanJovanovicTech
      @MilanJovanovicTech  ปีที่แล้ว +1

      I'm using both. They have some overlap surely, but they complement each other also

  • @user-up5wg7pc9m
    @user-up5wg7pc9m 6 หลายเดือนก่อน +1

    Very helpful video, thank you. I am having a problem in my project where I need to disable all analyzers in a specific project directory. I tried to suppress it in the .editorconfig file, but the rest of the rules are more specific, therefore it overwrites the suppression. How could I suppress those directories?

    • @MilanJovanovicTech
      @MilanJovanovicTech  6 หลายเดือนก่อน

      You can have .editorconfig in each directory

  • @angelldark6426
    @angelldark6426 ปีที่แล้ว +1

    interesting, cool, but it's definitely not for a student, thanks, I went to finish my second project.) I fell into the trap when I watched your lessons, and I'm still figuring out the Rusult class. I liked him very much.

    • @MilanJovanovicTech
      @MilanJovanovicTech  ปีที่แล้ว

      There's a nice library here: github.com/altmann/FluentResults

    • @angelldark6426
      @angelldark6426 ปีที่แล้ว

      @@MilanJovanovicTech OMG thanks 🙏

  • @nove1398
    @nove1398 ปีที่แล้ว +1

    Great!

  • @calwayNL
    @calwayNL ปีที่แล้ว +1

    @Milan I also see CS1591 lines in my .editorconfig. These are Compiler warning that are configurable. Should these also be moved down.
    VS just plops those lines somewhere it looks. But some seem to be inside a [*.cs] selector, so they would only apply to *.cs files I think. In my case I think they are now in a [*.{cs,vb}] section so still apply to *.cs but do you know whether this is true, Ie. There position is important if you also have other extension sections in your .editorconfig ?

  • @microtech2448
    @microtech2448 ปีที่แล้ว +1

    Thanks for the video. When you say a solution can contain up to 100 projects or even more. Can you please let us know how we can configure multiple projects on different repositories under the same solution. So the solution should be within the repo having few projects in the same repo but other projects can go in different repo.

    • @MilanJovanovicTech
      @MilanJovanovicTech  ปีที่แล้ว

      Well that doesn't make much sense from a code sharing perspective... How do you see that working?

  • @michalzemek
    @michalzemek ปีที่แล้ว +1

    Thanks for the Video, I have one question, How to get Directory.Build.Props to other projects that are in separate GIT repositories ?

    • @MilanJovanovicTech
      @MilanJovanovicTech  ปีที่แล้ว

      You'll have to copy that file into the other repository 🤷‍♂️

  • @ramiamara644
    @ramiamara644 6 หลายเดือนก่อน

    Hello, and thank you for this video, i have a question: why in Repository with Update and Add functions you don't use async

    • @MilanJovanovicTech
      @MilanJovanovicTech  6 หลายเดือนก่อน

      I don't need to make them async. So why pay the price of having an async method?

  • @MarusykRoman
    @MarusykRoman ปีที่แล้ว +1

    what is your recommendation about configuring PrivateAssets and IncludeAssets?

  • @sechabamotaung8552
    @sechabamotaung8552 ปีที่แล้ว +1

    This was very cool. Thank you. Question though if for instance you did not want other developers to be able to change the severity of the rule from the nuget package?
    Do you have a way?

    • @MilanJovanovicTech
      @MilanJovanovicTech  ปีที่แล้ว +1

      Code reviews? 😅
      Nothing else comes to mind

    • @MiningForPies
      @MiningForPies 6 หลายเดือนก่อน

      In your CI build pipeline you can pull in an editor configuration file from a secure place that will break the build.

  • @tryagain6148
    @tryagain6148 ปีที่แล้ว +1

    All good until you mentioned the StyleCop - a real nightmare, same as his predecessor (fxCop). I prefer using SonarQube rules (via SonarLint) for sanity, .editorconfig for enforcing behavior, and the "old" roslyn analyzer.
    Also I prefer shipping the .editorconfig file via a NuGet package, with a custom task in the CI pipeline that's validating the the package presence. What's nice about this approach is the fact that you do not depend of a specific path, but you can opt to deliver it via the organization projects, and you can achieve the same with other package managers as well - maven, npm, others.

    • @MilanJovanovicTech
      @MilanJovanovicTech  ปีที่แล้ว

      It's all configurable via .editorconfig, so I don't see much problems with it.

  • @ahmadyamout6867
    @ahmadyamout6867 ปีที่แล้ว +1

    Dear can you make like a very small project from a to z using these tools to write a clean code . So for the newbies like me can understand clearly . Thank you

  • @nigelclark3997
    @nigelclark3997 9 หลายเดือนก่อน +1

    Been looking into throwing static code analysis into Git when making pull requests, to assert clean code only gets merged. Been looking at it lightly, but come across random issues. Have you looked into this?

    • @MilanJovanovicTech
      @MilanJovanovicTech  9 หลายเดือนก่อน +1

      Add it as part of your CI: th-cam.com/video/58mt3A2MNdg/w-d-xo.html

    • @MilanJovanovicTech
      @MilanJovanovicTech  9 หลายเดือนก่อน +1

      Version where you can copy the YAML: www.milanjovanovic.tech/blog/how-to-build-ci-cd-pipeline-with-github-actions-and-dotnet

    • @nigelclark3997
      @nigelclark3997 9 หลายเดือนก่อน

      How will this work remotely? Doesn't the csproj reference a bunch of Unity dlls that exist in the Editor Hub. From what I see Unity doesn't output relative path references for anything like that?@@MilanJovanovicTech

  • @danhkevo5292
    @danhkevo5292 9 หลายเดือนก่อน

    wtf ads