I recently bought a Canon EF 40mm STM lens from a local seller for a damn good price. I used to own this lens and I sold it a few years back when a sold my Canon digital cameras. I regret that decision. I'm glad I was able to rectify it though. The 50mm lens was my go-to focal length for most of life.
The last couple of years I have gravitated to 35mm, and I really like it. There is something about the 40mm. It's more than the focal length. I like the fact it is a pancake lens. They're small and lightweight. A very portable lens.
Pros and cons? This is a great all around lens of you don't need to manual focus. The focus-by-wire is not very good. The autofocus is reliable and accurate, but it's slow. The lens is sharp but there is some vignetting when wide open. It has lovely bokeh, there are seven rounded blades, but it's an f2.8 lens. You can get a lot in focus at f5.6, but the f2.8 works fine if you have some distance from your subject. The f2.8 might be a little too dark for shooting indoors, grab a flash.
I think Canon wanted to market this lens to video shooters back in 2012. I've never used it for video, but I could see if you were using Canon 7d this would be a great run-and-gun kit. It's light and the AF is fantastic. Now that Canon has implemented Dual Pixel AF, this lens would work very well on cameras equipped with that technology.
This lens is really affordable, especially on the used market. Canon since released the 50mm 1:1.8 STM lens and that lens is a bit quicker and brighter. This 40mm has more character and image quality, in my opinion of course.
If you shoot Canon EOS film cameras, I don't think you could go wrong with this lens. My lens is white, I have never seen white one before. I think it stands out too much.
Who is this lens for? I think it's for people that don't care about razor thin depth-of-field, want a light and compact lens, and are on a budget. It gives you a slightly wider field of view than the 50mm, which I think is closer to the human eye's field of view. I've used this side by side with the 50mm and I prefer the 40mm.
I have never used the Canon EF 35mm 1:2 (non-USM IS version) lens, but I have seen sample images and the image quality is probably slightly nicer on the 40mm, especially in corner sharpness. The 35mm is a stop faster, and more than double the price on the used market.
The 40mm STM goes for just over $100.00 used on KEH.com. The EF 35mm 1:2 Mk I is running just $220.00 used. The EF 35mm 1:2 USM IS goes for about $470.00 used. So I think the 40mm STM wins.
In the end, this lens is a joy to use and works just fine for me. Even on my Sony A7II with a smart adapter, this lens is great.
Here's a gallery of pictures I have shot with the 40mm STM, old and new images.