There's probably not a simple formula here, so I'll construct a list of traits of constructive comments:
Necessary. The problem cannot be addressed in a more appropriate way for a question and answer site; primarily asking a question or giving a better answer, but also editing, up/downvoting, voting to close, etc.
Positive. The comment is primarily about improving the post (and consequently the site).
Actionable. The comment identifies a way in which the author can improve their post.
Furthermore, making the requested change should not just result in more comments; ideally it should result in an upvote.
Informative. There should be a clear answer to: what message does this comment convey?
Referenced. The comment contains references to back up claims, either relating to Islam, or relating to this site's policies. Markup example: [the Qur'an](http://quran.com/)
Effortful. Just like for questions and answers. Take your time to say the right thing clearly; it's so easy for a comment to be misinterpreted.
Polite and wholesome. The comment is written as if the human being on the other side is sitting across from them. The comment is something the author would be willing to say to their family, friends, coworkers, etc., in person.
The online disinhibition effect is the reduction or abandonment of social restrictions and inhibitions found in normal face-to-face communication when using remote electronic communications. ...
Suler names six primary factors behind why people sometimes act radically differently on the internet from the way they do in normal face-to-face situations: 1. "You don't know me"; 2. "You can't see me"; 3. "See you later"; 4. "It's all in my head"; 5. "It's just a game"; 6. "Your rules don't apply here".
Welcoming. The comment implies that the user's contributions continue to be welcome (and does not imply the opposite).
I like to say "Welcome to Islam.SE" to new users; a habit carried over from math.SE beta. Sometimes they went on to be productive users for years.
Respectful. Write comments as if you're interacting with a scholar.
They may actually be a scholar (or may become a scholar, or may be able to answer one or two questions at a scholarly level), and unconstructive comments risk chasing them away (along with their contributions).
Bear in mind: first post = worst post. It takes time to become familiar with the site. Let's not stop users before they even get started.
Even if a post is a total schmozzle, the user's other posts might be useful, or might improve over time.
Cooperative. The comment doesn't sound like a contest, or a zero-sum game, where someone is going to "win" and someone is going to "lose". The comment reads as if they're genuinely trying to help (a "win-win" situation).
The site relies on teamwork by the community of volunteer contributors.
Detached. The comment reads as if its author is not personally invested in the response. If the author of the post disagrees, it's no biggie.
Flexible. The comment doesn't assume their stance is "correct" (or "the default") and consequently other stances are "wrong" and must be eliminated.
[If it is actually wrong, give a correct answer and let voting decide.]
Impersonal. The comment talks about the content, not the user.
I notice some users interpret questions motivated by personal matters as invitations to criticise their life in comments. This is rather off-putting.
Succinct. The comment pinpoints precisely what the commenter wants to convey, omitting that which is unnecessary. If it's long, it reads like yet another rant of some Internet troll, and may just be ignored ("ain't nobody got time for that").
Useful. Even if the author of the post dismisses a comment, it continues to be useful to other users of the site.
Unassuming. The comment doesn't make unstated assumptions about someone's beliefs.
Charitable. The comment assumes there is some respectable reasoning behind what a user writes.
...the principle of charity requires interpreting a speaker's statements to be rational and, in the case of any argument, considering its best, strongest possible interpretation.
I'm not sure how to order these traits, so they're in no particular order (at the moment). I'll try to update this (inshallah) as I see incoming constructive/non-constructive comments.
Side story (related to "polite and wholesome"): In the early MathOverflow days (before StackExchange 2.0) we were encouraged to use our real names, which I still do to this day. This makes you more accountable for what you write. Meta post:
Using real names reminds everybody that they are corresponding with real people, and it demonstrates a certain level of personal investment in your MathOverflow identity.