LINK DOWNLOAD MIỄN PHÍ TÀI LIỆU "Tài liệu Seven Languages in Seven Weeks pptx": http://123doc.vn/document/1041427-tai-lieu-seven-languages-in-seven-weeks-pptx.htm
A Pragmatic Guide to Learning
Programming Languages
Bruce A. Tate
The Pragmatic Bookshelf
Raleigh, North Carolina Dallas, Texas
Many of the designations used by manufacturers and sellers to distinguish their prod-
ucts are claimed as trademarks. Where those designations appear in this book, and The
Pragmatic Programmers, LLC was aware of a trademark claim, the designations have
been printed in initial capital letters or in all capitals. The Pragmatic Starter Kit, The
Pragmatic Programmer, Pragmatic Programming, Pragmatic Bookshelf and the linking
g
device are trademarks of The Pragmatic Programmers, LLC.
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
.
The team that produced this book includes:
Editor: Jackie Carter
Indexing: Potomac Indexing, LLC
Copy edit: Kim W i m p s e t t
Layout: Steve Peter
Production: Janet Furlow
Customer support: Ellie Callahan
International: Juliet Benda
Copyright
©
2010 Pragmatic Programmers, LLC.
All rights reserved.
No part of this publication may be reproduced, stored in a retrieval system, or transmit-
ted, in any form, or by any means, electronic, mechanical, photocopying, recording, or
otherwise, without the prior consent of the publisher.
Printed in the United States of America.
ISBN-10: 1-934356-59-X
ISBN-13: 978-1-934356-59-3
Printed on acid-free paper.
P1.0 printing, October 2010
V e r s i o n : 2010-10-28
Contents
Dedication 9
Acknowledgments 11
Foreword 14
1 Introduction 17
1.1 Method to the Madness . . . . . . . . . . . . . . . . . . 17
1.2 The Languages . . . . . . . . . . . . . . . . . . . . . . . 19
1.3 Buy This Book . . . . . . . . . . . . . . . . . . . . . . . . 21
1.4 Don’t Buy This Book . . . . . . . . . . . . . . . . . . . . 22
1.5 A Final Charge . . . . . . . . . . . . . . . . . . . . . . . . 24
2 Ruby 25
2.1 Quick History . . . . . . . . . . . . . . . . . . . . . . . . 26
2.2 Day 1: Finding a Nanny . . . . . . . . . . . . . . . . . . 28
2.3 Day 2: Floating Down from the Sky . . . . . . . . . . . 35
2.4 Day 3: Serious Change . . . . . . . . . . . . . . . . . . . 48
2.5 W r a p p i n g Up Ruby . . . . . . . . . . . . . . . . . . . . . 56
3 Io 60
3.1 Introducing Io . . . . . . . . . . . . . . . . . . . . . . . . 60
3.2 Day 1: Skipping School, Hanging Out . . . . . . . . . . 61
3.3 Day 2: The Sausage King . . . . . . . . . . . . . . . . . 74
3.4 Day 3: The Parade and Other Strange Places . . . . . . 83
3.5 W r a p p i n g Up Io . . . . . . . . . . . . . . . . . . . . . . . 92
4 Prolog 95
4.1 About Prolog . . . . . . . . . . . . . . . . . . . . . . . . . 96
4.2 Day 1: An Excellent Driver . . . . . . . . . . . . . . . . . 97
4.3 Day 2: Fifteen Minutes to W a p n e r . . . . . . . . . . . . 109
4.4 Day 3: Blowing Up V e g a s . . . . . . . . . . . . . . . . . . 120
4.5 W r a p p i n g Up Prolog . . . . . . . . . . . . . . . . . . . . . 132
CONTENTS 8
5 Scala 135
5.1 About Scala . . . . . . . . . . . . . . . . . . . . . . . . . 135
5.2 Day 1: The Castle on the Hill . . . . . . . . . . . . . . . 139
5.3 Day 2: Clipping Bushes and Other New Tricks . . . . . 153
5.4 Day 3: Cutting Through the Fluff . . . . . . . . . . . . . 167
5.5 W r a p p i n g Up Scala . . . . . . . . . . . . . . . . . . . . . 176
6 Erlang 181
6.1 Introducing Erlang . . . . . . . . . . . . . . . . . . . . . 181
6.2 Day 1: Appearing Human . . . . . . . . . . . . . . . . . 185
6.3 Day 2: Changing Forms . . . . . . . . . . . . . . . . . . 195
6.4 Day 3: The Red Pill . . . . . . . . . . . . . . . . . . . . . 207
6.5 W r a p p i n g Up Erlang . . . . . . . . . . . . . . . . . . . . 219
7 Clojure 223
7.1 Introducing Clojure . . . . . . . . . . . . . . . . . . . . . 224
7.2 Day 1: TrainingLuke . . . . . . . . . . . . . . . . . . . . 225
7.3 Day 2: Y o d a and the Force . . . . . . . . . . . . . . . . . 243
7.4 Day 3: An Eye for Evil . . . . . . . . . . . . . . . . . . . 256
7.5 W r a p p i n g Up Clojure . . . . . . . . . . . . . . . . . . . . 264
8 Haskell 268
8.1 Introducing Haskell . . . . . . . . . . . . . . . . . . . . . 268
8.2 Day 1: Logical . . . . . . . . . . . . . . . . . . . . . . . . 269
8.3 Day 2: Spock’s Great Strength . . . . . . . . . . . . . . 285
8.4 Day 3: The Mind Meld . . . . . . . . . . . . . . . . . . . 294
8.5 W r a p p i n g Up Haskell . . . . . . . . . . . . . . . . . . . . 309
9 Wr a p - U p 313
9.1 Programming Models . . . . . . . . . . . . . . . . . . . . 313
9.2 Concurrency . . . . . . . . . . . . . . . . . . . . . . . . . 317
9.3 Programming Constructs . . . . . . . . . . . . . . . . . 319
9.4 Finding Y o u r V o i c e . . . . . . . . . . . . . . . . . . . . . 321
A Bibliography 322
Index 323
Report erratum
this copy is (P1.0 printing, October 2010)
Dedication
The five months from December 2009 through April 2010 were among
the most difficult of my life. My brother, not yet 47 years old, had emer-
gency bypass surgery. No one had any clue that anything was wrong
at all. (He came through the surgery without further incident and is
doing well.) In late March, my sister was diagnosed with breast cancer.
The biggest shock of all came in early March. My mother was diagnosed
with terminal cancer. A few short weeks later, she was gone.
As you would expect, I am left to struggle with the grief of a jarring
and unexpected loss because of a brutally efficient disease. I would
not be human otherwise. But strangely, this experience has not been
an entirely negative one. Y o u see, my mother was at peace with the
remarkable life she lived, her relationships with her family were strong
and fulfilling, and she was exactly where she wanted to be with her
faith.
LyndaLyleTate put her creative energy into painting with watercolors.
She shared her art primarily through her Madison Avenue Art Gallery
and her classes. Before I left home, I had the opportunity to take a few
lessons from her. For someone from a technical profession, the experi-
ence was always a little disorienting. I would visualize the masterpiece
on my blank canvas. As the actual image took shape, it drifted further
and further from my original vision. When I despaired that things were
beyond my ability to fix, Mom looked over my shoulder and told me
what she saw. After a few flicks of her talented wrist added darks to
accentuate depth and highlights to add clarity and detail, I would real-
ize that I had not been too far astray at all. It just took a gifted touch to
bring back my creation from the brink of disaster. Then, I would throw
my excited arms up in victory and tell everyone in the class about this
thing I had created, not yet realizing that each member of the class was
going through their own private burst of joy.
D
EDICATION
10
After a little while, I learned that Mom was working on another canvas
as well. Through her church and through her profession, she’d find
broken people. Encountering a lost spouse here or a troubled marriage
there, my mother would bring them into class where she would use the
paint and paper to slightly open a door that had been slammed shut.
As we spent our last week together, person after person would come
through her room devastated at the thought of losing their teacher, but
Mom would tell the perfect joke or offer the right word of kindness,
comforting those who came to comfort her. I got to meet the human
canvases who had been put right by the master and gone on to do great
things. It was a humbling experience.
When I told my mother that I would dedicate this book to her, she
said that she would like that, but she had nothing to do with com-
puters. That is true enough. The very thought of W i n d o w s would leave
her helpless. But Mom, you have had everything to do with me. Y o u r
well-timed words of encouragement inspired me, your love of creativity
shaped me, and your enthusiasm and love of life guide me even now.
As I think about these experiences, I can’t help but feel a little better
and a little stronger because I, too, am a canvas shaped by the master.
This book is dedicated with love to LyndaLyleTate, 1936–2010.
Report erratum
this copy is (P1.0 printing, October 2010)
Acknowledgments
This is the most demanding book I have ever written. It’s also the most
rewarding. The people who have offered to help in various ways have
made it so. Thanks first and foremost to my family. Kayla and Julia,
your writing amazes me. Y o u can’t yet imagine what you can accom-
plish. Maggie, you are my joy and inspiration.
In the Ruby community, thanks to Dave Thomas for turning me on
to the language that turned my career upside down and helped me
have fun again. Thanks also to Matz for your friendship and your offer
to share your thoughts with my readers. Y o u invited me to Japan to
visit the place where Ruby was born, and that experience inspired me
much more than you will ever know. To Charles Nutter, Evan Phoenix,
and TimBray, thanks for the conversations about topics in this book
that must have seemed tiresome but helped me refine and shape the
message.
In the Io community, thanks to Jeremy Tregunnafor helping me get
plugged in and sharing some cool examples for the book. Y o u r reviews
were among the best. They were timely and helped build a much
stronger chapter. Steve Dekorte, you’ve created something special,
whether or not the marketplace ever recognizes it as so. The concur-
rency features rock, and the language has intrinsic beauty. I can def-
initely appreciate how much of this language feels right. Thanks for
helping this neophyte debug his installation. Thanks also for your
thoughtful reviews and your interview that helped me capture the es-
sence of Io. Y o u captured the imagination of the beta readers and cre-
ated the favorite language of many of them.
In the Prolog community, thanks to Brian Tarbox for sharing your
remarkable experience with my readers. The dolphin projects, featured
on Nova, certainly add a dramatic flair to the Prolog chapter. Special
thanks go to Joe Armstrong. Y o u can see how much your feedback
shaped the chapter and the overall book. Thanks also for contributing
A
CKNOWLEDGMENTS
12
your map-coloring example and your ideas for Append. They were the
right examples delivered at the right time.
In the Scala community, thanks to my good friend V e n k a t Subrama-
niam. Y o u r Scala book is both rich and understandable. I leaned on
it heavily. I greatly appreciate your review and the little bits of help
that you offered along the way. Those little bits of your time saved
me tremendous anguish and let me focus on the task of teaching.
Thanks also to Martin Odersky for helping this stranger by sharing your
thoughts with my readers. Scala takes a unique and brave approach
to integrating functional programming paradigms with object-oriented
paradigms. Y o u r efforts are greatly appreciated.
In the Erlang community, I again thank Joe Armstrong. Y o u r kindness
and energy have helped me form the ideas in this book. Y o u r tireless
promotion of the way distributed, fault-tolerant systems should be built
is working. More than any other idea in any other language in this
book, Erlang’s “Let it crash” philosophy makes sense to me. I hope to
see those ideas more broadly adopted.
In the Clojure community, thanks to Stuart Halloway for your reviews
and ideas that forced me to work harder to bring a better book to
my readers. Y o u r insights into Clojure and your instincts helped me
understand what was important. Y o u r book was also hugely influential
in the Clojure chapter and actually changed the way I attacked some
problems in other chapters as well. Y o u r approach in your consulting
practice is greatly appreciated. Y o u ’ r e bringing much-needed simplicity
and productivity to this industry. Thanks also to Rich Hickey for your
thoughtful ideas on the creation of the language and what it means to
be a Lisp dialect. Some ideas in Clojure are intensely radical and yet
so practical. Congratulations. Y o u ’ v e found a way to make Lisp revolu-
tionary. Again.
In the Haskell community, thanks to Phillip W a d l e r for the opportu-
nity to look inside the process that created Haskell. W e share a pas-
sion for teaching, and you’re very good at it. Thanks also to Simon
Peyton-Jones. I enjoyed working through your interview, the insights
you added, and the unique perspective you brought to these readers.
The reviewers did an outstanding job with this book. Thanks to Vladi-
mir G. Ivanovic, Craig Riecke, Paul Butcher, Fred Daoud, Aaron Bedra,
David Eisinger, Antonio Cangiano, and Brian Tarbox. Y o u formed the
most effective review team I’ve ever worked with. The book is much
Report erratum
this copy is (P1.0 printing, October 2010)
A
CKNOWLEDGMENTS
13
stronger for it. I know that reviewing a book at this level of detail is
thankless, demanding work. Those of us who still like technical books
thank you. The publishing business could not exist without you.
I also want to thank those of you who shared your ideas about language
choice and programming philosophy. At various times, Neal Ford, John
Heintz, Mike Perham, and Ian W a r s h a k made significant contributions.
These kinds of conversations made me look smarter than I really am.
Beta readers, thank you for reading the book and keeping me working.
Y o u r comments have shown me that a good number of you are working
through the languages rather than casually skimming. I’ve changed the
book based on hundreds of comments so far and expect to do even more
throughout the life of the book.
Finally, to the team at the Pragmatic Bookshelf, I offer my sincerest
gratitude. Dave Thomas and Andy Hunt, you have had an incalculable
impact on my career as a programmer and again as an author. This
publishing platform has made writing viable again for me. W e can take
a book like this one that might not be as attractive to the mass market
and make it financially worthwhile. Thanks to all the members of the
publishing team. Jackie Carter, your gentle hand and guidance were
what this book needed, and I hope you enjoyed our conversations as
much as I did. Thanks to those who labored in my shadow to make
this book the best it could be. Specifically, I want to thank the team
that labored so hard to make this book look good and correct all of my
bad habits, including Kim W i m p s e t t , the copy editor; Seth Maislin, the
indexer; Steve Peter, the typesetter; and Janet Furlow, the producer.
This book would not be what it is without you.
As always, mistakes that slipped through this fine team are all mine.
For those of you I missed, I offer my sincerest apologies. Any oversight
was not intentional.
Finally, thanks to all of my readers. I think that real hard-copy books
have value, and I can follow my passion and write because you do, too.
Bruce Tate
Report erratum
this copy is (P1.0 printing, October 2010)
Foreword
From the yet to be written “How Proust Can Make Y o u a Better
Programmer”
by Joe Armstrong
, Creator of Erlang
“The Gmail editor cannot get typographic quotes right.”
“Disgraceful,” said Margery, “the sign of an illiterate programmer and a
decadent culture.”
“What should we do about it?”
“We must insist that the next programmer we hire has read all of ‘A la
recherche du temps perdu.”’
“All seven volumes?”
“All seven volumes.”
“Will it make them better at punctuation and make them get their quotes
right?”
“Not necessarily, but it will make them a better programmer. It’s a Zen
thing ”
Learning to program is like learning to swim. No amount of theory is
a substitute for diving into the pool and flailing around in the water
gasping for air. The first time you sink under the water, you panic, but
when you bob to the surface and gulp in some air, you feel elated. Y o u
think to yourself, “I can swim.” At least that’s how I felt when I learned
to swim.
It’s the same with programming. The first steps are the most difficult,
and you need a good teacher to encourage you to jump into the water.
Bruce Tate is such a teacher. This book gives you the opportunity to
start with what is the most difficult part of learning to program, namely,
getting started.
Không có nhận xét nào:
Đăng nhận xét