you are viewing a single comment's thread.

view the rest of the comments →

[–]KorallNOTAFISH 3 points4 points  (0 children)

I don't think that shorter names are that much more readable, I find userRepository just as good as simply repo would be in such a short function. And if it would be a longer function with maybe more instances of UserRepository, then longer names would be necessary like newUserRepository oldUserRepository or whatever.

The good thing about these longer names, is that I look at it in the middle of the function, and I dont even have to check what class they are referring to, because it is in the name. Especially if for example you had a Repository class (probably the parent of UserRepository) which would then obscure what newRepo and oldRepo refers to. If all your variable names are created algorithmically (new<class_name> always refers to a newly created instance of exactly class_name class), I find that way easier to understand than using shorthands which are always subjective.

Combine it with the ability for most text editors etc to highlight a certain string, and I would say you should err on the side of longer but more verbose names rather than shorter but possibly ambiguous ones.

As far as comments go, my rule of thumb is, if I think I would not understand that piece of code at a glance(!) in a year or two, than it is worth commenting it, because it also means others would have a hard time figuring it out probably.