[PD] Idiomatic Pd

Enrique Erne enrique at netpd.org
Tue Jul 29 14:01:56 CEST 2008


Hi Luke

Luke Iannini wrote:
> There are some amazing sets of abstractions being released recently,
> which has served to highlight the many extant styles of patching.  I
> was wondering if there was interest in establishing a set of
> guidelines for patching in the vein of PEP 8 for Python; I've found
> that document to be very relaxing as it is a standardized approach to
> OCD.  More seriously, it greatly helps when reading other people's
> code or collaborating.
> http://www.python.org/dev/peps/pep-0008/
> 
> The only one I have seen so far for Pd covers best practices for
> layout.  I'd want to include that, but also codify naming, arguments,
> common idioms, and so on.
> 
> I've begun to collect some of my practices to start things off.  I was
> hoping we could all lazy-vote the document together in this thread and
> I'll then compile it into a PdPedia/Pd.info document.  So, feel free
> to object to or replace my propositions.
> 
> Style:
> * If giving $0 as an argument to an abstraction, it is always first in
> the argument list [1]
> * * When possible, pass parent arguments in numeric order, like [child
> $0 $1 $2 other1 other2] etc.
> * Sends and Receives are written in camelCase, with "R" appended to
> complementary receives (e.g. in GUIs, $0mySlider for the send and
> $0mySliderR for the receive)
> * When prepending $0 to a symbol, only add a "-" to separate it from
> another number, like [r $0-1stSend].  Otherwise the symbol should
> immediately follow, like [r $0mySend].

i arbitrary use ".", "-" and "_" . IMO a separator in a send/receive 
name is needed when you use a dollar, and i would welcome a guideline, 
especially if there is a certification and quality brand for pd-patches :)

but there are so many styles and i don't even know which way to declare 
an external.

now a bit personal: i don't like $0 :) . It's fine for a namespace 
within a patch, but I found myself often needing to access something 
from "outside" so i have to pass $0 around, which is ugly. I much more 
prefer a global receiver and route everything. so i pass the name of my 
patch to it's abstractions. abstracions get global receiver with $1 in 
it which is the motherpatchname.
it helps for orientation i.e. look at the window title:

yourabstraction.pd (mother)
isn't it better than:
yourabstraction.pd (1284)

you can even use it for [sssad $1/vol] without having the $0 making your 
sssad key into a unusable name. If I have GUI inside the GOP each 
sliders send and receive name begin with $1. or $1- or $1_ (guideline 
please!), that makes it possible to hijack the patch from an other 
patch. Like the midilearn or automator patch can control any slider in 
this setup.

Franks recommendation UPPERCASE for globals is really neat.

For GUI elements like sliders I've never regret to use a kind of name
hierarchy ($1.vol), usually
mypatch-myabs-myparameter or
mypatch.myabs.myparameter or
mypatch_myabs_myparameter or whatever. so you can hijack your channel
aux-sender with anything.

but that means you can't open a patch multiple times, no problem for me 
because i reuse code always with abstractions.

does somebody run 1 patch multiple times?
(sounds like fun would you mind and share?)


i look forward to the lazy-vote :)

eni



> * When working with stereo, Left and Right pairs are written with Le
> and Ri appended (to distinguish them from an R denoting "receive",
> above)
> 
> Programming recommendations
> * To invert a toggle, use [== 0]
> * Use the loadbang of the parent of both abstractions to initialize
> two or more interdependent abstractions
> 
> [1] I think of this like emulating the "self" convention in Python
> 

Programming recommendations

always use [trigger] for 1tomany connections

















More information about the Pd-list mailing list