I think people are often against this as they see it as a criticism of their parenting. I know I asked the same question on here when my eldest was a baby and that she would end up eating all the sweets at parties.
We said we wouldn't give chocolate or sweets until our DC knew what it was and actively wanted it. DC1 got to three until she ever had chocolate and was about 6 before she had fizzy drinks. After that, we did chocolate as part of a meal, but avoided doing sweet treats until she was older.
Our aim was to try and set her up with the right food habits from the start and then to be much more relaxed as she got older.
We did have a problem in school when she was 6/7. DD was giving away any sweet snacks she was given and swapping them for other children's carrots. So we had to stop that.
To this day, she still loves carrots and snacks on them. She's 17 now, is not a massive sweet fan. She prefers to have a small box of hotel chocolat and she'll treat herself to one a day, rather than scoffing bars of the cheap stuff. She'll still snack on carrots, and doesn't like fizzy drinks. If we go out for a meal, she'll choose fruit juice or a J2O as her drink.
Only downside - it's much harder to do with DC2, and indeed DD2 was given sweets and chocolate much younger and fizzy drinks too. She loves all of that stuff now. Couldn't keep her away from it, unfortunately.