Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

Should namespaces start with Assets. ?

Discussion in 'Scripting' started by MapuHoB, Oct 11, 2015.

  1. MapuHoB

    MapuHoB

    Joined:
    Aug 17, 2014
    Posts:
    50
    I am using ReSharper which has a pretty awesome feature to auto arrange my namespaces with just a few clicks. The thing is that every time it does that, let's say we have a script in Scripts/MyMonoBehaviour.cs, and now ReSharper says that the corresponding namespace to this file is Assets.Scripts, while I consider it to be simply Scripts.

    Which is the correct namespace?

    1) Scripts
    2) Assets.Scripts

    If 1) is the correct one, then how can I tell ReSharper to exclude the Assets from the potential namespace refactoring?
     
  2. Timelog

    Timelog

    Joined:
    Nov 22, 2014
    Posts:
    528
    There is no "correct" namespace. Namespaces are purely for organization of scripts, and thus can, and should be, named in a way so you can easily keep your scripts organized. The default behavior in Visual Studio for namespace naming is to use "Assembly > (sub)folder names". This "default namespace" can be changed however using the following steps:
    Code (csharp):
    1. -> Project
    2. -> Properties
    3. -> Default Namespace
    Having said that, personally I just use what gets generated by default, which is Assets.Scripts.Whatever.Structure.I.Use and I can imagine most do.
     
    code-blep and Kiwasi like this.
  3. MapuHoB

    MapuHoB

    Joined:
    Aug 17, 2014
    Posts:
    50
    @Timelog thank you for the quick response! I'm sorry for the inaccurate word that I used, a better one would be "the most common one" instead of correct, sorry again about that. Anyway for my last few projects I've been using ReSharper's default suggestion as well which is Assets.etc.

    For example (idk if you are using GPG Plugin for Unity) which namesaces omit the Assets. part should I let ReSharper adjust all the namespaces in their classes there to fit the Asset. pattern? Here I'm talking just what would be a good practice.

    Thanks! :))))
     
  4. MapuHoB

    MapuHoB

    Joined:
    Aug 17, 2014
    Posts:
    50
    I found another way to omit the Assets folder though.

    Cheers and thanks again! :))))
     
  5. Timelog

    Timelog

    Joined:
    Nov 22, 2014
    Posts:
    528
    No, because imo you then step into a very dangerous rabbit hole. While adjusting namespaces should not harm the package in any way, there are most likely more patterns and practices used in that package that ReSharper doesn't like, some of which will break the package if auto changed making you have to fix them manually costing you a lot of time. I would just keep the package as is, and use your patterns and practices only in your code.
     
    Kiwasi likes this.
  6. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    Going one step further, think about maintaining the assets in the future. Each time the publisher pushes an update you'll have to go through this process again.
     
    Timelog likes this.
  7. MapuHoB

    MapuHoB

    Joined:
    Aug 17, 2014
    Posts:
    50
    Thank you guys :)))) Really appreciate your time spent on helping me out here :)))