What is nationalism?
I disagree with both viewpoints. Nationalism is not similar in origin or nature to religion. It is not vulnerable to the cultural forces which are eroding religion, nor does it logically serve as a substitute for religion. Religion is a belief, nationalism is a feeling. They're fundamentally different.
The belief that God exists is an assertion of fact about objective reality, like the belief that unicorns exist or that a continent you have never personally seen exists. Such assertions may have widely varying probabilities of being true, but in principle they are all subject to the same kind of testing against evidence which can allow us to infer how likely they are to be true -- even if in practice people often have emotional rather than evidence-based reasons for holding such beliefs.
Nationalism, like love of family, is an emotional attitude toward a group of humans of which one feels oneself to be part. It is not an assertion about reality, though it may occasionally generate such assertions. Moreover, while it's still debatable just how religion arose and where in our evolutionary background it is rooted (if at all), there is little doubt about the roots of the human experience of national identity and solidarity. To understand this, consider our closest living relative, the chimpanzee, an animal probably quite similar to our common ancestor which lived six million years ago.
Territorial group solidarity is the basis of chimpanzee social organization. Wild chimpanzees live in social groups of up to 120 members. Each group has a defined territory and knows exactly where the borders of that territory lie. Males regularly patrol the borders of the territory in packs, on constant alert for possible encroachments from neighboring chimpanzee groups. When they find an intruder, the result is almost always murderous violence. Within each group there are smaller factions, cliques, and endless rivalries and quarrels, but all these are subordinated to solidarity within the group, against outsiders. "Wars" between neighboring social groups, sometimes escalating to extermination of the losing side, have been observed.
Each social group has certain distinct habits which qualify as "culture", in the sense that they are behavior patterns passed from one generation to the next by observation and imitation, not genetically. The distinctive hoots and calls by which chimpanzees communicate, for example, differ subtly in sound from one social group to the next, giving each group a distinct "accent" which chimpanzees can probably identify as easily as we can recognize the sound of semi-familiar foreign languages. Individuals in one group may hold their hands in a distinctive position when greeting each other, while members of an adjacent group do not. A certain food-gathering technique may be used by all members of one group, but unknown among its neighbors.
We can see territorial group solidarity operating among humans at various levels, from the street gang to the nation-state. Especially the nation-state.
One difference between humans and chimpanzees is that we have the ability to accept individuals whom we do not personally know as members of our social group. This has removed the upper limit on social-group size which exists among chimpanzees. I and most readers of this blog belong to a human territorial social group of three hundred million individuals, whose territory covers half the North American continent, yet the underlying feelings and the inborn instincts in which they are grounded remain fundamentally similar.
If anything, the fact that human culture is vastly more complex than its rudimentary chimpanzee counterpart means that the cultural component of our sense of group identity is far richer. Humans in different regions speak different languages, practice different conventions of social interaction, and hold to different norms of sexual behavior and family life. (Humans who discover how different the practices of other groups are, often find those practices disquieting, even horrifying.) They revere different ancestors and are inspired by different historical events. The larger social groups each have massive traditions of literature, music, political development, and military heroism which serve as sources of pride in group membership for each individual. All these things strengthen and enhance a form of group identity and solidarity whose ultimate roots are at least six million years old.
And all this is, as I say, an emotion, not a belief. For a human to feel love for his nation and pride in it, to feel that it is the only place in the world he would choose to live, to be willing to fight and kill and even die to defend it -- all that does not require that he believe his nation to be better than other nations (though he may also believe that). It requires only that it be his nation.
(By analogy, your love for your family does not depend on your holding a belief that this collection of people is objectively better than any other family. It's simply a result of the fact that it's your family.)
We humans differ from chimpanzees in another important way which is relevant here. The level of violence between human nations is very low compared with the level of violence between chimpanzee social groups (measured by per capita death rates from intergroup conflicts), and has been declining for centuries, even taking the gigantic wars of the early twentieth century into account. Because we are three times as intelligent as chimpanzees, we can embrace our feelings without becoming enslaved by them.
Russian superpatriot Alexander Solzhenitsyn dismissed the sepa- ratist nationalism of Ukraine (which had been part of the Russian Empire for centuries) as an absurdity -- until he met Ukrainian nationalists in the Gulag and learned firsthand the depth of their feeling. Later he wrote that, while he still thought that Ukrainian independence from Russia would be a tragic mistake, "If that is what they truly want, then we must let them go -- for I would rather that Russia be renowned for the greatness of its deeds than for the greatness of its territory."
There speaks the true patriot -- whose own love for his people gives him light to understand that of another.
(This posting is adapted from a comment here.)