Both are good. There's a ton of threads on this.
Get the m50 if you want more bass and a headphone that's slightly less detailed, but has a more comfortable fit. I don't find it all that neutral, but it's still pretty good. This would actually be better for longer listening sessions over the SRH-840. Soundstage is pretty poor even for a closed headphone. Vocals are so-so, but I wish they were a bit more forward.
Get the SRH-840 if you want a more neutral headphone with a lot of detail, but nothing excessive. The highs can be fatiguing for me at about the 2 hour mark. These are huge and don't fit that well on my head, so I had to sell them and downgrade the overall sound quality a tad and get something I could actually wear comfortably (M50). Possibly the best headphone in the world for "Imogen Heap".
I'd only suggest getting the SRH-840s if you can find them under $150. They are not worth $200 to me. Even for $150, that's a bit high. These would be a good deal for $130.
BTW the bass on SRH-840 is good enough for me, just check the charts and you can see that it definitely has a lot of bass, but some people may still find it disappointing.
If you want even more bass (then even the M50) get the Shure SRH-750DJ. I hated these headphones though, but a lot of people prefer them over the 840s.
None of these had my perfect sound signature, but both are very good and you can't go wrong with either of them.