Does The Lord of the Flies' ending indicate that Golding is pessimistic or optimistic about the future of society?
Interesting question. First, it helps to have some insight into the author's motivations for writing a work of literature. Though this isn't always possible, we do know that Golding, in a publicity questionnaire, described the theme of Lord of the Flies as follows:
The theme is an attempt to trace the defects of society back to the defects of human nature. The moral is that the shape of a society must depend on the ethical nature of the individual and not on any political system however apparently logical or respectable. The whole book is symbolic in nature except the rescue in the end where adult life appears, dignified and capable, but in reality enmeshed in the same evil as the symbolic life of the children on the island. The officer, having interrupted a man-hunt, prepares to take the children off the island in a cruiser which will presently be hunting its enemy in the same implacable way. And who will rescue the adult and his cruiser?
It is clear, from this statement, that Golding believes that humans are inherently savage--and that the presence of a political system is not a sufficent means of shaping people's fundamental nature. In other words, the "defects of human nature" are what cause problems in society, and those defects, Golding would say, are present within us all. (Golding chose to use children as his characters to show that even youngsters, who haven't been "corrupted" by society to the extent that adults have, are still susceptible to the descent into savagery.) Further, it's important to note that Golding's experiences in World War II shaped his view that humans resort to savagery in certain conditions. These things considered, it's relatively safe to conclude that Golding is quite pessimistic of the future of society, since he believes that we are all fundamentally flawed.
Aside from the irony regarding the boys' rescue by officers on a warship, we see irony in the fact that Jack, who fought for power throughout the entire novel, becomes suddenly unwilling to accept responsibility when one officer asks who's in charge. Here, Golding effectively reduces the warrior Jack to a small, meek little boy:
A little boy who wore the remains of an extraordinary black cap on his red hair and who carried the remains of a pair of spectacles at his waist, started forward, then changed his mind and stood still.
Instead, Ralph, who considered giving up being chief because of Jack's power and growing following, assumes responsibility for the others. Not surprisingly, it is Ralph who understands the scope of the situation--and it is Ralph (along with others) who is left weeping as the novel closes:
Ralph wept for the end of innocence, the darkness of man's heart, and the fall through the air of the true, wise friend called Piggy.
As the naval officer lands on the island and rescues the boys, he seems dumbstruck by what has occurred on the island. The boys could have come together in the crisis of being stranded on the island and worked together for their mutual survival. Instead the group is divided with the boys turning on each other. While Ralph and Piggy are interested in protecting the little ones and keeping the fire going, Jack's group is only concerned with the immediate gratification of hunting.
Because Golding has Jack's group become dominant and stronger even killing Piggy and Simon (although Piggy and Ralph were present in this scene too), he seems to be saying that the baser instincts of mankind will win out in the end. I'd say that's pretty pessimistic.
The irony comes in when we realize that the sailors who are rescuing the boys from themselves are at war too. Although shocked by the boys' behavior, the adults have turned on each other as well as evidenced in the war.