Deep Into Pharo

Deep Into Pharo

Deep into Pharo Alexandre Bergel Damien Cassou Stéphane Ducasse Jannik Laval ii This book is available as a free download from: http://deepintopharo.com Copyright © 2013 by Alexandre Bergel, Damien Cassou, Stéphane Ducasse and Jannik Laval. The contents of this book are protected under Creative Commons Attribution-ShareAlike 3.0 Unported license. You are free: to Share — to copy, distribute and transmit the work to Remix — to adapt the work Under the following conditions: Attribution. You must attribute the work in the manner specified by the author or licensor (but not in any way that suggests that they endorse you or your use of the work). Share Alike. If you alter, transform, or build upon this work, you may distribute the resulting work only under the same, similar or a compatible license. • For any reuse or distribution, you must make clear to others the license terms of this work. The best way to do this is with a link to this web page: creativecommons.org/licenses/ by-sa/3.0/ • Any of the above conditions can be waived if you get permission from the copyright holder. • Nothing in this license impairs or restricts the author’s moral rights. Your fair dealing and other rights are in no way affected by the above. This is a human-readable summary of the Legal Code (the full license): creativecommons.org/licenses/by-sa/3.0/legalcode Published by Square Bracket Associates, Switzerland. http://SquareBracketAssociates.org ISBN 978-3-9523341-6-4 First Edition, August, 2013. Cover art by Jérôme Bergel ([email protected]). Contents 1 Preface1 I Libraries 2 Zero Configuration Scripts and Command-Line Handlers7 2.1 Getting the VM and the Image............7 2.2 Getting the VM only................9 2.3 Handling command line options...........9 2.4 Anatomy of a handler............... 12 2.5 Using ZeroConf script with Jenkins.......... 13 2.6 Chapter summary................. 14 3 Files with FileSystem 15 3.1 Getting started.................. 15 3.2 Navigating a file system.............. 16 3.3 Opening read and write Streams........... 19 3.4 Renaming, copying and deleting files and directories.... 20 3.5 The main entry point: FileReference.......... 21 3.6 Looking at FileSystem internals............ 27 3.7 Chapter summary................. 29 4 Sockets 31 4.1 Basic Concepts.................. 31 4.2 TCP Client................... 33 4.3 TCP Server................... 37 iv Contents 4.4 SocketStream.................. 43 4.5 Tips for Networking Experiments........... 48 4.6 Chapter summary................. 49 5 The Settings Framework 51 5.1 Settings architecture................ 51 5.2 The Settings Browser................ 53 5.3 Declaring a setting................ 56 5.4 Organizing your settings.............. 61 5.5 Providing more precise value domain......... 65 5.6 Launching a script................ 68 5.7 Start-up actions management............ 69 5.8 Extending the Settings Browser............ 71 5.9 Chapter summary................. 75 6 Regular Expressions in Pharo 77 6.1 Tutorial example — generating a site map........ 78 6.2 Regex syntax.................. 85 6.3 Regex API................... 90 6.4 Implementation notes by Vassili Bykov......... 96 6.5 Chapter summary................. 97 II Source Management 7 Versioning Your Code with Monticello 101 7.1 Basic usage................... 102 7.2 Exploring Monticello repositories........... 113 7.3 Advanced topics................. 115 7.4 Getting a change set from two versions......... 120 7.5 Kinds of repositories................ 121 7.6 The .mcz file format................ 124 7.7 Chapter summary................. 126 8 Gofer: Scripting Package Loading 129 8.1 Preamble: Package management system......... 129 v 8.2 What is Gofer?.................. 132 8.3 Using Gofer................... 133 8.4 Gofer actions.................. 135 8.5 Some useful scripts................ 141 8.6 Chapter summary................. 144 9 Managing Projects with Metacello 147 9.1 Introduction................... 147 9.2 One tool for each job................ 148 9.3 Metacello features................. 149 9.4 A simple case study................ 151 9.5 Loading a Metacello Configuration.......... 154 9.6 Managing dependencies between packages....... 155 9.7 Baselines.................... 157 9.8 Groups..................... 160 9.9 Dependencies between projects............ 163 9.10 About dependency granularity............ 169 9.11 Executing code before and after installation....... 171 9.12 Platform specific package.............. 172 9.13 Milestoning development: symbolic versions....... 176 9.14 Load types................... 181 9.15 Conditional loading................ 183 9.16 Project version attributes.............. 185 9.17 Chapter summary................. 186 III Frameworks 10 Glamour 191 10.1 Installation and first browser............. 191 10.2 Presentation, Transmission and Ports.......... 194 10.3 Composing and Interaction............. 200 10.4 Chapter summary................. 207 11 Agile Visualization with Roassal 209 11.1 Installation and first visualization........... 209 vi Contents 11.2 Roassal core model................ 212 11.3 Detailing shapes................. 218 11.4 Edges: linking elements.............. 221 11.5 Layouts.................... 224 11.6 Events and Callbacks............... 230 11.7 The interaction hierarchy.............. 231 11.8 Understanding a View’s Camera........... 234 11.9 Beyond Pharo.................. 238 11.10 Chapter summary................. 239 12 Scripting Visualizations with Mondrian 241 12.1 Installation and first visualization........... 241 12.2 Starting with Mondrian............... 242 12.3 Visualizing the Collection framework......... 247 12.4 Reshaping nodes................. 248 12.5 Multiple edges.................. 249 12.6 Colored shapes.................. 251 12.7 More on colors.................. 252 12.8 Popup view................... 253 12.9 Subviews.................... 255 12.10 Forwarding events................ 256 12.11 Events..................... 257 12.12 Interaction................... 257 12.13 Chapter summary................. 259 IV Language 13 Handling Exceptions 263 13.1 Introduction................... 263 13.2 Ensuring execution................ 264 13.3 Handling non-local returns............. 265 13.4 Exception handlers................ 266 13.5 Error codes — don’t do this!............. 268 13.6 Specifying which exceptions will be handled....... 269 vii 13.7 Signaling an exception............... 271 13.8 Finding handlers................. 273 13.9 Handling exceptions................ 275 13.10 Comparing outer with pass .............. 281 13.11 Exceptions and ensure:/ifCurtailed: interaction....... 282 13.12 Example: Deprecation............... 284 13.13 Example: Halt implementation............ 285 13.14 Specific exceptions................ 286 13.15 When not to use exceptions............. 288 13.16 Exceptions implementation............. 289 13.17 Ensure:’s implementation.............. 295 13.18 Chapter summary................. 300 14 Blocks: a Detailed Analysis 303 14.1 Basics..................... 304 14.2 Variables and blocks................ 306 14.3 Variables can outlive their defining method....... 313 14.4 Returning from inside a block............ 314 14.5 Contexts: representing method execution........ 320 14.6 Message execution................ 323 14.7 Chapter conclusion................ 326 15 Exploring Little Numbers 329 15.1 Power of 2 and Numbers.............. 329 15.2 Bit shifting is multiplying by 2 powers......... 331 15.3 Bit manipulation and access............. 333 15.4 Ten’s complement of a number............ 335 15.5 Negative numbers................ 336 15.6 Two’s complement of a number............ 337 15.7 SmallIntegers in Pharo............... 340 15.8 Hexadecimal.................. 342 15.9 Chapter summary................. 342 viii Contents 16 Fun with Floats 345 16.1 Never test equality on floats............. 345 16.2 Dissecting a Float................. 347 16.3 With floats, printing is inexact............ 351 16.4 Float rounding is also inexact............ 352 16.5 Fun with inexact representations........... 353 16.6 Chapter summary................. 354 V Tools 17 Profiling Applications 357 17.1 What does profiling mean?............. 357 17.2 A simple example................. 358 17.3 Code profiling in Pharo............... 359 17.4 Read and interpret the results............ 362 17.5 Illustrative analysis................ 367 17.6 Counting messages................ 369 17.7 Memorized Fibonacci............... 369 17.8 SpaceTally for memory consumption per Class...... 371 17.9 Few advices................... 372 17.10 How MessageTally is implemented?.......... 372 17.11 Chapter summary................. 373 18 PetitParser: Building Modular Parsers 375 18.1 Writing parsers with PetitParser........... 375 18.2 Composite grammars with PetitParser......... 384 18.3 Testing a grammar................ 389 18.4 Case Study: A JSON Parser............. 391 18.5 PetitParser Browser................ 397 18.6 Packrat Parsers.................. 409 18.7 Chapter summary................. 409 19 Biographies 411 Chapter 1 Preface “Smalltalk is well known as an excellent tool for agile and exploratory programming. In this book the authors present a new dialect of Smalltalk called Pharo that has been specifically designed for inventive developers. The authors are key members of the Pharo team and accom- plished Object Oriented educators, researchers and designers. Numer- ous Smalltalk projects from the authors and others have been ported to Pharo. Enjoy Deep Into Pharo” - Dave Thomas1

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    420 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us