There is much Donald Trump might learn from a visit to the westernmost tip of the Great Wall of China – not least that if you are really determined to keep outsiders from entering your country, cow and horse excrement can be useful allies.

Local historians claim that was one of the secret weapons Ming dynasty soldiers used to repel nomadic raiders, hurling bucketfuls of manure into the desert winds to blind the barbarians as they galloped towards this sand-swept Gobi outpost.

Civilized People and Barbarians

According to some historical accounts, tribes in the north of China were militarily ahead but culturally behind, thus looting China whenever possible to steal the riches of their southern neighbors. This is one speculation as to why the Chinese opted to build the Great Wall. Another argument is that the Great Wall was nothing more than an ambitious project contrived by a vainglorious emperor. The Great Wall was supposed to show the world China’s superiority, making a clear distinction between civilized people and barbarians.

This made it a physical and psychological boundary, and although it is considered to be unique in the world, similar examples can also be found in Europe. For instance, Hadrian’s Wall in northern England served the same purpose – to divide the civilized Roman world from barbarians in Scotland. So, the wall was supposed to offer protection against barbarians from the north, and during the times of the first emperor especially against the powerful Xiongnu state. In latter stages, it also served as protection from the Mongols and the Manchus.

But Zhang Xiaodong, who runs a museum dedicated to the Chinese super-structure in the city of Jiayuguan, believes there is an even more valuable lesson the US president must grasp before he begins work on what he has dubbed the Great Wall of Trump.

“China’s Ming dynasty did all of this at its own expense, while Trump has said the Mexicans are the ones who should pay,” the historian said during a tour of the Jiayu Pass, a 14th-century fort that punctuates the western extreme of the 8,850km Ming-era wall.

Across China, from the wall’s spectacular, cliff-hugging ruins near Beijing to its wind-battered remains here in the barren north-western province of Gansu, scholars and enthusiasts have been pondering Donald Trump’s pledge – repeated this week during the president’s address to Congress – to build a “great, great wall” of his own.

What, if anything, do the two projects have in common? What might the designers of Trump’s barrier along the US-Mexico border glean from studying the history of China’s changcheng (“long wall”)? What challenges might the president face and what pitfalls might he avoid as he erects his own version of what one 19th-century adventurer called China’s “fantastic serpent of stone”?

Zhang, a 45-year-old history fanatic who has been visiting the wall since he was a year old, when his father was posted to a steel mill near Jiayuguan, said he saw striking parallels between the initiatives. One had targeted unruly nomads and the other Latin American migrants but ultimately both were designed to “protect people from outsiders,” he said.

That being so, Zhang said there were several design elements Trump might borrow from his Chinese precursors, foremost among them the gaping ditches soldiers carved into the arid soil around the Jiayu Pass, a fortress built on the orders of the Hongwu emperor in 1372.

“If Trump builds this wall, it would be best for him to dig moats and to fill them with water as well,” Zhang suggested. “That would be my advice.”

China’s legendary fortification was not created as a single wall but as a network of at least 16 distinct and unconnected barriers built over the course of more than 2,400 years to subdue unwanted outsiders. Scholars say that, by describing his frontier project as a “great wall”, the president is evoking not a marvel of engineering but a calamitous and ill-conceived folly.

First Emperor’s Toy

The Great Wall’s daunting appearance should have been enough to make possible invaders think twice about their intentions. Aside from this, there were also archers positioned all along the wall, making it more of a threat. Unfortunately, invaders often decided to simply ride around the wall. There were also large garrisons manning the wall’s larger gates, with the purpose of keeping invaders from breaking in. But again, unfortunately, during the most crucial stages of Chinese history traitors willingly opened the gates for the enemy. The Great Wall served well in the times of the first emperor, as all invaders were effectively kept out of the country. However, one might argue that it was more due to Qin Shi Huang’s great armies and their achievements on the battlefield, rather than the effectiveness of the wall. Rulers of the Han Dynasty hoped that the wall would offer them the same protection that it had for the first emperor, but this was not to be. The Xiongnu up north grew even stronger and in 200 BCE overran China, looting and plundering. The weakened Han Dynasty could not provide enough men to guard the wall, and the Xiongnu simply took control of one of the main gates and entered the land without much trouble.

“When Trump said, ‘I’m going to build a great wall,’ I thought, ‘What the hell are you talking about? You’re going to have stonemasons down there?’ I mean, it’s ridiculous,” said Arthur Waldron, a University of Pennsylvania professor who wrote one of the most detailed studies of China’s wall.

“The purpose of China’s wall was to keep out tens of thousands of guys on horseback who could ride faster than anybody, who could shoot arrows more accurately than anybody, who didn’t give a whit for all of China’s great civilization but were very happy to get grain, metals, silks and beautiful Chinese princesses and so forth and take them back out into the steppe,” said Waldron, the author of The Great Wall of China: From History to Myth.

But in practice, Waldron said, the wall had proved a catastrophic and costly failure that drained the Ming’s coffers and ultimately failed to prevent its downfall when the Manchus stormed China and established the Qing dynasty, in 1644.

