C
C#11mo ago
Pibbles

❔ File naming convention preference

In VS, the I have a folder for ReadModels and another for WriteModels. I then have a file in each for User. Would you name this file User.cs or ReadUserModel.cs (/Write). User.cs is simpler and nicer, but then the VS tabs for your files all just say User.cs, and I have to click in to know what actual file that is. So which way do you go? I know I can also get an extension to change this header name, let me know if you do that too
11 Replies
mtreit
mtreit11mo ago
You can't share the User type?
Pibbles
Pibbles11mo ago
I'm not sure what you mean?
mtreit
mtreit11mo ago
What's in User.cs? Why do you need two of them?
Pibbles
Pibbles11mo ago
oh that was really just an example the point is you have a file with the same name, but in 2 completely different folders
mtreit
mtreit11mo ago
I generally don't care if the files have the same name but if it really bothers you then sure, name them something distinct. I don't think there is a common existing convention for this.
Pibbles
Pibbles11mo ago
fair enough then thanks
JakenVeina
JakenVeina11mo ago
general rule of thumb for C# is "file name matches class name" what I'd ACTUALLY do for this setup, personally, would probably be....
Library/
Users/
ViewModel
MutationModel
Library/
Users/
ViewModel
MutationModel
or something very similar
Coehl
Coehl11mo ago
I usually establish one as what should be considered the User. Then just further define the other. For example, mvvm? There's a User and UserViewModel. User gets passed around for business logic easily and usually gets turned into UserViewModel before hitting the UI. Same for a rest API. There's a main User that usually correlates to what gets saved in the database and maybe it's even what you get in a GET. Then I might have CreateUser, UpdateUser, etc for the other endpoints. All of these might share some interfaces too like IUser and ICreatable or something Just my .02
JakenVeina
JakenVeina11mo ago
sounds like DDD
Coehl
Coehl11mo ago
Hm. I've never studied it but I may be influenced by proxy
Accord
Accord11mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.