Is American manufacturing in free fall, as Mr. Sanders and Mr. Trump assert? Figures from the Federal Reserve Bank of St. Louis show industrial output a tad below an all-time record level, while nearly double the output of the Reagan presidency, another supposed golden age. It’s just that advancing technology allows more manufacturing with fewer workers — a change unrelated to foreign competition.

Manufacturing jobs described by Mr. Trump and Mr. Sanders as “lost” to China cannot be found there, or anywhere. As Charles Kenny of the nonpartisan Center for Global Development has shown, technology is causing factory-floor employment to diminish worldwide, even as loading docks hum with activity. This transition is jarring to say the least — but it was always inevitable. The evolution of the heavy-manufacturing sector away from workers and toward machines will not stop, even if international trade is cut off completely.

A century ago, most Americans worked in agriculture: Today hardly any do, and we’re all better off, including farmers. That manual labor, farm or factory, has given way to 60 percent of Americans employed in white-collar circumstances is the important story in the long term. But nothing is achieved by moaning about the past. The challenge is to create even more white-collar opportunities.

Though candidates on the right are full of fire and brimstone this year, the trend away from optimism is most pronounced among liberals. A century ago Progressives were the optimists, believing society could be improved, while conservatism saw the end-times approaching. Today progressive thought embraces Judgment Day, too. Climate change, inequality and racial tension are viewed not as the next round of problems to be solved, but as proof that the United States is horrible.

And yet developing the postindustrial economy — while addressing issues such as inequality, greenhouse emissions and the condition of public schools — will require optimism. Pessimists think in terms of rear-guard actions to turn back the clock. Optimists understand that where the nation has faults, it’s time to roll up our sleeves and get to work.

That’s why the lack of progressive optimism is so keenly felt. In recent decades, progressives drank too deeply of instant-doomsday claims. If their predictions had come true, today petroleum would be exhausted, huge numbers of major animal species would be extinct, crop failures would be causing mass starvation, developing-world poverty would be getting worse instead of declining fast. (In 1990, 37 percent of humanity lived in what the World Bank defines as extreme poverty; today it’s 10 percent.)

The lack of optimism in contemporary liberal and centrist thinking opens the door to Trump-style demagogy, since if the country really is going to hell, we do indeed need walls. And because optimism has lost its standing in American public opinion, past reforms — among them environmental protection, anti-discrimination initiatives, income security for seniors, auto and aviation safety, interconnected global economics, improved policing and yes, Obamacare — don’t get credit for the good they have accomplished.