Posting comments that don't offer any value simply for the badge definitely isn't a good idea (and I'm sure you're not too surprised by that!).
Although the system has no way to tell whether your comment is constructive or spam, you would hypothetically be awarded the badge... but once other users notice comments like that, it's likely that they'd be flagged and deleted. Continued abuse of the system to gain badges could lead to you receiving messages from the site's moderators, or more serious action taken.
Beyond trivial badges, most require some verification and vetting from your peers (other users) in the form of votes. Creating low-quality posts just to get the badge won't work either — badges such as Curious (ask 5 questions) also specify that you must maintain a positive question record (the specifics aren't important here, but I can tell you that this would exclude posts that were voted down, deleted, etc).
Essentially: if you're just doing it for the badge, you probably shouldn't be doing it, and the system will prevent you from getting badges you shouldn't be getting. And regarding reputation: this can only be gained through actions that are vetted by other people. You only gain rep when you're upvoted, or suggest an edit and have it approved. It's difficult to game the system!
On Stack Exchange, we take great care to make sure the site maintains high quality content. I sincerely hope that you can help us to do that, and share your knowledge where you can. Posting unnecessary comments gets in the way of that — have you ever Googled something, and struggled to find the answer buried in a lot of discussion? That's what we're trying to solve here.
A few days of participation on the site should quickly allow you to write a few useful comments (and, by the way, take a read of what we use comments for here — in a nutshell, they're only for asking for clarification or suggesting a way of improving a post, e.g. if there's an error — very dissimilar to other sites that have comments, so it can be a little confusing at first). Good luck.