Temporary account for obvious reasons, feel free to direct message me, if you'd like to discuss in further detail. I apologize for the length of the post in advance :)
Most of my experiences are filtered through the lens of working at companies in the SF Bay Area, with "a good work-life balance". This is effectively code for "we recognize that the work week is approximately 9-5 or 10-6, Monday-Friday". California has had legalized medical Marijuana for a few years, and recently legalized commercial sale of recreational Marijuana. In this comment, I'll try to offer a survey of what I've seen other people in tech doing, as well as what I myself have been doing.
By far, the most prolific and most visible mood-affecting substances are Alcohol and Caffeine. In every company where I've worked, these were freely available to employees, and consumed socially.
Caffeine feels like a major component of programmer culture. There's a plethora of boutique coffee shops peppering San Francisco, and having a discriminating coffee taste seems to be a mark of refinement. It's worth noting the popular software engineering book, Code Complete - the cover most prominently features a keyboard, and a cup of coffee - suggesting these are the essential tools of programming.
Personally, I consume coffee once or twice a day, and make a bit of conscious effort to limit my dependence, and not become too tolerant. I have a bit of difficulty keeping a regular sleep schedule and getting enough sleep, and caffeine helps counteract that.
At multiple companies I've worked at, beer was freely available, on-tap from a keg. However, it generally was not consumed during work hours, but after-hours, socially. Companies also tend to host happy hours on certain Fridays, with a variety of mixed drinks available and a party theme. Tech-related meetups are typically sponsored and hosted at a company office, and free beer is provided. Broad use of public transit, or Uber, likely resolve potential problems with drunk driving, I'm unsure on that point. I've not typically seen people drink to excess at work functions, but it's not unheard of for someone to get themselves fired at a holiday party. A taste for unique beers seems to also be a social mark of refinement.
Personally, I don't consume alcohol. This is a bit unusual, and usually raises some questions from coworkers, but the choice is generally respected and I don't experience any pressure to drink. That said, it still feels a bit alienating to have an unusual stance on drinking, and a bit alienating when there's a variety of unique mixed drinks or small-brew beers available, and only water/coke for non-alcoholic options. Non-drinkers are respected, but not considered.
I know a few people who smoke Tobacco, but it seems to be very rare. It's looked down on a bit, and there's several health laws restricting where it's permitted. Vaporizers have made it marginally more accepted. I personally don't smoke.
My impression is that many coworkers enjoy Marijuana at least occasionally, but this is far less visible. I've never noticed someone at work smelling skunky, and it seems like a substance that would completely prevent any kind of productivity at work.
I recently had my first marijuana experience, via edibles, and quite enjoyed it. It's not something I am going to make a regular habit of, but it was fairly inexpensive, and I had basically no negative effects the next day at work (except for some worse-than-usual sleep).
Purchasing marijuana was one of the most privilege-demonstrating experiences I've had. Being aware of decades of racial discrimination, of dime bags being exchanged surreptitiously, etc. With all that, I was able to walk into a well-lit store, peruse products, stand in line with several respectable-looking folks wearing tech company hoodies, present an ID, and walk out the door. That feels a little mind-boggling to me.
At a previous company, I've heard at least one employee openly talk about having tried mushrooms in the past, and recommending other people try it at least once.
Other than that, I'm generally unaware of _any_ use of any other mood-altering substances.
In terms of productivity, it seems much more typical for people to be very concerned with diet or fitness. There's quite a few vegans, vegetarians, gluten-free, etc., and many people are involved with a gym, or some outdoor activity.
My personal philosophy is that good development is a marathon, not a sprint, and properly maintaining physical and mental health is a key component of being happy and productive.
Outside of physical substances, video games are also quite popular as a recreational activity, and my use of them has, at times, bordered on addictive and life-interfering.