toString() method equivalent for debugging
-
Hi,
I come back from other language country like Python and Java Island... Both of them have a toString feature , which allow debugging class.
Is there something equivalent that I didn't see before ?
As example, I want to do :MyClass car; qDebug()<<car;
-
From a design point of view it's not ugly. It's actually prettier.
For example if you have a class Triangle or APieceOfRock they have conceptually no debugging or to string conversion notion whatsoever.
Why should a triangle or a piece of rock know anything about strings or how to convert to them? Should it also convert to other data types like ACar or QWidget? Should you add a conversion method to them every time you introduce another type in your app? MakingtoSting()
method in every class is pumping in it functionality that is out of their purpose scope and does not belong to that class.A separate utility function, detached from the class is actually a much cleaner solution that keeps responsibility separation.