Programming Groovy Dynamic Productivity for the Java Developer 1st Edition Venkat Subramaniam download
Programming Groovy Dynamic Productivity for the Java Developer 1st Edition Venkat Subramaniam download
https://ebookname.com/product/programming-groovy-dynamic-
productivity-for-the-java-developer-1st-edition-venkat-
subramaniam/
https://ebookname.com/product/programming-groovy-2-dynamic-
productivity-for-the-java-developer-2nd-edition-venkat-
subramaniam/
https://ebookname.com/product/programming-scala-tackle-multi-
core-complexity-on-the-java-virtual-machine-1st-edition-venkat-
subramaniam/
https://ebookname.com/product/programming-concurrency-on-the-jvm-
mastering-synchronization-stm-and-actors-venkat-subramaniam/
https://ebookname.com/product/sociological-theory-in-the-
classical-era-text-and-readings-3rd-edition-edition-laura-desfor-
and-scott-appelrouth/
Security and Trends in Wireless Identification and
Sensing Platform Tags Advancements in RFID 1st Edition
Pedro Peris Lopez
https://ebookname.com/product/security-and-trends-in-wireless-
identification-and-sensing-platform-tags-advancements-in-
rfid-1st-edition-pedro-peris-lopez/
https://ebookname.com/product/lake-taihu-china-dynamics-and-
environmental-change-monographiae-biologicae-1st-edition-boqiang-
qin/
https://ebookname.com/product/the-ecological-approach-to-visual-
perception-classic-edition-james-j-gibson/
https://ebookname.com/product/practicing-materiality-1st-edition-
ruth-m-van-dyke/
https://ebookname.com/product/historical-dictionary-of-the-cold-
war-2nd-edition-edition-joseph-smith/
Primitive Mental States A Psychoanalytic Exploration of
the Origins of Meaning 1st Edition Jane Van Buren (Ed.)
https://ebookname.com/product/primitive-mental-states-a-
psychoanalytic-exploration-of-the-origins-of-meaning-1st-edition-
jane-van-buren-ed/
What readers are saying about Programming Groovy
Venkat Subramaniam
Every precaution was taken in the preparation of this book. However, the publisher
assumes no responsibility for errors or omissions, or for damages that may result from
the use of information (including program listings) contained herein.
Our Pragmatic courses, workshops, and other products can help you and your team
create better software and have more fun. For more information, as well as the latest
Pragmatic titles, please visit us at
http://www.pragprog.com
ISBN-10: 1-934356-09-3
ISBN-13: 978-1-934356-09-8
Printed on acid-free paper with 50% recycled, 15% post-consumer content.
–
1 Introduction 16
1.1 Why Dynamic Languages? . . . . . . . . . . . . . . . . . 16
1.2 What’s Groovy? . . . . . . . . . . . . . . . . . . . . . . . 19
1.3 Why Groovy? . . . . . . . . . . . . . . . . . . . . . . . . . 20
1.4 What’s in This Book? . . . . . . . . . . . . . . . . . . . . 23
1.5 Who Is This Book For? . . . . . . . . . . . . . . . . . . . 26
1.6 Acknowledgments . . . . . . . . . . . . . . . . . . . . . . 26
I Beginning Groovy 29
2 Getting Started 30
2.1 Getting Groovy . . . . . . . . . . . . . . . . . . . . . . . . 30
2.2 Installing Groovy . . . . . . . . . . . . . . . . . . . . . . 31
2.3 Test-Drive Using groovysh . . . . . . . . . . . . . . . . . 32
2.4 Using groovyConsole . . . . . . . . . . . . . . . . . . . . 33
2.5 Running Groovy on the Command Line . . . . . . . . . 34
2.6 Using an IDE . . . . . . . . . . . . . . . . . . . . . . . . . 35
4 Dynamic Typing 75
4.1 Typing in Java . . . . . . . . . . . . . . . . . . . . . . . . 75
4.2 Dynamic Typing . . . . . . . . . . . . . . . . . . . . . . . 78
4.3 Dynamic Typing != Weak Typing . . . . . . . . . . . . . 79
4.4 Design by Capability . . . . . . . . . . . . . . . . . . . . 80
4.5 Optional Typing . . . . . . . . . . . . . . . . . . . . . . . 86
4.6 Types in Groovy . . . . . . . . . . . . . . . . . . . . . . . 86
4.7 Multimethods . . . . . . . . . . . . . . . . . . . . . . . . 87
4.8 Dynamic: To Be or Not to Be? . . . . . . . . . . . . . . . 91
5 Using Closures 92
5.1 Closures . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
5.2 Use of Closures . . . . . . . . . . . . . . . . . . . . . . . 96
5.3 Working with Closures . . . . . . . . . . . . . . . . . . . 98
5.4 Closure and Resource Cleanup . . . . . . . . . . . . . . 98
5.5 Closures and Coroutines . . . . . . . . . . . . . . . . . . 101
5.6 Curried Closure . . . . . . . . . . . . . . . . . . . . . . . 102
5.7 Dynamic Closures . . . . . . . . . . . . . . . . . . . . . . 105
5.8 Closure Delegation . . . . . . . . . . . . . . . . . . . . . 107
5.9 Using Closures . . . . . . . . . . . . . . . . . . . . . . . 110
15 MOPping Up 224
15.1 Creating Dynamic Classes with Expando . . . . . . . . 224
15.2 Method Delegation: Putting It All Together . . . . . . . 227
15.3 Review of MOP Techniques . . . . . . . . . . . . . . . . . 231
B Bibliography 296
Index 298
Foreword
Back in 2003, when we started Groovy, our goal was to provide Java
developers with an additional language to complement Java, a new
Swiss Army knife to add to their tool belt. Java is a great language and
a wonderful platform, but sometimes you need the agility and expres-
siveness of scripting languages or, even better, dynamic languages. We
didn’t want a new language that would be a paradigm shift for Java
developers. Instead, Groovy was made to seamlessly integrate with Java
in all possible ways while at the same time adding all the goodies
you would expect from a dynamic language. The best of both worlds!
You don’t even have to wait for Java 7, 8, or 9 to get all the nuggets
you’d want to have in your next programming language of choice: clo-
sures, properties, native syntax for lists, maps, and regular expres-
sions. Everything is already there.
Over the course of time, Groovy has matured a lot and has become a
very successful open source dynamic language used by tons of Java
developers and by big companies that embed it in their applications
servers or their mission-critical applications. Groovy lets you write more
expressive unit tests and simplifies XML parsing or SQL data imports,
and for your mundane tasks, there’s a scripting solution perfectly inte-
grated with your Java ecosystem. When you need to extend your appli-
cation to customize it to your needs, you can also integrate Groovy
at specific points by injecting Groovy scripts. Thanks to Groovy’s mal-
leable syntax, you can even create domain-specific languages fairly eas-
ily to represent business rules that even end users can author.
Now, step back a little. At first sight, despite the marketing taint of
the previous paragraphs, it sounds great, and you probably see a few
places where you’d definitely need to use such a versatile tool. But it’s
just something else you have to learn to be able to leverage it to its
fullest extent, right? You’re a Java developer, so do you fear it’s going
to be difficult to get the best out of it without wasting too much of your
time and energy?
F OREWORD 15
Fortunately, this book is right for you. Venkat will guide you through
Groovy and its marvels. Without being a boring encyclopedia, this book
covers a lot of ground. And in a matter of hours (well, in fact, just the
time to read the book), you’ll be up to speed, and you’ll see how Groovy
was made by Java developers for Java developers. You won’t regret your
journey, and you’ll be able to keep this book on your desk for reference
or for finding new creative ways to solve the problem of the day.
Introduction
As a busy Java developer, you’re constantly looking for ways to be more
productive, right? You’re probably willing to take all the help you can
get from the platform and tools available to you. When I wax poetic
about the “strength of Java,” I’m not talking about the language or its
syntax. It’s the Java platform that has become more capable and more
performant. To reap the benefit of the platform and to tackle the inher-
ent complexities of your applications, you need another tool—one with a
dynamic and metaprogramming capabilities. Java—the language—has
been flirting with that idea for a while and will support these features
to various degrees in future versions. However, you don’t have to wait
for that day. You can build performant Java applications with all the
dynamic capabilities today, right now, using Groovy.
1. Tim O’Reilly observes the following about developing web applications: “Rather than
being finished paintings, they are sketches, continually being redrawn in response to
new data.” He also makes the point that dynamic languages are better suited for these in
“Why Scripting Languages Matter” (see Appendix A, on page 291).
2. A fifth reason is the ability to run dynamic languages on the JVM, but that came
much later.
W HY D YNAMIC L ANGUAGES ? 18
3. The Groovy users mailing list is very active, with constant discussions from passion-
ate users expressing opinions, ideas, and criticisms on current and future features. Visit
http://groovy.codehaus.org/Mailing+Lists and http://groovy.markmail.org if you don’t believe me.
4. “Legacy code is simply code without tests.” —Michael C. Feathers [Fea04]
W HAT ’ S G ROOVY ? 19
on. In this section, I will discuss whether Groovy is the right language
for you.
As a programmer, I am shameless about languages. I can comfortably
program in about eight structured, object-oriented, and functional pro-
gramming languages and can come dangerously close to writing code
in a couple more. In any given year, I actively code in about two to three
languages at least. So, if one thing, I am pretty unbiased when it comes
to choosing a language—I will pick the one that works the best for a
given situation. I am ready to change to another language with the ease
of changing a shirt, if that is the right thing to do, that is.
Groovy is an attractive language for a number of reasons:
• It has a flat learning curve.
• It follows Java semantics.
• It bestows dynamic love.
• It extends the JDK.
I’ll now expand on these reasons. First, you can take almost any Java
code9 and run it as Groovy. The significant advantage of this is a flat
learning curve. You can start writing code in Groovy and, if you’re
stuck, simply switch gears and write the Java code you’re familiar with.
You can later refactor that code and make it groovier.
For example, Groovy understands the traditional for loop. So, you can
write this:
// Java Style
for(int i = 0; i < 10; i++)
{
//...
}
As you learn Groovy, you can change that to the following code or one
of the other flavors for looping in Groovy (don’t worry about the syntax
right now; after all, you’re just getting started, and very soon you’ll be
a pro at it):
10.times {
//...
}
println XmlParser.class
println XmlParser.class.superclass
Now let’s talk about the third reason to love Groovy. Groovy is dynamic,
and it is optionally typed. If you’ve enjoyed the benefits of other dynamic
languages such as Smalltalk, Python, JavaScript, and Ruby, you can
realize those in Groovy. If you had looked at Groovy 1.0 support for
metaprogramming, it probably left you desiring for more. Groovy has
come a long way since 1.0, and Groovy 1.5 has pretty decent metapro-
gramming capabilities.
For instance, if you want to add the method isPalindrome( ) to String—a
method that tells whether a word spells the same forward and back-
ward—you can add that easily with only a couple lines of code (again,
don’t try to figure out all the details of how this works right now; you
have the rest of the book for that):
Download Introduction/Palindrome.groovy
String.metaClass.isPalindrome = {->
delegate == delegate.reverse()
}
word = 'tattarrattat'
println "$word is a palindrome? ${word.isPalindrome()}"
word = 'Groovy'
println "$word is a palindrome? ${word.isPalindrome()}"
Finally, as a Java programmer, you rely heavily on the JDK and the API
to get your work done. These are still available in Groovy. In addition,
W HAT ’ S IN T HIS B OOK ? 23
Groovy extends the JDK with convenience methods and closure support
through the GDK. Here’s a quick example of an extension in GDK to the
java.util.ArrayList class:
lst = ['Groovy' , 'is' , 'hip' ]
println lst.join(' ' )
println lst.getClass()
The output from the previous code confirms that you’re still working
with the JDK but that you used the Groovy-added join( ) method to con-
catenate the elements in the ArrayList:
Groovy is hip
class java.util.ArrayList
You can see how Groovy takes the Java you know and augments it.
If your project team is familiar with Java, if they’re using it for most
of your organization’s projects, and if you have a lot of Java code to
integrate and work with, then you will find that Groovy is a nice path
toward productivity gains.
working with multiple Java/Groovy classes and scripts—so you can put
Groovy to use right away for your day-to-day tasks. I also discuss the
Groovy extensions and additions to the JDK so you can take advantage
of both the power of Groovy and the JDK at the same time.
In the chapters in Part 3, “MOPping Groovy,” I focus on the metapro-
gramming capabilities of Groovy. You’ll see Groovy really shine in these
chapters and learn how to take advantage of its dynamic nature. You’ll
start with the fundamentals of MetaObject Protocol (MOP), learn how to
do aspect-oriented programming (AOP) such as operations in Groovy,
and learn about dynamic method/property discovery and dispatching.
Then you’ll apply those right away to creating and using builders and
domain-specific languages (DSLs). Unit testing is not only necessary in
Groovy because of its dynamic nature, but it is also easier to do—you
can use Groovy to unit test your Java and Groovy code, as you’ll see in
this part of the book.
Here’s what’s in each chapter:
Part 1: “Beginning Groovy”
In Chapter 2, Getting Started, on page 30, you’ll download and install
Groovy and take it for a test-drive right away using groovysh and groovy-
Console. You’ll also learn how to run Groovy without these tools—from
the command line and within your IDEs.
In Chapter 3, Groovy for the Java Eyes, on page 37, you’ll start with
familiar Java code and refactor that to Groovy. After a quick tour of
Groovy features that improve your everyday Java coding, you’ll learn
about Groovy’s support for Java 5 features. Groovy follows Java seman-
tics, except in places it does not—you’ll also learn gotchas that’ll help
avoid surprises.
In Chapter 4, Dynamic Typing, on page 75, you’ll see how Groovy’s
typing is similar and different from Java’s typing, what Groovy really
does with the type information you provide, and when to take advan-
tage of dynamic typing vs. optional typing. You’ll also learn how to take
advantage of Groovy’s dynamic typing, design by capability, and multi-
methods.
In Chapter 5, Using Closures, on page 92, you’ll learn all about the
exciting Groovy feature called closures, including what they are, how
they work, and when and how to use them.
W HAT ’ S IN T HIS B OOK ? 25
"At that time I myself was still a god, and none of the positive
religions had more value for me than another; I could only wear
their uniforms as a matter of courtesy, on the same principle
that the Emperor of Russia dresses himself up as an officer of
the Prussian Guard when he honours his imperial cousin with a
visit to Potsdam."
After all, his apostasy brought with it its own punishment, not only in
its deep-felt shame, but in the fact that he eventually threw up law
for literature, and thus rendered so great a sacrifice of racial loyalty
and his own self-respect consummately futile. After selling his
birthright he found that he had absolutely no use for the mess of
pottage which he had purchased.
In the summer of 1825, Heine, having just succeeded in passing his
degree, proceeded to the little island of Norderney, off the coast of
Holland, to recuperate. Living ardently the simple life and indulging
to the full his passion for the sea, he now wrote not only the second
part of the Reisebilder, entitled Norderney, but the far greater
Nordsee Cyklus, which in its irregular swinging metre expresses with
such marvellous efficiency the whole roar and grandeur of the
ocean. Speaking generally, of course, Heine was too subjective to be
a real nature poet. No writer, it is true, fills up so freely and with so
fantastic an elegance the blank cheques of nightingales and violets,
lilies and roses, stars and moonshine, yet none the less these rather
served to grace his measure than as his real flame. His one genuine
love was the sea. With the sea he felt a deep psychological affinity.
The sea was the symbol of his own infinite restlessness, of his own
divine discontent, and mirrored in the sea's ever-changing waters he
beheld the incessant smiles and storms of his own soul.
In 1826 Heine published the Heimkehr, the Nordsee Cyklus, the airy
and sparkling Harzreise, and the first part of the Reisebilder.
From Norderney Heine moved to Hamburg, avowedly to practise,
though it does not appear that he took his profession with much
seriousness. At any rate, until 1831, when he migrated to Paris, his
career is excessively erratic. At one moment he is paying a flying
visit to England, "the land of roast beef and Yorkshire plum-pudding,
where the machines behave like men and the men like machines"; at
another he is on the staff of the Allgemeinen Politischen Annalen
and the Morgenblatt of Munich; he is now in Hamburg, now in
Frankfurt, and now in Italy, where his sojourn inspired the racy and
brilliant Italy and Baths of Lucca, both of which works obtained the
gratuitous and well-merited state advertisement of prohibition, and
achieved a most undeniable succès de scandale.
The departure to Paris marks an entirely new epoch in Heine's life,
and offers a convenient stopping-place at which to give some
account of his early poetry and prose, as exemplified in the Book of
Songs, which was published in 1827, and the Reisebilder, the last
part of which, the Baths of Lucca, was published in 1831.
Though neither the Book of Songs nor the Reisebilder is as great or
as characteristic as the Romanzero and Poetische Nachlese on the
one hand, or the Salon on the other, they are yet by far the most
popular of his works and contain some of his most delightful writing.
One of the first traits that strikes us in the Book of Songs is the
Romantic tendency to bizarre and exotic themes. In the Junge
Leiden and Lyrisches Intermezzo in particular we move in a ghostly
atmosphere of apparitions, sea-maidens, skeletons, and midnight
churchyards. Another interesting characteristic of these poems is his
deep love of the East, a love which is to be probably ascribed more
to the general eastward gravitation of the Romantic school than to
the poet's Oriental blood. This tendency is responsible for two of the
most charming poems in the book, the exquisite lyric starting:
"Auf Flügeln des Gesanges
Herzliebchen trag ich dich fort
Fort nach den Fluren des Ganges
Dort weiss ich den schönsten Ort."
It is this trait of doing things with an object which supplied the true
clue to Disraeli as a man of letters. We admit, of course, the verve
and brilliancy of the novels, their claim to rank as classic, but it is
impossible to arrive at a correct appreciation of them unless they be
taken in the closest conjunction with their author's political career.
Vivian Grey, for instance, no doubt afforded an excellent outlet for
the fermenting passion of Disraeli's youth; it was itself one of the
best society novels ever written, but it was something more. Before
that time the future Premier had been hiding his light. How could he
obtain a free field for the exercise of his gifts? His father's Bohemian
clique scarcely answered his purpose. How could he burst open the
doors of society? The bombshell was supplied by Vivian Grey. It was
a case of self-advertisement raised to the level of a fine art, and
Disraeli introduced himself to the public with a bow of most
elaborate flourishes. Contarini Fleming strikes a slightly different
note, exhibiting the more poetic side of its author's character; but
we must not forget that at the time when it was published Disraeli's
long absence in the East had temporarily obscured his fame in
London, and that it was the success of Contarini Fleming which
secured for him once more the entrée into society. Similarly,
Coningsby, Sybil, and Tancred were, in the main, but the gospels in
which, in the rôle of a political saviour, he propagated the new creed
of Young England. Lothair and Endymion were partly written to
replenish his empty exchequer. The protagonists, moreover, in all his
chief novels were fashioned in the image of himself, and even Lord
Cadurcis in Venetia, who is theoretically Byron, is portrayed with the
physical features of the author, so as to ensure a vivid impression on
the public mind of his own personality. Not that Disraeli did not
experience a genuine joy in the wielding of the pen. He could soar
high in his flights of mysticism and romance; could describe the
picturesque and the beautiful in passages of inspired rhetoric,
though it was in the dash and brilliancy of his satire which at its best
equalled that of Heine, or Voltaire, or Byron, that he was most
himself. His style is redolent of his race. It possesses the genuine
Oriental glamour, the Oriental love of gorgeous and grandiose
magnificence, the Oriental lack of symmetry and proportion. His
prodigious genius for sarcasm was also Semitic, if we are to believe
Mr. Bryce, who considers that gift a peculiar property of the race,
instancing, as examples, Lucian and Heine, the greatest satirists of
ancient and modern times.
This same combination of temperament and policy which explains
Disraeli, the man of letters, explains Disraeli, the dandy. Living as he
did in an age which revolted, under the leadership of Count D'Orsay,
against the chaste and classic traditions of Brummel, and which
offered in the elaborate picturesqueness of its dress an excellent
medium for the expression of personality, is it to be wondered at
that so ambitious a nature as Disraeli's should, apart from other
reasons, enter gaily into the sartorial arena? These early years
remind us of Alcibiades, who, in his youth, his genius, his precocious
political ambitions, his aristocratic lineage and superb insolence, his
extravagance and irresponsibility, offers a fairly close analogy.
Disraeli, however, was an Alcibiades with ballast, and his most erratic
phases were governed by a consistent purpose. He had, it is true,
the regular Hebrew love for the picturesque, the racial craving for
flamboyant display; but the unique characteristic of the man was the
ingenious method by which he exploited even his weaknesses to
advance his purpose. Realising that nothing was more fatal to his
career than the indifference of the public, that to be hated was
better than to be ignored, and that notoriety was a passable
substitute for fame, he was determined to bulk largely in the public
eye. Living, fortunately, in an age when dandyism, if not an art, was
at any rate a career, and when "wild, melancholy men" were still the
rage among the ladies, he manipulated the dandy and Byronic pose
with phenomenal success. But his social career was not all pose.
Though political ambition was to him always the main point of
existence, he was far too healthy to lose sight of the small change of
life. He had, moreover, a genuine love of society. His remark apropos
of Gladstone, "What can we do with a leader who is not even in
society?" was sincere in spite of being an epigram, and the hosts of
great ladies who crowd his novels attest conclusively to his social
fastidiousness. But the most convincing proof of this lighter side of
his nature is to be found in his correspondence with his sister. Those
letters, dashed off hurriedly to his "dearest Sa," written with that
complete lack of ceremony which is the sign of a perfect intimacy,
show with what zest he frequented balls and water-parties, dinners
and soirées. Yet his ambition is never far in the background. He goes
to the House of Commons, hears the big man speak, and then writes
to his sister, "But between ourselves I could floor them all." His
genius for conversation is historic, and we are not surprised that he
considered that the one unforgivable sin was to be a bore. He had
not, it is true, Gladstone's habit of unburdening himself freely to the
most casual of acquaintances. How many, indeed, were there of his
intimates who had penetrated into the secret places of his heart?
But over-much sincerity is a hindrance to the art of conversation;
and many of his most brilliant paradoxes were thrown off as an
evasive retort to an impertinent question. When, however, we come
to Disraeli's social and private life, the most interesting question that
presents itself is that of his relation to his wife. Even though he had
discoursed in Contarini Fleming of the grand passion with all the
high-flown sentimentalism of the age, it was obviously impossible for
him, considering the disparity of their ages, to be seriously in love
with Mrs. Disraeli; and it must have seemed that he had been forced
to exchange the poetry of the mistress for the prose of the wife. Had
he not, about ten years before his marriage, written to his sister,
"How would you like Lady B—— for a sister-in-law? Clever, £25,000,
and domestic. As for love, all my friends who have married for love
either beat their wives or live apart from them. This is literally true. I
may commit many follies, but never that of marrying for love, which,
I am convinced, cannot but be a guarantee of infelicity." Yet this
union, based originally on mere policy and camaraderie, was
eventually crowned with the most faithful of loves. It was his wife's
absorbing interest in his career that supplied the link. He has himself
written that the most exquisite moment in a man's life was when he
surprised his lady-love reading the manuscript of his first speech,
and the sympathy of Mrs. Disraeli in his successes may well have
given them a yet further charm. The situation is well expressed in
the remark of Mrs. Disraeli's: "You know you married me for money,
and I know that if you had to do it again you would do it for love."
In fact the warm and constant affection Disraeli lavished on his wife
during her lifetime, and the poignant grief that he evinced at her
death, furnish a more than sufficient refutation to those who persist
in regarding him as a mere cynical fortune-hunter. Disraeli, like
Browning, had
"Two soul sides, one to face the world with,
One to show a woman when he loves her."
In the other departments of private life he was likewise exemplary.
His hardness was limited to politics; he was the most dutiful of sons,
the most affectionate of brothers, the most faithful of friends. His
debts, for the most part, were incurred by backing the bills of other
men. His touching and romantic friendship for Mrs. Brydges
Williams, the eccentric old Cornish lady who gave him pecuniary
assistance at a critical period of his career, is well known. The story,
again, of the Premier and his wife dancing a Highland jig in their
night apparel on hearing of the success of an old friend, shows how
little the bitter struggles of politics had hardened his heart.
Particularly touching, also, is the mutual affection between him and
the Queen, that sweetened his last years. She was, as we read in a
letter of Disraeli's to the Marchioness of Ely, "the best friend he had
in the world."
But Disraeli, though he fulfilled himself in many ways, was first of all
a politician, and it is Disraeli the politician rather than Disraeli the
man of letters, the dandy, or the human being, that principally
provokes our interest. What were his real views on politics? How far
can we distinguish between the official edition of himself which he
displayed for public inspection and the original that he alone could
read? Given his policy, how far was it justifiable, how far rational?
The view of his most devoted, but yet in reality, quite
unappreciative, admirers, that throughout a political career of over
half a century he remained consistently and absolutely faithful to his
original ideals, and that he introduced into politics an integrity and
disinterestedness that Parliament had rarely witnessed, is even more
absurd than the opinion of his blind and malignant enemies that he
was a mere charlatan who juggled with parties and the people
without possessing a single genuine political faith of his own.
Disraeli, as was inevitable in a man of so detached and unprejudiced
a nature, simply took the then party system at its true worth, and, of
course, realised from the outset that before he could do anything
worth doing he must first obtain that power which alone could give
him the opportunity of doing it. His attack on Peel was, primâ facie,
an occasion that it would have been the depth of folly to have
missed, and Mr. Birrell's statement that Disraeli "ate his peck of dirt,"
and his comparison of him to Casanova, is mere petulance. For these
preliminary stages of the higher politics Disraeli was admirably fitted,
and the following autobiographic passages from Tancred show how
congenial were his Herculean labours: "To be the centre of a maze
of manœuvres was his empyrean, and while he recognised in them
the best means of success he found in their exercise a means of
constant delight"; and again, "'Intrigue,' cried the young prince,
using, as was his custom, a superfluity of expression both of voice
and hand and eyes, 'intrigue, it is life, it is the only thing. If you wish
to produce a result you must make a combination, and you call
combination intrigue.'" Disraeli viewed party politics from the
dispassionate standpoint of a chess-player, "playing off the proud
peers like pawns," skilfully manœuvring his knights and bishops
beneath the shadow of the old mediæval castles, though it was "in
his masterly manipulation of his queen" that he really surpassed
himself. What a contrast to Gladstone's youthful frame of mind, who
entered politics because he felt a strong moral duty to defend that
Church which he was afterwards partly to disestablish against the
insidious attacks of philosophic Radicalism. But Disraeli's point of
view was, after all, merely that which was obvious and rational. It is
well known that in Disraeli's day the whole efficiency of the party
system as a means of carrying on the government was based on
that sagacious inconsistency, so characteristic of this country, which,
cheerfully accommodating the most untractable of facts to the most
docile of theories, drew between the two parties no clear dividing
line either of principle or of class. Those genuine lines of cleavage
both of policy and interest that now tend to become more and more
clearly marked did not then exist. The only vital political distinction
then existing in England was that between the Ins and the Outs.
Whigs and Tories were, in their origin, merely the names for the two
rival organisations for the pursuit of political power into which the
oligarchy of the time had divided itself, and the party catch-words
then indicated as much essential difference as the badges by which
the two sides of a "scratch" game symbolise a fictitious distinction.
Particularly interesting is the following quotation from a letter of
Gladstone, written comparatively early in his career, which shows
convincingly that the subsequent democratic idealist fully realised
the intrinsic farce of the then party system: "Each of them, the Whig
and the Tory Party, comprises within itself far greater divergencies
than can be noticed as dividing the more moderate portion of the
one from the more moderate portion of the other. The great English
parties differ no more in their general outlines than by a somewhat
different distribution of the same elements in each." It is impossible
for the opportunist position to be more cogently stated. It is, indeed,
a strange paradox that political integrity should be traditionally
associated with the name of Gladstone, who accomplished more
than any other of our statesmen in changing statesmanship into
demagogy. His pronouncedly religious temperament, however, led to
extraordinary results, and his psychological condition was best
expressed in the well-known epigram that "he followed his
conscience in the same manner that the driver of a gig follows the
horse." It was not that he was deliberately insincere. He could
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade
Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.
ebookname.com