How to avoid crazy naming conventions?

Is it possible to name one assembly name, name the folder inside the assembly another, and then start transferring these names to classes inside these folders? For instance:

Project.Presenter Carriers CarriersFindPreferedCarriersPresenter.cs CarriersPreferencesPresenter.cs PreferredTargetLocationPresenter.cs Project.Service.Fixture Carriers CarriersServiceFixture.cs 

Or transfer these further, even methods such as this:

 List<PreferredTargetLocationPresenter.PreferredTargetLocation> newlyAddedPreferredLocations = new List<PreferredTargetLocationPresenter.PreferredTargetLocation>(); newlyAddedPreferredLocations.add(destinationLocation.PreferredCity); 

It seems to me that this is becoming more and more confusing as you work on the project longer and start adding additional assemblies and methods. Is there a better way to work with this?

Any feedback would be appreciated.

+4
source share
4 answers

Pragmatic Programmers popularized the DRY principle: don't repeat yourself. This also applies to naming. Reusing the same area or prefix names again and again does not add more information, it just makes the names longer, less readable, more frivolous and more difficult to find. If you have 100 class names starting with PreferredLocation* , it will be difficult for you to find the correct option: - (

Therefore, I am completely against it. The names of classes and methods are limited to nested names of paths / projects (in java, which would be package , in C # I do not know what the correct term is), so if you need all the information about the location of the class / method, just look at its full name. However, in normal code, you cannot always use the full name. The only exception is a clash of names, but I believe that this should be seen as an exception, not a rule.

In addition, in a well-developed application, most methods / classes are not displayed globally, only inside their respective package (where the programming language allows it - Java, I'm sure C # too). This reduces the risk of name conflicts and eliminates the need for class name prefixes even further.

+4
source

Ask a hundred different people this question and you will get a hundred different answers. I am a fan of any method that makes writing / maintaining code the easiest, these are long and descriptive names one and a half times, and short and clear names are the other half. As long as the code is intuitive and flexible, I don't see a problem anyway.

+4
source

Sometimes you have to use longer names, but usually you want the names to be as short as possible. The key should have descriptive names that give enough details and nothing more.

+3
source

Is PreferredTargetLocationPresenter.PreferredTargetLocation subtype of type PreferredTargetLocationPresenter ? In other words, are you nested classes?

If so, you might be better off breaking PreferredTargetLocation into your class. This allows you to write:

 List<PreferredTargetLocation> 

instead

 List<PreferredTargetLocationPresenter.PreferredTargetLocation> 

If you are working in C # 3.0, you can shorten the declaration further by using var :

 var locations = new List<PreferredTargetLocation>(); 
+2
source

Source: https://habr.com/ru/post/1300804/


All Articles