Another option that has merits is 'Named
Parameters'. It is another way of handling
optional arguments. You simply name which of the
optional arguments you are supplying.
It won't necessarily shorten the amount of typing. It can't handle cases where groups of
optional parameters are required to be specified if any of them are specified (though I can't think of much that would fit this case).
It would keep compatibility with older code because the
optional parameters can still be specified by their order and wouldn't change the way the procedure declarations are made. It would increase the complexity of parsing the code for compiling because the
optional parameters would have their names matched. It would give some freedom in determining the order of the
optional parameters (which can be a source of frustration) for both the users and the creator of the language.
Here are a lot of examples:
Code: Select all
AddStaticGeometryEntity(0, 10, 5, -2, 5, ScaleZ: 2.2, RotateY: -1.6)
ApplyEntityForce(0, 10, 5, 2, PositionX: -1.0)
AttachEntityObject(0, "leg", 3, Yaw: 19.3)
BindEvent(#PB_Event_Gadget, @GadgetHandler(), EventType:#PB_EventType_LeftClick)
CompareMemoryString(*String1, *String2 , Flags:#PB_UTF8)
CreateCylinder(#Mesh, 3.2, 5, VerticalShift:1)
CreateImage(#Image, 500, 400, BackColor:RGB($10, $F0, $40))
CreateText3D(#Text3D, "Testing", Color:RGB(0, 0, $FF))
Date(Year:2014, Month:m)
DisplayTransparentSprite(#Sprite, 10, 12, Color:RGB($FF, $FF, $FF))
DrawText(x, y, Text$, BackColor:RGB(255, 128, 128))
FillMemory(*Memory, Size, Type:#PB_Word)
FindString(String$, "Fred", Mode:#PB_String_NoCase)
NodeLookAt(#Node, 2, -3, 15.2, DirectionZ: 0.35)
OpenScreen(1280, 800, 32, "Game", RefreshRate:60)
OpenWindowedScreen(WindowID(0), 0, 0, 500, 300, #True, FlipMode:#PB_Screen_NoSynchronization) ;AutoStretch specified positionally
PokeS(*Buffer, "Hello World", Flags:#PB_UTF8)
PostEvent(#PB_Event_Gadget, Object:3, Data:*data)
RemoveString(String$, "bug", NbOccurrences:3)
SaveImage(#Image, Filename$, Depth:8)
TransformSprite(#Sprite, x1, y1, x2, y2, x3, y3, x4, y4, z1:15, z4:15) ;this is a unusual example
It would be useful anywhere the
optional parameters are numerous (just look at the 3D and multimedia libraries).