Psychedelics and cannabis can help with the conceptual part of designing software, but they make it more difficult to write actual code and can make it more buggy. I find that a small amount of weed can help me focus for a couple of hours before it makes me groggy. Also, microdosing LSD - taking just enough to get the stimulating, creative, awareness-expanding, uplifting effects but not enough for the reality distortion and motor impairment - shows promising signs as a nootropic. I would recommend looking into LSD microdosing if you're really curious about how recreational drugs could be used beneficially for intellectual purposes.
I've never used LSD explicitly for problem solving, but all kinds of unique ideas come to me spontaneously, and there have been many times while tripping that I've viewed the world in an objected-oriented way for example thinking about each person as a separate implementation of an abstract Person class along with implementing interfaces for each role they perform in society as a way of conceptualizing the way unique people can all fit into predefined roles in society. Most of the realizations on psychedelics are hard to describe to others, but that's mostly because of how complex and nuanced (and many times, personal) the realizations are. It would be like trying to explain how some 100,000 line system you wrote works to someone; You understand it conceptually in your head, but putting it into words so a lay person can understand the inner workings is all but impossible.
It's not that recreational drugs help the actual act of writing code, but they can be greatly beneficial to the conceptual design process.
Then there's stimulants like adderall and (obviously) caffeine. And the fact that smoking weed after work can be an effective means of preventing burn out.
In the end, I think it mostly varies from person to person. What drugs they're used to, how their mind naturally works, what kind of work they do, what kind of effects the want, etc.