"The dismal science" is a derogatory alternative name for economics coined by the Victorian historian Thomas Carlyle in the 19th century (originally in the context of his argument to reintroduce slavery in the West Indies). The term drew a contrast with the then-familiar use of the phrase "gay science" to refer to song and verse writing. The latter phrase later appeared as the title of a book by Friedrich Nietzsche, The Gay Science.
Some modern synonyms include the term "the miserable science".
Origin
The phrase "the dismal science" first occurs in Thomas Carlyle's 1849 tract called "Occasional Discourse on the Negro Question", in which he argued in favor of reintroducing slavery in order to restore productivity to the West Indies:
Not a "gay science", I should say, like some we have heard of; no, a dreary, desolate and, indeed, quite abject and distressing one; what we might call, by way of eminence, the dismal science.
It was "dismal" in "find[ing] the secret of this Universe in 'supply and demand', and reducing the duty of human governors to that of letting men alone". Instead, the "idle Black man in the West Indies" should be "compelled to work as he was fit, and to do the Maker's will who had constructed him".
Carlyle's view was attacked by John Stuart Mill as making a virtue of toil itself, stunting the development of the weak, and committing the "vulgar error of imputing every difference which he finds among human beings to an original difference of nature".
Carlyle did not originally coin the phrase "dismal science" as a response to the economically-influential theories of Thomas Malthus, who predicted that starvation would inevitably result as projected population growth exceeded the rate of increase in the food supply. However, Carlyle used the word "dismal" in relation to Malthus' theory in Chartism (1839):
The controversies on Malthus and the 'Population Principle', 'Preventive Check' and so forth, with which the public ear has been deafened for a long while, are indeed sufficiently mournful. Dreary, stolid, dismal, without hope for this world or the next, is all that of the preventive check and the denial of the preventive check.
Beyond Carlyle
Many at the time and afterward have understood the phrase in relation to the grim predictions drawn from the principles of 19th century political economy. According to Humphry House:
Carlyle's phrase, "the dismal science", has been so often quoted, that there is a risk of thinking that the opinion behind it was confined to him and his followers; but the opinion was widespread, and thought to be a justifiable inference from the works of the economists: "No one," said J. E. Cairnes, "can have studied political economy in the works of its earlier cultivators without being struck with the dreariness of the outlook which, in the main, it discloses for the human race. It seems to have been Ricardo's deliberate opinion that a substantial improvement in the condition of the mass of mankind was impossible." It is not merely that the Malthusian principle of population and the doctrine that wages must normally and necessarily fall to the minimum point were gladly accepted by wicked exploiters as the justification of their profits; but thousands whose immediate interests were not touched by these beliefs found it difficult to avoid them. ... Malthus hung over England like a cloud. It is difficult now to realize what it meant to thousands of good and sensible men that they believed his principle of population to be exactly true—believed that as poverty was relieved and the standard of life raised, so surely there would be bred a new race hovering on the misery-line, on the edge of starvation. However they might wish it false, they feared it true...
(Ricardo, however, did not believe that wages must always fall to the minimum. He believed that they were a function of the margin of production.)
In modern terms, the phrase is sometimes referenced by synonymous terms like "the miserable science", as shown in this quote by E. W. Dijkstra:
As economics is known as "The Miserable Science", software engineering should be known as "The Doomed Discipline"