1\documentstyle[local,twoside,pce,psfig,logo,11pt]{report} 2 3\makeindex 4 5%\includeonly{draw} 6 7\begin{document} 8 9\begin{titlepage} 10\titlepageheader 11\vfil\vfil\vfil 12\begin{center} 13 {\Huge \bf PceDraw \\[3mm] 14 \LARGE An example of using PCE-4} \\[1.5cm] 15 {\large \it Jan Wielemaker} \\[3mm] 16 {\large jan@swi.psy.uva.nl} 17\end{center} 18\vfil 19\begin{quote} 20This document describes the design and implementation of PceDraw, a 21drawing tool written in PCE-4/Prolog. PceDraw exploits many of the 22features of PCE and is written according to our current ideas on using 23PCE/Prolog. 24\end{quote} 25\vfil 26\vfil 27\end{titlepage} 28 29\pagestyle{esprit} 30\newcommand{\bottomleft}{\mbox{}} 31\newcommand{\bottomright}{\mbox{}} 32 33\tableofcontents 34 35\chapter{Introduction} 36 37One of the aims of writing PceDraw is to provide users of PCE who have 38made their first steps in using the system with an example that 39explains how large applications can be realised using PCE/Prolog. 40This document motivates the decisions taken to arrive at PceDraw, both 41at the level of the overall design and at the level of the detailed 42design and implementation. 43 44This document is part of the documentation of PCE-4. The complete 45documentation consists of: 46 47\begin{itemize} 48 \tick{Programming in PCE/Prolog \cite{PCE:Prolog}} 49This document is an introduction to programming in PCE/Prolog. It 50provides the background material to understand the other 51documentation. 52 \tick{PCE-4 Functional Overview \cite{PCE:overview}} 53This document provides an overview of the functionality provided by PCE. 54It may be used to find relevant PCE material to satisfy a particular 55functionality in your program. 56 \tick{PCE-4 User Defined Classes Manual \cite{PCE:udc}} 57This document describes the definition of PCE classes from Prolog. PceDraw 58is implemented as a set of user-defined classes. 59 \tick{The online PCE Reference Manual} 60The paper documents are intended to provide an overview of the 61functionality and architecture of PCE. The online manual provides 62detailed descriptions of classes, methods, etc.\ which may be accessed 63from various viewpoints. \cite{PCE:Prolog} describes how to 64use the online manual. 65\end{itemize} 66 67This document aims at PCE users who have understood the basics of PCE 68and have some experience with Prolog. In its final context (as an 69appendix) the tutorial should provide the necessary material. When 70new constructs are introduced in this document they are often 71explained. It is adviced to read chapter~\ref{sec:design} first and 72proceed with the introduction and the first section of 73chapter~\ref{sec:sources}. The remaining material may be used as a set 74of examples. At the end of this document is an index, indicating 75references to methods, predicates and files discussed. 76 77Chapter~\ref{sec:design} explains the overall design of 78PceDraw. Chapter~\ref{sec:sources} contains a brief overview of the 79organisation of the sources, followed by the annotated sources. 80 81Two chapters that will be part of the tutorial have been added as 82appedices to this manual. The first deals with style conventions 83for the definition of classes and the second with using global 84object references (e.g. @same_center). 85 86 87\chapter{Design} \label{sec:design} 88 89\section{Functional overview} 90 91PceDraw is a drawing tool for creating structured diagrams: 92flow-charts, diagrams capturing architecture, etc. In this kind of 93diagrams there is usually a small number of reoccurring shapes that 94have to be linked to each other. For this reason, the editor should 95allow the user to create/save/load a library of prototypes. A typical 96example of such a prototype is a box with centered text. Lines 97between shapes often represent semantical relations and therefore 98should remain connected to the shape if the shape is moved/resized and 99should be destroyed when the shape is deleted. 100 101This document aims at the software design and implementation of 102PceDraw and therefore the requirements analysis and functional 103specification is very brief. For getting a clear view on the 104functionality it is adviced to run PceDraw. It can be started from 105xpce by the command: 106 107\begin{code} 1081 ?- pcedraw. 109\end{code} 110 111PceDraw has been designed from these principles. The initial tool 112consist of three areas: the drawing area itself, a menu with available 113prototypes and a general command and feedback area. Besides creating, 114moving, resizing, etc., the tool must be able to edit shape attributes 115such as the thickness of the drawing pen and the font. This functionality 116is dealt with by an attribute editor which can be launched in a separate 117toplevel window. 118 119PceDraw provides two kinds of menu's. All commands are available 120through pulldown menus in the `command area' of the tool. Frequently 121used commands on a single shape are also available through a 122popup-menu associated with each shape. This approach has several 123advantages. The pulldown menus provide a place where all 124functionality can be found (except selecting a prototype and 125operations performed via direct-manipulation such as selecting, moving 126and resizing shapes), while the popup menus allows for fast access to 127the commonly used commands. 128 129\index{keyboard accelerators} 130The current version of PceDraw does not support keyboard accelerators. 131Defining accelerators should be supported by PCE's dialog primitives. 132This will be implemented later. 133 134 135\section{Realisation in PCE} 136 137After the functionality is specified, PCE primitives that serve as a 138starting point for the realisation be selected. It is hard to tell 139how this should be done. PCE contains a large amount of functionality 140that can be combined in several ways. Examples, the tutorial and the 141online manual (manpce/[0-1]) are the starting point. Below is a brief 142list with the main choices for PceDraw. See the various sourcefiles 143in chapter~\ref{sec:sources} for details. 144 145\begin{shortlist} 146 \tick{Overall tool} 147A {\em frame} is a collection of windows and provides an ideal 148starting point for the overall tool. 149 \tick{Drawing area} 150A {\em picture} is a window indended for displaying arbitrary 151graphical objects. 152 \tick{Prototype menu} 153Two possibilities: 1) {\em dialog} + {\em menu} + {\em menu_item} or 1542) {\em picture} + {\em bitmap}. See discussion in `menu.pl'. 155 \tick{Command area} 156A {\em dialog} with a list of pulldown menus organised in a {\em 157menu_bar} and a {\em label} for feedback messages. 158 \tick{Shapes} 159Appropriate PCE graphical (box, ellipse, text, line, etc.). 160 \tick{Prototypes} 161A {\em device} is a collection of graphicals that can be manipulated 162as a single unit. The <-klone method can be used to create instances. 163 \tick{`Settings' (or attribute) editor} 164A {\em dialog} window with appropriate {\em dialog_items} for the 165various settings. 166 \tick{(Direct) manipulation of shapes} 167{\em recognisers} can be attached to the various shapes. We can 168start from the various standard {\em gestures} defined in PCE. 169PceDraw can operate in various modes (select, create, edit_text, 170etc.). A mode attribute can be attached to the drawing area, where 171it can easily be found from the recognisers, so they can use it as 172a condition. 173 \tick{Load and Save} 174Both prototypes and drawings must be saved and loaded to/from Unix 175files. This can be realised using PCE's behaviour `Object ->save_in_file' 176and `File <-object'. 177\end{shortlist} 178 179 180\subsection{Creating an application} 181 182After we have selected the PCE building blocks from which to start, we 183have to extend them so that they fulfill our exact needs and cooperate 184to form the drawing tool. There are two ways to do this. The first 185is to regard PCE as a class/object library and extend/combine objects 186via `free-style' Prolog code. In this case our entire tool is (from 187the outside) a collection of Prolog predicates. The second 188possibility is to create subclasses from the basic PCE classes. Using 189the latter approach, the entire tool is a class of which an instance 190is created. What are the advantages of both approaches? We will look 191at them from an example. 192 193Suppose we have a drawing area and displaying an object on it should 194change a `modified' attribute associated with the drawing area. The 195PCE class picture is our starting point. Class picture does not 196have an instance variable `modified', so our task is to add such a 197variable and provide means to display an object on it and set the 198modified attribute. 199 200 201\subsubsection{Using PCE as a library} 202 203When using PCE as a library, the predefined objects and classes of PCE 204are regarded as a library of functionality we can access via the 205Prolog predicates new/2, send/[2-12] and get/[3-13]. There are two 206ways to modify or extend the behaviour of an object from a standard 207PCE class. The first is to write Prolog predicates that perform 208certain operations on the object(s). The second is to use PCE's 209object-level programming mechanisms to extend the object. Below is 210the code that results from using Prolog predicates. 211 212\begin{code} 213create_canvas(P) :- 214 new(P, picture), 215 send(P, attribute, attribute(modified, @off)). 216 217display_canvas(P, Graphical, Point) :- 218 send(P, display, Graphical, Point), 219 send(P, modified, @on). 220\end{code} 221 222Although this technique does not create a new (PCE) class, it does 223create a new `conceptual' kind of object: the canvas. `Display' is a 224method of this new kind. Depending on whether the method is defined 225in the PCE class or in Prolog, the behaviour should be invoked either 226via send/[2-12] or with the Prolog predicate: 227 228\begin{code} 2291 ?- send(P, selection, @nil). 2302 ?- display_canvas(P, box(30,30), @default). 231\end{code} 232 233The syntactical difference makes it clear whether the action initiates 234a Prolog predicate ---and thus a part of the application--- or a 235method of the PCE library. A programmer using this conceptual kind of 236object must be aware whether the method is part of PCE or part of the 237extension. Calling the raw PCE method might lead to inconsistencies: 238if the user invokes 239 240\begin{code} 2411 ?- send(P, display, box(30,30)). 242\end{code} 243 244the contents of the canvas will be modified, but the modified 245attribute won't change. 246 247\header{Extending the object} 248 249The second possibility uses programming PCE at the object level. 250Methods can be assigned to objects similiar to classes. The method 251object consists of three parts: the name or selector, the type 252specification and the action or message. The type specification is a 253vector with the same number of arguments as expected by the method. 254Each element of the vector specifies the corresponding type. See the 255online manual, topic `types'. While a message implementing a method 256is executed, @arg1 is bound the the first argument provided, @arg2 257to the second, etc. See also `Object ->send_method'. 258 259 260 261\begin{code} 262create_canvas(P) :- 263 new(P, picture), 264 send(P, attribute, attribute(modified, @off)), 265 send(P, send_method, 266 send_method(display, vector(graphical, '[point]'), 267 block(message(P, send_class, 268 display, @arg1, @arg2), 269 message(P, modified, @on)))). 270\end{code} 271 272Using this solution, the user of the canvas does not need to know that 273the ->display method of the raw PCE object has been redefined. The 274new object has a method named ->display which not only takes care of 275displaying the object, but also updates the modified attribute. Remaining 276problems are: 277 278\begin{shortlist} 279 \item PCE object are created using new/2, while application objects 280 area created via a Prolog predicate. 281 \item From the outside one cannot tell easily whether the object is 282 a raw PCE object or a modified one. 283 \item If many instances are created, each of them will have method 284 objects attached to them. 285 \item Writing code like this requires the user to know PCE's 286 programming classes (block, if, and, etc.). 287 \item If the implementation cannot be handled by PCE's programming 288 classes a message to @prolog is necessary. In this case the 289 implementation will be spread over two locations. 290 \item The code is attached to the object. If ---during debugging--- 291 this code needs to be changed there is little alternative then 292 destroying the object and recreating it. 293 \item If the object is saved using `Object ->save_in_file' or kloned 294 using `Object <-klone', the code part is saved/kloned as well. 295 \item It is difficult to read and write. 296\end{shortlist} 297 298Object level programming is not used intensively in PCE, but in 299some situations it is the best solution. 300 301 302\subsubsection{Extending PCE} 303 304The alternative provided by PCE-4 is to create a new class for the 305canvas. Creating a class is done using the normal PCE interface 306primitives new/2, send/[2-12] and get/[3-13], but a Prolog defined 307preprocessor based on the Edinburgh Prolog primitive term_expansion/2. 308This is our solution based on classes. 309 310The pce_begin_class/3 call creates class canvas as a subclass of (the 311predefined) class picture. Next, it asserts (using asserta/1) a 312clause for term_expansion/2 that will convert the class declarations. 313The optional last argument is the summary documentation of the class. 314The pce_end_class/0 call terminates the declaration by removing the 315clause for term_expansion/2. 316 317The variable/4 declaration is expanded to attach a new instance 318variable for the class. The arguments are the name, the type, the 319access rights and the optional summary documentation. The 320\verb$:->/2$ is expanded to define a send method for the class. The 321first argument is `self'. The remaining arguments are of the form 322\mbox{`PrologVar:PceType'}. The body may start with a line 323'\verb$"...."::$', which is recorded as the summary documentation of 324the method. The remainder is plain Prolog code. 325 326The method ->initialise is called from the PCE virtual machine (VM) to 327initialise the instance from the arguments provided with new/2. It 328should be there if the initialisation should do something in addition 329to the initialisation of the super-class. When defined, the ->initialise 330method should perform the initialisation of the super_class: 331 332\begin{code} 333send(Self, send_super, initialise, ...) 334\end{code} 335 336In this example, the variable <->modified must be initialised to @off. 337 338The ->display method as defined below redefines the built-in method of 339class picture by setting the modified flag. 340 341\begin{code} 342:- pce_begin_class(canvas, picture, "Drawing area"). 343 344variable(modified, bool, both, "Has diagram been modified"). 345 346initialise(C) :-> 347 send(C, send_super, initialise), 348 send(C, modified, @off). 349 350display(C, Gr:graphical, Pos:[point]) :-> 351 "Display graphical and set modified":: 352 send(C, send_super, display, Gr, Pos), 353 send(C, modified, @on). 354 355:- pce_end_class. 356\end{code} 357 358After this, we can use the class as if it were a predefined PCE class: 359 360\begin{code} 361 ... 362 new(C, canvas), 363 send(C, display, box(30,30)), 364 ... 365\end{code} 366 367User defined classes is one of the three possibilities to build an 368application in PCE. It does not have the disadvantages of introducing 369`conceptual' kinds using Prolog predicates, neither the disadvantages 370of using object-level programming. Complete applications however 371normally consist of a large number of objects with sometimes only 372slightly different behaviour. Using classes for each of these 373categories makes it difficult to avoid large amounts of awkward 374classnames. For this reason, using Prolog predicates or object level 375programming can be a good alternative for defining a class. It is 376adviced to use these techniques only for local communication and use 377class-level programming for global communication between components 378of the application. 379 380 381\subsubsection*{Extending vs. creating classes} 382 383PCE/Prolog allows both for extending the behaviour of existing classes 384and defining new ones. Extending classes implies redefining them, 385and should first of all be used to (temporary) overcome ommisions in 386the PCE system itself. Extending behaviour of existing classes may 387easily affect consistency of large applications, so be careful. 388 389For one case, extending PCE classes may be considered. Suppose we 390have an application that creates various subclasses of the various 391predefined subclasses of class graphical (e.g. box, circle, line) and 392all these classes need to have some common method that can be 393implemented at the level of the PCE class graphical. In this case 394it might be desirable to implement the method there instead of at 395each subclass. If you decide to do so, it is adviced to give the 396method a name that clearly indicates the application for which it was 397introduced, so no conflicts with other applications or future PCE 398extensions is to be feared.% 399\footnote{An alternative (and in this case better) solution to this 400problem would be to introduce multiple inheritance. Multiple 401inheritance however introduces various conceptual problems and in 402the current implementation of PCE unresolvable technical ones.} 403 404Creating new classes however does not affect the consistency of the 405system and provides a clean way to extend PCE. 406 407 408\section{Class organisation and communication} 409 410\subsection{Overall tool communication} 411 412The application as a whole is represented by an instance of class 413`draw', which is a subclass of the PCE class frame. Class draw serves 414as an overall manager of the various parts of the drawing tool. Class 415frame forms an ideal starting point to do this: 416 417\begin{shortlist} 418 \item 419Any graphical object (and almost anything in such a tool is a 420graphical object or is closely related to one) can easily find 421the reference to the tool as a whole using `Graphical <-frame'. 422 \item 423Class frame can easily find all its parts using `Frame <-member'. 424\end{shortlist} 425 426For this reason, the instance of class frame is the ideal part to 427support communication. For example, feedback can be centralised by 428defining a method ->feedback on the frame. Now, any graphical object 429can give feedback by doing: 430 431\begin{quote} 432 send(Myself?frame, feedback, 'I just did this'). 433\end{quote} 434 435 436\subsection{Drawing area and shapes} 437 438Picture and graphical are a communication couple. The drawing area of 439PceDraw is realised by class draw_canvas which is a subclass of 440picture. The various shapes that can be drawn are subclasses of 441closely related standard graphical classes (e.g. box, line). The pair 442canvas and shape adds responsiveness to user-events, maintenance of 443changes, etc. to the standard interaction between picture and 444graphical. 445 446 447\subsection{User Events (Shapes and gestures)} 448 449Shapes define the `Shape ->event' behaviour by forwarding the event 450to a reusable `gesture' object. A `gesture' is an object that 451allows for the management of a sequence of button-events, starting 452with a mouse-down and ending with the corresponding mouse-up. PCE 453defines several standard gestures. The file gesture.pl creates 454subclasses to implement the specific user-interface needed by 455PceDraw. 456 457\chapter{The Sources} \label{sec:sources} 458 459The application is subdivided into a number of files, each of which is a 460Prolog module file and defines a number of PCE classes that serve 461a similar role in the overall application. We use the Prolog module 462system to avoid possible name-conflicts with other packages for 463predicates used to support the methods. Below is an overview of the 464files. 465 466\begin{shortlist} 467 \tick{draw.pl} 468 Defines the toplevel predicates and the class `draw', of which 469 a drawing tool is an instance. Class draw is a subclass of 470 the PCE class `frame' 471 \tick{canvas.pl} 472 Defines class `draw_canvas'; a subclass of class picture. It is 473 the drawing area of the editor. 474 \tick{shapes.pl} 475 Defines the shapes that can be drawn on the canvas. These 476 shapes are small extensions to standard PCE classes. 477 They add handles for connections and handling user events. 478 \tick{gesture.pl} 479 Defines subclasses of the PCE gesture classes. These gestures 480 are linked to the shapes to process user events. 481 \tick{menu.pl} 482 Defines the menu at the right of the drawing area and 483 the (prototype) icons displayed on them. 484 \tick{attribute.pl} 485 Defines the attribute editor that can be used to modify the 486 attributes of graphical objects. 487 \tick{align.pl} 488 Defines the automatic alignment functionality. This file 489 is not included in the sources as it adds little to the 490 understanding of xpce. 491\end{shortlist} 492 493\header{Conventions} 494 495Each source file is given in a section named ``Source file name''. The 496actual code is preceded by small line numbers at the left margin. 497 498\include{draw} 499\include{canvas} 500\include{shapes} 501\include{gesture} 502\include{menu} 503\include{attribute} 504 505 506\chapter{Conclusions} 507 508In this document we presented a medium-sized application to illustrate 509how applications can be designed and realised using PCE. We have 510tried to make the design process and design decissions explicit. No 511doubth it is possible critise the code and decissions made. Nevertheless, 512we hope the sources of PceDraw form a valuable starting point for 513programming in PCE/Prolog. 514 515The drawing tool presented in this document may be used as such. It should 516be noted however that the functionality is incomplete. Notably editing 517prototypes is limited. 518 519 520\appendix 521 522\chapter{Programming Style} 523 524As O'Keefe argues in ``The craft of Prolog'' \cite{Keefe:90}, using a 525`good' programming style is not something optional. PCE/Prolog as 526presented in this document is definitely something different then 527Prolog with some additional library predicates. PceDraw as presented 528here is an example of what we currently believe to be good programming 529style. 530 531 532\section{Organisation of sourcefiles} 533 534The PCE class compiler allows for the definition of multiple classes 535in one file. Quintus Prolog compatible Prolog systems allow a file 536represent at most one Prolog module. What is the best way to organise 537your sources? There seem to be two reasonable solutions. 538 539Each file either represents a Prolog module and one PCE class, or a 540bundle of Prolog predicates. Files of the first type generally do not 541export any predicates. All communication is done by sending messages 542to instances of the class defined in the file. Files defining normal 543Prolog predicates do have an export list (otherwise we can't reach 544their contents). These predicates can be imported as usual. 545 546The second possibility is to define (small) classes that belong to 547each other or the same category in the same file (and module). 548Internally, these classes may communicate both using Prolog calls and 549by sending messages. 550 551 552\section{Organisation of a class definition} 553 554Below is a list of the various sections that make up a class 555definition. Except for the header and footer, all the sections are 556optional. Technically (currently) no ordering between the other 557sections is required. For clarity it is adviced to use a standard 558schema for all your classes. 559 560\begin{shortlist} 561 \tick{Header} 562This is just the \verb$:- pce_begin_class(Class, Super).$ declaration. 563 \tick{Instance variable declarations} 564The variable/[3-4] declarations for additional instance variables. 565 \tick{X-resource declarations} 566The resource/[3-4] declarations that provide access to the X-resource 567database. All aspects that are arbitrary default choices of the UI 568style should be declared via resources. This enhances clarity of the 569choices and allows the user to tailor the UI. 570 \tick{Handle declarations} 571The handle/4 declaration to create handles for connections. 572 \tick{Initialisation method} 573The initialisation method of a class normally comes first. It is 574invoked by the PCE vitual machine (VM) operation new() that creates 575an instance. Messages and predicates that only support the 576initialisation method (if it is very complicated; long 577initialisation methods can often be found for dialog windows) are 578defined right below the method. 579 \tick{Unlink method} 580The unlink method is invoked from the PCE VM operation that 581destroyes an instance. It is normally declared right after the 582initialisation method. 583 \tick{Other reserved methods} 584PCE's internals call various other methods that may be redefined. 585Examples are `Graphical ->geometry', `Graphical ->event' and 586`Gesture ->initiate'. These are normally declared before the 587other methods. 588 \tick{Public functionality} 589With this, we refer to methods that facilate the communication with 590other parts of the application. 591 \tick{Local utilities} 592Methods and Prolog predicates that are used from various places 593within this class definition are placed at the bottom. The reason for 594this is that one is usually not interrested in these things. 595 \tick{Footer} 596The \verb$:- pce_end_class.$ declaration terminates the declaration of 597the class. 598\end{shortlist} 599 600Section~\ref{sec:class-template} provides a template for the class 601declaration. 602 603\subsection{Class definition template} \label{sec:class-template} 604 605Italic words indicate text that should be filled in by the user. 606`...' denotes ``more of these''. 607 608\newcommand{\F}[1]{{\it #1}} 609\begin{pcecode} 610\tt\obeyspaces 611:- pce_begin_class(\F{Class}(...\F{TermDescriptionArguments}...), \F{Super}, 612 "\F{Documentation}"). 613 614variable(\F{Name}, \F{Type}, \F{Access}, "\F{Documentation}"). 615... 616 617resource(\F{Name}, \F{Type}, \F{Default}, "\F{Documentation}"). 618... 619 620handle(\F{X_FORMULA}, \F{Y_FORMULA}, \F{Kind}, \F{Name}). 621... 622 623 /******************************** 624 * CREATE/UNLINK * 625 ********************************/ 626 627initialise(\F{Self}, ...\F{Arg}:\F{Type}...) :-> 628 "Initialise from \F{Arguments}":: 629 \F{CheckArguments}, 630 send(\F{Self}, send_super, initialise, ...\F{SuperInitArgs}...), 631 \F{SpecificInitialisation}. 632 633unlink(\F{Self}) :-> 634 "\F{Documentation}":: 635 \F{SpecificUnlink}, 636 send(Self, send_super, unlink). 637 638 /******************************** 639 * RESERVED METHODS * 640 ********************************/ 641 642event(\F{Self}, Ev:event) :-> 643 "\F{Documentation}":: 644 ( send(\F{Recogniser}, event, Ev) 645 -> true 646 ; send(\F{Self}, send_super, event, Ev) 647 ). 648 649... 650 651 /******************************** 652 * PUBLIC METHODS * 653 ********************************/ 654 655\F{Sendmethod}(\F{Self}, ...\F{Arg}:\F{Type}...) :-> 656 "\F{Documentation}":: 657 \F{Implementation}. 658 659\F{Getmethod}(\F{Self}, ...\F{Arg}:\F{Type}..., \F{Result}) :<- 660 "\F{Documentation}":: 661 \F{Implementation}. 662 663 664 /******************************** 665 * UTILITIES * 666 ********************************/ 667 668\F{Methods}. 669... 670\F{Prologpredicates}. 671... 672 673:- pce_end_class. 674\end{pcecode} 675 676 677\section{Choosing names} 678 679Apart from the Prolog predicates and variables for which any Prolog 680oriented naming schema applies, various other objects have to be named 681while using PCE/Prolog. Names for PCE objects have either global 682scope or local scope to the class they are associated with. Names for 683classes and global objects are global. Names for selectors, variables 684and resource are local to their class. For all these names, the 685following should apply: 686 687\begin{shortlist} 688 \item Names with global scope over the entire process should be 689 short when they denote some very basic concept of the 690 application. Otherwise they are best prefixed with some 691 indication of the category they belong to (e.g. \verb$draw_$ 692 for all global names related to PceDraw). 693 \item Names with local scope (selectors, variables and resources) 694 have meaningful names. In general they should not be 695 abbreviations. When they denote a general operation, they 696 should be named to this operation (e.g. `quit', `relate'). 697 When they denote something very specific, something that 698 can be used only under some non-frequently occuring 699 situation, they should have long names. 700\end{shortlist} 701 702 703\section{Predicates or methods?} 704 705When writing in PCE/Prolog, there is usually the choice between 706writing a method and invoking this using send[2-12] or get/[3-13] or 707writing Prolog predicates and calling these directly. When using 708user-defined classes as the basis for structuring an application, the 709following rules apply: 710 711\begin{shortlist} 712 \item Communication between classes defined in different source-files 713 is always using messages. This way the overall structure 714 of the application is based upton one mechanism. 715 \item Within one sourcefile Prolog based activation/calling may 716 be used. This however should be limited to cases where: 717 \begin{enumerate} 718 \item Data that is not easily converted to PCE data is to 719 be passed as arguments. 720 \item Prolog backtracking should be exploited. 721 \item Communication is very time critical. 722 \item It implies a private unitily. 723 \end{enumerate} 724\end{shortlist} 725 726 727\section{Method arguments} 728 729Arguments to methods are determined by there location in the argument 730vector. PCE distinguishes between obligatory and optional 731arguments (i.e. arguments that may be @default). To avoid having to 732look in the manual continuously it is necessary to define some 733standards for argument ordering. The rules used inside PCE have never 734been stated explicitely and compatibility considerations sometimes 735leaded to non-intuitive arguments. Below is an attempt to make them 736explicit. 737 738\begin{itemize} 739 \item Do not use too many obligatory arguments. If possible try 740 to limit the number of obligatory arguments to 1 or 2. 741 `Name' or similar arguments in general come first. `Values' 742 (e.g. `dialog_item <->selection') come second. If there is 743 a sensible default or the user might not want to specify the 744 value because it will be filled in later, make the argument 745 optional. Example: initialising a line does not require 746 any arguments. Start and end-points default to (0,0). This 747 is useful as (notably for defining links), it is not unlikely 748 the user wishes to create a line and define the start and 749 end-point later. 750 \item Define sensible defaults the optional and order 751 them in decreasing `likelyness' the user might wish to overrule 752 the default. 753\end{itemize} 754 755 756\section{Layout conventions} 757 758The considerations for layout of PCE/Prolog programs do not differ 759very much from those for ordinary Prolog programs. PCE/Prolog 760programs tend to use deeply nested complex terms, notably while 761specifying message objects. The normal rules for breaking long 762terms apply. 763 764 765\bibliographystyle{name} 766\bibliography{pce} 767 768\printindex 769 770\end{document} 771