“This wall was the product of imperial oppression, it cost the lives of many innocent people and also it didn’t work,” said Waldron.

He said Trump was right to claim immigration policy had become “very, very lax” and argued some action was necessary. But naming his barrier after a structure synonymous with xenophobia and isolation was a “terrible mistake” for “an extraordinary immigrant nation.” In China, where the Communist party has transformed the landmark into a potent symbol of the country’s revival, Trump’s project has found a more sympathetic audience.

“I think it is a good thing for the Americans,” enthused Zhang, who credits China’s Unesco World Heritage site with bringing peace and stability to sparsely populated strategic border regions such as the Hexi corridor, where the Jiayu Pass was built by the Ming.

Dong Yaohui, one of the founders of China’s Great Wall Society, said the meandering fortification had been an effective means of protecting residents of the empire’s often lawless fringes. Given the exorbitant cost of permanently stationing troops in such villages, how else would the central government have protected farmers whose harvests were pilfered by Mongol raiders?

Dong conceded many lives had been lost building a structure some called the longest cemetery on earth – “but the cost would have been much higher had there been no such thing as the Great Wall.” Zhang, whose museum sits at the foot of the Jiayu Pass, flanked by snow-capped mountains and rock-strewn deserts, has little time for Great Wall detractors.

A sign at the entrance to its permanent exhibition reads: “The Great Wall was a military system of defense of great magnificence … It is one of the greatest cultural and architectural miracles in the history of world civilization.”

Zhang claimed the Ming wall had allowed foreign traders, diplomats and officials to safely come and go along the Silk Road while simultaneously saving farmers from roaming bands of tribesmen who used “guerrilla tactics” to loot their properties.

However, Dong acknowledged the structure’s history also held some cautionary tales for Trump, perhaps none more urgent than that of the Jiajing emperor, who ruled from 1522 to 1567 and was known for his inflexible policies towards the steppe. Jiajing – who was notorious, according to Waldron’s research, for his deep hatred of nomads and lack of understanding of border matters – forbade all trade with outsiders and cut off their access to essential goods such as grain.

The result, noted Dong, was an almost constant state of war.

Overrun by Mongols

The Xiongnu invaded Shanxi and besieged Taiyuan, and after several skirmishes the Han emperor had to marry off his daughter to the Xiongnu ruler in order to make peace. The Chinese had to accept the Xiongnu state as an equal, and based on an agreement the Great Wall started to act as a border between the two states. After a few hundred years, the Xiongnu faded into history and the Great Wall was effective enough to keep random barbarian looters away. But when a real danger arose, the Great Wall was again nothing more than a scarecrow. Such a situation developed during the late stages of Song Dynasty. The dynasty was politically divided and in a feeble state — the same could have been said about the Great Wall. At first the land was overrun by Jurchens, who conquered the capital of Song Kaifeng and imprisoned the whole imperial family and its court. This led to the establishment of the Southern Song Dynasty, which was founded by the remains of the imperial court. At the same time, the Jin Dynasty on the northern border had to hold on against offenses from Mongols led by Genghis Khan. By this time, the Great Wall, built by hundreds of thousands of workers, had collapsed in many places. At some point, Mongols were able to find a part of the wall that they could simply ride over. Mongols overthrew the Jin Dynasty, took control of northern China and soon wiped out all other Chinese dynasties as well. By the year 1271, the Mongol Kublai Khan declared the creation of the Yuan Dynasty, which ruled with a heavy hand over the Chinese until 1368.

“Trump should understand the story of Jiajing when building the wall, and not focus solely on America’s interests,” Dong warned, arguing that flexible, semi-porous barriers were preferable to closed-off frontiers that often stoked hostilities. “Strategic moves such as the Great Wall should be regarded as a means to maintain a balance … and certainly not a way to strangle one’s opponent to death through force. It’s like when you are driving a car – it is good to transport people or goods but it is bad to simply run people over.”

Since taking office Trump has vowed to pursue the “immediate construction” of his border wall, despite suspicions that bureaucratic, budgetary and logistical hurdles mean he will end up with little more than a few hundred miles of fence. Dong was also torn. “There are two possible results from Trump building this wall: one is that it might help him to obtain his goal of maintaining order between the US and Mexico; the other is that it might fuel conflicts – just as happened in the case of the Ming dynasty.”

The Traitor’s Gate

The Great Wall was briefly revived during the Chinese Ming Dynasty, which drove out the Mongols and started thorough rebuilding of the wall so that they could never re-enter Chinese territory. The Great Wall we know today is mostly the creation of the Ming Dynasty era. It was a large-scale rebuilding project, and all too pointless. The Mongols never came back, but in truth they hardly even tried. By 1644, the Ming Dynasty was about to collapse, and at the gates of the Great Wall was a new powerful enemy – the Manchus. We will never know if this would have been the great moment for the wall to write itself into history, as the battle for China never took place. General Wu Sangui, who was in charge of protecting the country, decided to switch sides and opened the gates of the Great Wall to the invaders in the Shanhai Pass.

Tom Phillips, with additional reporting by Wang Zhen

Help deliver the independent journalism that the world needs, make a contribution of support to The Guardian.