Don't mix condos/town homes and single family homes. They are completely different. Condos/town homes by their nature have more need for rules and governance.
As to whether or not to buy in a HOA, it's a very personal preference. If you care how the appearance of your neighbor's home affects your home value and in general your mood about where you live, then only the HOA community gives you any real chance to get some level of upkeep/nice looking properties enforced.
Yes, there are city codes that govern non-HOA communities and this may help with junk cars in the yard, etc, but it won't help with general appearance standards like not having peeling paint, broken shutters, wild colors, weedy yards, rusted chain link fence, etc. If those things don't bother you, then non-HOA is OK for you. If they do bother you, then consider a HOA.
Does a HOA prevent all those problems? Of course not. The HOA is run by volunteers and each will have it's own level of governance. But at least the rules are there and you have the opportunity to get involved yourself to make it better. You won't have that in the non-HOA community.
The HOA community may also offer amenities that non-HOA communities won't, like private green areas/parks, private walking trails, tennis, pools, club house, etc. If you want those things, then they likely require a HOA to have them.
Also, don't be discouraged by the problems you read about here. People come here to solve problems so when you read the site you see mostly......problems
That doesn't mean HOAs are full of issues and you should avoid them.
Again, it's just your personal preference of the kind of community you want.