Is there any "best practice" for this? Is One Way Better Than Others? Or is it just code readability and nothing more?
Simplified: In your scenario, it is useless. This is not true, but why would you do this:
ffTeacherListItem t = getItem(pos); String teacher = t.teacher; return teacher;
when you can do the same:
ffTeacherListItem t = getItem(pos); return t.teacher;
and also you can:
return getItem(pos).teacher;
All of the above does the same, but the second and third codes are cleaner, and you should always try to write clean code without useless lines and links 1 . There is also an unwritten rule - less code, fewer errors.
1 This is an βadvantageβ of languages ββsuch as C ++, which do not have a garbage collector, and you are responsible for all the objects and instances that you create (freeing them from memory, etc.). So, you think more before deciding to create a new instance of an object.
source share