I have a question for naming Array or List. Which one do you prefer or are you using something else?
1. -s
2. -Array, -List ( name with Type, ex. -LinkedList)
For example, let's say there's a variable which is
List<ScreenChannel>
type, then for me, -s is very short and not clear what type it is so, I prefer the second one like
val screenChannelList: List<ScreenChannel>
is this verbose?
j
Jason Robinson
05/31/2023, 3:54 AM
Personally, I choose to use -s when the type is a
List
or
ArrayList
most of the time. I don't have a very strong conviction to that though, sometimes I will add -List if I think it just sounds better aesthetically. It's basically the default collection in my mind. for less frequently used collections, like
Set
, I'll pretty much always add -Set to the end.
✅ 1
l
lazynoda
05/31/2023, 9:05 AM
Choose what's better for you and your team. One of the reasons we name things and don't use
a
or
b
is to improve readability. So just go with the most convenient convention (inception here) for the ones using the code
✅ 1
c
Chrimaeon
05/31/2023, 10:17 AM
Also keep in mind when you put the type in the name and the type changes, we’ll have a lot to refactor, that could be easily avoided with not having the type in the name.
✅ 1
j
Jason Robinson
05/31/2023, 4:25 PM
Shift+F6 makes variable renaming trivial. Plus changing the underlying type could be a pretty big deal and warrants inspection of call sites (and potentially refactoring) regardless. Readability is more important imo, and making it explicit in the name that you're dealing with a special list type can help prevent improper usage. Just my 2 cents.