Re:Never Use toString() for Behaviour
by simendsjo on Wednesday December 04, 2019 @07:20AM
(#21701541)
A complete waste of time for some, and very useful for others. I don't believe comments like this is constructive for anyone.
Re:Never Use toString() for Behaviour
by kasperni on Wednesday December 04, 2019 @09:05AM
(#21702209)
Yeah, I was a bit harsh. But they already posted an announcement post about their Christmas calendar: https://news.ycombinator.com/item?id=21700759 I don't see the need to go into individual posts on top of it.
In the end, I just think there are better channels for getting started with programming in a particular language then this site.
> That was a complete waste of time.
I think that's a bit harsh. It's an article explaining simply, but effectively why you should probably not use toString(). Just because something can be summed up in a sentence does not make it a waste of time.
Re:Never Use toString() for Behaviour
by netsharc on Wednesday December 04, 2019 @07:15AM
(#21701519)
It's cool to read, but yeah, it's like reading Beginner's Java, lesson 3.
Re:Never Use toString() for Behaviour
by simendsjo on Wednesday December 04, 2019 @07:24AM
(#21701565)
More like "beginning software architecture". While this is "common knowledge" after coding for years, it's actually hard-earned, battle-scarred knowledge. Sharing experience on how to design software is very useful for all the people just starting out.
To sum it up: don't rely on the format of a generic toString() method. Prefer country.getName() over country.toString(), even if toString() returns getName().