Image copyright AFP

Terrorism, like Europe, is an issue that has dominated British politics for decades. I woke up on Friday morning expecting to hear the seismic fallout from Brexit monopolising the headlines yet again. I was shocked when I heard the latest news from Nice - that so many men, women and children had been horrifically mowed down by a terrorist driving a lorry.

I was shocked but not surprised, given that the so-called Islamic State has encouraged such attacks by individuals, who don't need a bomb or a gun to carry out slaughter on such a scale. Here in the UK the killers of Fusilier Lee Rigby heeded the same call using a knife. The difference is that one of Lee Rigby's attackers was on MI5's radar while the Nice lorry driver was not on France's equivalent - its "S" list of suspects.

Mass casualty attacks, as France, Belgium and the UK know only too well, are the perpetual nightmare that governments fear - a nightmare that becomes all too real when intelligence fails to detect them.

Since the London bombings of a decade ago, Britain has managed to avoid such a mass attack. But statistics show it has been a close-run thing. Forty terrorist plots have been disrupted since 2005 - including seven in the past 18 months.

Reporting on terrorism and political violence as I have done for more than 40 years has few silver linings. "Don't you ever get depressed?" is a question I'm often asked. The honest answer is "yes" - and Nice only underlines it - however, I still try to make sense of what invariably seems senseless. But there is some good news, although I hate to tempt fate by saying so.

Image copyright AFP Image caption French police search the lorry driven by the Nice killer

It's no accident that this country has not yet endured a Paris, Brussels or Nice. Britain's defences against terrorist attack depend not just on the watery buffer of the English Channel and our non-membership of Schengen - Europe's border-free area. Crucially they also rely on the way in which intelligence is now intimately shared between all the agencies: the Security Service (MI5), MI6, GCHQ - and the police. This is the key to keeping Britain safe - although it's by no means guaranteed.

In stark contrast, the situation across the Channel is very different. France has six intelligence agencies - and they're decidedly not joined up, as the failures to detect the Paris attacks in January and November last year clearly illustrate. As I discovered when I investigated the November attacks, there was a fatal lack of communication and co-ordination both before and during those attacks. As a result, this month's French Parliamentary inquiry recommends the establishment of a single overarching agency to improve intelligence sharing - similar to America's National Counterterrorism Center (NCTC), or the UK's Joint Terrorism Assessment Centre (JTAC). The inquiry concludes: "The multi-layered, cumbersome intelligence apparatus was like an army of soldiers wearing lead boots."

From Our Home Correspondent

Peter Taylor's report features on this week's From Our Home Correspondent, broadcast on Radio 4 at 13:30 on Sunday 17 July. He also be discussing the Nice attacks on Sunday Morning Live at 10:00 on BBC One.

But effective intelligence-sharing in the UK didn't happen overnight - as the history of combating Irish and Islamist terrorism shows. In many years of covering the conflict in Northern Ireland, I lost count of the number of times I was assured that intelligence-sharing had never been closer and the IRA was on the run. Both were fictions. In the mid-1970s, I remember one Northern Ireland Secretary, Roy Mason, boasting that he would squeeze out the IRA like a tube of toothpaste. Martin McGuinness and some of his former IRA comrades now at Stormont bear testimony to the fiction.

In the aftermath of 9/11, I was still hearing that intelligence-sharing between the police and MI5 had never been closer - but it wasn't. Take this example.

Early in 2004, MI5 surveillance officers were monitoring a cell that was plotting to attack targets in London and the south-east of England. They followed suspects on the fringes of their investigation nearly 200 miles up the M1 to West Yorkshire - and noted the addresses in the Leeds area where they ended up.

To my great surprise, I discovered that MI5 didn't immediately notify West Yorkshire Police Special Branch that the suspects were on their patch. I was subsequently told by two senior West Yorkshire officers - independently and on different occasions - that this was common. The Security Service did not routinely share such detailed operational intelligence with the police. I later had sight of the MI5 officers' log that recorded the journey and confirmed what I'd been told.

The omission was a fatal error. Two of the suspects turned out to be Mohammed Saddique Khan and Shehzad Tanweer. They were the leaders of the four suicide bombers who murdered 52 people when they attacked London's transport network on 7 July 2005 - known as 7/7. To be fair, MI5 was monitoring dozens of cases and several thousand potential suspects at the time and had to prioritise targets and resources.

Image copyright AFP Image caption A policeman stands at the memorial to 7/7 in Hyde Park in 2015

7/7 was a tragic wake-up call. In its aftermath, structures were put in place to ensure that intelligence was properly shared. Five Regional Counter Terrorist Units were set up across the country. But the change in attitude was as important as the change in structure. Previously, I had been told by my sources in West Yorkshire that its officers were never allowed inside MI5's inner sanctum. Its door was permanently locked.

All that has dramatically changed. The Security Service and local counter-terrorism police officers now work closely together and share all intelligence. The barriers are down. MI5's door is open. This shared intelligence is then passed upwards to the pinnacle of Britain's counter-terrorist pyramid where it's sifted and analysed by MI5, MI6, GCHQ and the police at their weekly meetings in MI5's London headquarters. A further benefit of shared intelligence is that the agencies and police - both at home and abroad - now all work from a single list of targets - the contents and length of which are a closely guarded national secret.

These are the hard-learned lessons that have kept Britain relatively safe for the past decade. But, as the intelligence services and the police here are at pains to point out, there is no guarantee that it will always be so.

Nice is a grim warning to all of us.

Follow @BBCNewsMagazine on Twitter and on Facebook