Pattern: External Method Selectors


Context

There are frequently a large number of functions in any external library. Implementing all the functions would consume a large amount of time, and waste memory in unused methods. However, if methods are implemented as needed, a standard form for the method selectors is required to simplify creating, reading and finding such methods, and avoid the possibility of multiple definitions of the same method with different names.

Solution

Use an algorithm to generate suitable keyword selectors from the function help or header file prototype. The algorithm permits no choices, preventing name collisions, and problems merging when more than one party adds the same external function.

A suitable algorithm is:

Two different people should always come up with the same selector name from the same help file definition.

Example

appendMenu: hMenuDrop uFlags: styleFlags uIDNewItem: menuId lpNewItem: menuText
	"Appends a new item to the end of the specified menu with the specified
	style, identifier and text.

	BOOL AppendMenu(
		HMENU hMenu,		// handle to menu
		UINT uFlags,		// menu item flags
		UINT uIDNewItem,	// menu item identifier or pop-up menu handle 
		LPCTSTR lpNewItem	// menu item content
		);"

	<stdcall: bool AppendMenuA handle dword dword lpstr>
	^self invalidCall

Known Uses

All external methods in the base system libraries (e.g. UserLibrary, KernelLibrary) have selectors generated in this way.

Related Patterns