I knew before reading HBP that Snape killed Dumbledore at the end -- couldn't avoid the spoiler on the Internet, seems people thought it fair game after DH was published

So it didn't shock me that much.
After some reflection (particularly Snape screaming "DON'T CALL ME A COWARD!" -- note: anything Rowling writes in all-caps is probably very significant), it seemed clear to me (before reading DH) that Snape was colluding with Dumbledore, and this was an elaborate and well-orchestrated sac(rifice) by Dumbledore. I thought this quite apt, considering Rowling's affectionate usage of chess as a Hogwarts activity.
Both the readers, and the people within the book, "know" that Snape is working for both sides: as a Death Eater for Voldemort, and as a member of Hogwarts and the Order. Consequently, neither side fully trusts him. Rowling milked that theme on both sides -- Hogwarts teachers & students, Order members, and the Unbreakable Vow sequence at the start of HBP.
Now, Dumbledore saw the grand events of the Second Wizard War as a conflict between Voldemort and the "Good Guys" -- and as Dumbledore was the nominal head of the good guys, this meant Voldemort vs. Dumbledore. (In DH, we saw that this is not the first time Dumbledore has accepted that responsibility -- he did a similar thing in challenging Grindelwald.)
I credit Dumbledore with enough foresight to see that various schemes may require that he sacrifice a member of his own army. Who would Dumbledore choose for that? Of course, himself! It fits his character. It has the further benefit that it's precisely the kind of move that Voldemort would not understand, since he himself can't begin to think that way.
I misjudged some aspects of Snape's motives (obviously, because they were only fully explained using new data from DH, which I coudn't anticipate). Here's how I saw it after HBP:
a) Snape was well-known for his very strong Occlumens -- evidently stronger than even Voldemort's Legilimens. This worked both ways -- Voldemort himself "knew" that Snape's Occlumens was stronger than Dumbledore's Legilimens! Without both of those aspects, the Snape-as-double-agent theme can't work.
b) Snape has a credibility problem on both sides. The story of a spy's life!
c) Dumbledore needs Snape to rise in trust in Voldedemort's eyes. For what purpose? I assumed it was so that Snape could gain a key position, which would give him the opportunity to swing events on the scene at the climax. (I didn't anticipate the Elder Wand transfer mechanism subplot.)
d) Snape must also trump Bellatrix Lestrange's distrust.
e) In HBP itself, we follow Draco Malfoy's dilemma: he must kill Dumbledore or his family will be tortured/punished. He's terrified and screwed, and there's no way out for him. Dumbledore "saw" that, too. Dumbledore would like to save Draco! (And in the very end, we see that Draco was worth saving, after all. It wasn't too late for him.)
What single stroke can Dumbledore arrange, which achieves all that? He arranges for Snape to kill him. Dumbledore, chuckling, calls it a
pawn sac!
f) They must have discussed it further, and realized that it solves the Draco and Bellatrix problems, too: Snape can offer up an Unbreakable Vow, and further flummox Bellatrix by asking
her to be Vow-Keeper -- which flabbergasts her into a blind spot! After that, she doesn't know what to think of him -- but she surely can't believe he's a spy.
g) Dumbledore trusted Snape completely. What was there between them that could make him think so? Here, my guess was a bit off: I thought it was tied to (a). I missed the clues that Snape loved Lily Evans (admittedly, these were quite scarce before DH). Hence, I thought that the one act Snape could do to win Dumbledore's trust was to
turn off his Occlumens, and deliberately open his mind to Dumbledore's probing. Which, in fact, he does appear to do, but Rowling downplays it in DH. DH puts much more emphasis on the fact that Snape's overarching motive, and the
basis of his remorse, was his love for Lily. You have to read between the lines, but it seems clear that in one of Snape's last memories, where he and Dumbledore have just completed a session of probing Snape's mind, that they were working together at it, rather than Snape resisting.
After DH, I liked Rowling's shift of the emphasis to Snape's love for Lily, rather than a purely rational computation of concrete advantages. It fits with Dumbledore's teachings to Harry that love was the strongest magic, and greatly enhances Snape as a tragic figure. Snape chose a very lonely path, with no real thought of gaining anything he wanted from it, and a nigh-certain unhappy end, and never wavered from it. What motivates a person to go to such lengths? Nobody on Voldemort's side did that for him! Snape did it out of love and remorse -- and Voldemort proved greatly vulnerable to that avenue of attack. He never did understand how Snape undermined him!
It could be argued that Bellatrix showed Voldemort a similar kind of loyalty. But of the two, Snape had a bigger effect on the course of events. Bellatrix ultimately was just a large-caliber cannon, roughly equal to 2 or 3 other Death Eaters -- good in a melee, but not particularly useful for any other operations. In contrast, Snape shaped the battlefield -- simultaneously an early-warning radar system and Enigma code-cracker for the Order, and a control rod amidst those Death Eaters' schemes in which he directly participated.
I first saw the Order of the Phoenix movie on endless HBO replays in a hotel, and even without knowing the rest of the series, I thought Snape's role was much more interesting than any of the other teachers. I look forward to seeing him really stretch his wings in the next 3 movies.