In short, it can be done, with *lots* of hiding spaces. But chances are they'll end up living at a high stress level, because anytime they see eachother the male will attempt to breed, which is a very aggressive activity for bettas. This is especially true if the fish weren't raised together. You might be able to pull it off with a brother and sister that grew up in the same community tank, but if you tried it with two random fish, chances are it'd end badly for one fish or the other.