I was a casual pot smoker decades ago. I tried, several times, to write code while stoned. Invariably, I regretted it in the next day. It was like looking at someone else's code and realizing that the other person really doesn't understand programming at all.
The problem (devil?), I think, was in the details. You get some terrific ideas when you're stoned. (Also some terrible ideas, but we'll stay positive for now.) Broad, general, sweeping ideas about how to do something in the most elegant manner imaginable. Better than anything that's come before. Then you sit down and actually try to write the stuff and realize that the compiler is extremely, extremely picky about everything. You also realize that you can only hold about two things in your head at a time, which makes handling complex data structures or algorithms really challenging. It's like trying to drive a cheap RC car from one point to another, where all you can do is go forward in a straight line and turn right in reverse. You can get there, but the route is torturous. Going from a broad idea to the details of writing code is not well accomplished while stoned. You have to hold too many things in your head simultaneously.
Bottom line, I discovered that it was a lot better doing other stuff stoned than write software. Programming with a perfectly clear head is way more satisfying in the long run. Of course, all this was a very long time ago. Maybe if I returned to smoking now I would think differently.