Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống
1
/ 336 trang
THÔNG TIN TÀI LIỆU
Thông tin cơ bản
Định dạng
Số trang
336
Dung lượng
3,45 MB
Nội dung
[...]... reproduce the examples in the book As you grow in confidence, you willbeabletotackleyourownprogrammingprojects Thefirststepinacquiringanynewskillisnotbeingabletodoyourown thing but being able to reproduce what other people have done before you.Thisisthequickestwaytomasteringaskill Getting started with programming in a new language is not so much a deep exercise in understanding the underlying principles that... variousmessageboardsofmanymore.Sevenlanguagesonsevenplatforms is an insurmountable topic for a single author and probably for amultiauthorbook.Ican’tsupportinstallationforsevenlanguages,so I’mnotgoingtotry I suspect that you’re not remotely interested in reading another outdated installation guide Languages and platforms change I’ll tell you where to go to install the language, and I’ll tell you what version I’m using That... (P1.0printing,October2010) 24 Aspoonfulofsugarmakesthemedicinegodown MaryPoppins Chapter 2 Ruby If you are sampling this book, chances are we have something in common: learning programming languages intrigues us To me, learning a language is like learning a character Throughout my career, I’ve experienced scores of languages firsthand Like any person, each languagetookonadistinctpersonality.Javawaslikehavingarichlawyer... quickly than you can in other languages Some languages support programming models that are laser-focused on a particularproblem,suchasusinglogictosolveconstraints When you’re through, you will not be an expert in any of these languages, butyou will knowwhateachuniquelyhastooffer.Let’sgetto thelanguages 1.2 TheLanguages Choosing the languagesin this book was much easier than you might imagine I simply asked... Ruby can be interpreted In fact, Rubyisalmostalwaysinterpreted,thoughsomedevelopersareworking onvirtualmachinesthatcompileRubytobytecodeasitgetsexecuted I didn’t declare any variables Everything I did returned a value, even Reporterratum thiscopyis (P1.0printing,October2010) 28 D AY 1: F INDING A N ANNY when I didn’t ask Ruby to return anything In fact, every piece of code inRubyreturnssomething Yu also... types of strings One quote around a string o means the string should be interpreted literally, and two quotes leads tostringevaluation.OneofthethingsthattheRubyinterpreterevaluatesisstringsubstitution.Inthisexample,Rubysubstitutedthevalue returnedbythecode language intothestring.Let’skeepgoing TheProgrammingModel Oneofthefirstquestionsaboutalanguageyoushouldansweris,“What is the programming model?”... end)orone-lineforms( stateif or unless To some, the ment if condition) when you’re working with Reporterratum thiscopyis (P1.0printing,October2010) 30 D AY 1: F INDING A N ANNY one-lineversionofthe if isoff-putting.Tome,itallowsyoutoexpressa singlethoughtinalineofcode: order.calculate_taxunlessorder.nil ? Sure,youcanexpressthepreviousinablock,butyouwouldaddadditional noise to what should be a single, coherent... probablybeenexposedtoprocedurallanguagessuchasC,Fortran,or Pascal Most of us are using object-oriented languages right now, but manyofthoselanguageshaveproceduralelementstoo.Forexample, in Java is not an object Yu may have picked up this book to explore o functional programming languages Some of those languages such as Scala mix programming models by throwing in object-oriented concepts There are dozens of other programming... of others haltingly, including the languagesin this book I’m not qualified to support six Reporterratum thiscopyis (P1.0printing,October2010) 23 A F INAL C HARGE of the languages on this list I write Ruby full-time and have for five years now But I couldn’t tell you how to write a web server in Io or a databaseinErlang IwouldfailbadlyifItriedtoprovideanexhaustivereferenceforeachof these languages I could... code.Inthissession,you’renotgoingtowritewholeprograms.Instead, you’ll use irb to execute a few Ruby snippets As always, you can find theanswersinthebackofthebook Find: • TheRubyAPI • The free online version of Programming Ruby: The Pragmatic Programmer’sGuide [TFH08] Reporterratum thiscopyis (P1.0printing,October2010) 34 D AY 2: F LOATING D OWN FROM THE S KY • Amethodthatsubstitutespartofastring • InformationaboutRuby’sregularexpressions . is interested in exploring new horizons
or evaluating emerging languages before committing to studying one
in particular.
Antonio Cangiano
Software engineer. introducing seven important and
diverse languages in a concise—but nontrivial—manner, revealing
their strengths and reasons for being. This book is akin