“Why do you think it was him?” Mary asked.
“Why do you think it was him?” asked Mary.
Since both options are common in books, I’m sure they both are perfectly correct in terms of grammar. But is there any difference in undertone or something? Or the two options don’t differ from each other at all, and it’s just a matter of preference of the author?