Suppose you have a table widget class.
Do you do table.row(i).column(0).setText(students[i].surname())
or table[0][i] = students[i].surname()
the latter makes way less sense but the simplicity is so luring 😉
ditto for: table.row(0).column(0).setBackground(red)
vs: table[0][0].setBackground(red)
Note that Table::row returns a Table::Row, whose column function returns a Table::Cell, and Table::Cell provides either setText or op= (as well as setBackground).
Same for Table::op[] and Table::Row::op[].
Your thoughts?
The solution with
Table::row()andTable::Row::column()methods is a bit more readable (in general) and allows you to unambiguously create aTable::column()method,Table::Column(proxy) class, andTable::Column::row()method later on, if that is ever needed. This solution also makes it easy to find all places where rows/columns are accessed, which is much harder when you use operator overloading.As others pointed out however, the second solution is less typing and, in my opinion, not much worse in readability. (May even be more readable in certain situations.)
It’s up to you to decide though, I’m just giving some implications of both solutions 🙂