Imagine you’re African-American and working at a 500-person technology company where everyone else is white, and one day the CEO declares in a national newspaper interview that his company’s lack of diversity isn’t an accident. In fact he prefers to hire white people because when it comes to technology white people simply make better employees.

That statement would be unthinkable. But what if a tech CEO made the same comment about age?

In 2013, I went to work at a software company called HubSpot. I was 52 years old. The average HubSpot employee was 26. Everyone seemed to be right out of college. The place was like a frat house, with refrigerators stocked with cases of beer and telemarketing sales “bros” drinking at their desks while hammering away on the phones. Thirty-something employees were considered “old people.”

About nine months after I joined, HubSpot’s CEO and co-founder, Brian Halligan, explained to the New York Times that this age imbalance was not something he wanted to remedy, but in fact something he had actively cultivated. HubSpot was “trying to build a culture specifically to attract and retain Gen Y’ers,” because, “in the tech world, gray hair and experience are really overrated,” Halligan said.

I gasped when I read that. Could anyone really believe this? Even if you did believe this, what CEO would be foolish enough to say it out loud? It was akin to claiming that you prefer to hire Christians, or heterosexuals, or white people. I assumed an uproar would follow. As it turned out, nobody at HubSpot saw this as a problem. Halligan didn’t apologize for his comments or try to walk them back.

The lesson I learned is that when it comes to race and gender bias, the people running Silicon Valley at least pay lip service to wanting to do better — but with age discrimination they don’t even bother to lie.

Making hiring and firing decisions based on age is illegal, but age discrimination is rampant in the tech industry, and everyone knows it, and everyone seems to accept it. What other industry operates like this? What would the world be like if doctors, lawyers, or airline pilots — or anyone, really, other than professional athletes — had to accept the idea that their career would end at age 40, or 50?

One excuse for pushing out older workers is that technology changes so fast that older people simply can’t keep up. Veteran coders don’t know the latest programming languages, but young ones do. This is bunk. There’s no reason why a 50-year-old engineer can’t learn a new programming language. And frankly, most coding work isn’t rocket science.

What’s more, most jobs in tech companies don’t actually involve technology. During my time at HubSpot fewer than 100 of the company’s 500 employees were software developers. The vast majority worked in marketing, sales, and customer support. Those jobs don’t require any special degree or extensive training. Anyone, at any age, could do them.

Also, over time, most people get better at what they do. They become wiser, calmer, more self-aware. They’ve also put in the 10,000 hours of practice that Malcolm Gladwell says are required to become expert in a skill. Why would companies not want employees who have gained that expertise? In the past few years, in addition to being a journalist and a novelist, I’ve also started writing for TV, on HBO’s “Silicon Valley.” The 55-year-old version of me creates a much wider range of material than the 35-year-old version did, and at a higher level.

A nap room at HubSpot. (Photo: David L. Ryan/Boston Globe via Getty)

People born after 1980 do not possess some special gene that the rest of us lack. But Silicon Valley venture capitalists and founders somehow seem to believe this is the case. I suspect the truth is that tech startups prefer young workers because they will work longer hours and can be paid less.

Twenty years ago, when venture capitalists invested in young founders, they usually insisted that founders team up with older, seasoned executives to provide “adult supervision.” Lately the conventional wisdom has been that it’s better to let young founders go it alone. The consequences have been predictably disastrous. Young male founders hire young male employees, and spend huge money building kooky office frat houses.

In the tech industry the practice of bros hiring bros is known as “culture fit,” and it’s presented as a good thing. The problem with “culture fit” is that unless you’re a twenty-something white person, you don’t fit. People of a certain age, people of color, and women — most of us, in other words — are often unwelcome. This huge, dynamic industry, which is generating so much wealth, has walled itself off from most of the workforce, telling millions of people that they cannot participate. This situation obviously shortchanges a lot of workers, but it also hurts tech companies by depriving them of talent.

Age bias goes hand-in-hand with other forms of bias. HubSpot had many female employees, but few in top management positions. The company was run (and still is) mostly by white men. As far as I could tell, there were no African-American employees. Once, after sitting through a company all-hands meeting and being stunned by the ocean of white faces, I wrote to a woman in HR asking if the company had any statistics on diversity. HubSpot prided itself on possessing numbers for everything, and being a “data-driven organization.” I received a terse reply: “No. Why?”

I spent three decades in newsrooms, working alongside colleagues of all ages, from recent college graduates to people in their sixties and seventies. At Forbes I wrote for an editor who was 78 years old. At Newsweek I reported to an editor-in-chief who was nine years younger than I was. Age was never an issue. The companies I worked for weren’t perfect, but they had a wider range of talent and were better managed than most tech startups. They also didn’t have the kind of frat-house culture that has become common in Silicon Valley, and the lack of oversight and corporate control that come with it.

I lasted 20 months at HubSpot. My time there was filled with incidents in which colleagues demonstrated they shared Halligan’s low regard for older workers. After I left the company, I announced I was writing a memoir about my experience as a 50-something guy trying to work in startup land. Apparently some of the company’s executives freaked out about what might be in the book, and they did something so crazy that I still almost can't believe it.

According to the FBI, which investigated, these executives tried to hack into computers to steal the manuscript, and also tried to prevent publication of the book by engaging in extortion. No criminal charges have been filed, but the hacking, extortion, and ensuing cover-up raised questions about HubSpot’s culture and the trustworthiness of its leadership. HubSpot's board fired the CMO, and sanctioned Halligan, the CEO. A vice president resigned before the board could decide whether to terminate him. The board still won't tell me what happened.

It occurs to me that the fiasco might not have occurred if HubSpot were run by more mature people — people with the “gray hair and experience” that Halligan derided. Embracing diversity isn’t just a nice thing to do; it’s also smart business.

Dan Lyons is the author of the new book, "Disrupted: My Misadventure in the Startup Bubble," on sale now from Hachette.