|
By: Kevin Picone I N D E X:
Naming Convention Overview It's doesn't matter if you've just started programming or have been at it for decades, learning a new language can be fairly confronting. Which is odd when you think about it, since most high level programming languages (BASIC in Particular) share a lot of design similarities. What tends to change is the structural format rules and naming conventions used. BASIC, like all high level languages takes a more English approach to command naming. The theory being, the closer to English the language is, the more readable and therefore easier it is to learn. While there are BASIC standards in place, they're neither current, nor enforced. Therefore adherence to such standards today isn't widely embraced. As such, languages using the BASIC dialect tend to come in many different flavors. PlayBASIC is no exception. With PlayBASIC we wanted to hold onto the frame work of BASIC, while trying to keep command names consistent. Therefore there are various naming rules we've employed throughout the language. Some of which break with tradition, some are not. An example of this might be the approach we've taken in setting & retrieving properties. PlayBASIC commands are generally reversible. Therefore if you can set a property, you read this property back by using the same command name with Get prefix appended. I.e. SpriteDrawMode & GetSpriteDrawMode() are a set/get pair. The purpose of this approach has been to make the PB easier both to read and remember. The better you can remember the commands name the easier it is to learn. Throughout PlayBASIC there's a few universally used prefixes across the various command sets. These keywords indicate Appling a particular action to a particular media type. Some examples of such keywords/actions are Create/Delete/Draw/New/Get/Position/Load etc. So effectively this means you can mix a prefix with a media type and end up with a valid command name. E.g. CreateSprite, CreateImage, NewSprite(), NewImage(), DrawSprite, DrawImage etc. This same formula is used right across the command sets. So once you come to terms with the naming convention, you can easily guess command names, even if you've never used the command set before. We've done this to try make the language readable for new programmers Packed Command Names All command names in PlayBASIC use a packed word format for command names. Therefore PlayBASIC expects multi word command names to be packed to together without separating spaces. For example, lets say we wish to create a sprite. We've therefore type the Create action prefix in front of the media type, which in this case a Sprite. While it might be more intuitive/English like to type 'Create Sprite', PlayBASIC will be unable to resolve your intent. Hence we need to pack the words together "CreateSprite". Now it can easily find the Create Sprite function and execute it accordingly. End Prefix In Structural Commands In PlayBASIC, most structural commands (declarations / decisions & comparisons) come in statement pairs. So we have the opening statement and a closing statement. This closing statement will use the End prefix attached to the opening statements name. Examples,
Those with previous BASIC experience might have noticed a break with tradition here in regards to the WHILE statement. As While is paired with the WEND in some dialects of the BASIC. Create (Manual), GetFree vs New (Dynamic) Media Creation PlayBASIC offers users a choice of two different approaches when it comes to the creation and management of command set Media. Those being (Manual & Dynamic. The difference applies to who allocates the media index for the entity in question. The Create prefix implies that the user wishes to nominate the media index manually, while the New keyword/ means the user wants PlayBASIC to do it for is. Regardless of the approach however, all the media entities are stored within the same container. For example lets say we wish to create a blank image. For manually creation (ie. the user supplies the image index) we've use CreateImage ImageIndex,Width,Height, were as for dynamic creation we'd use ImageIndex=NewImage(Width,Height) While the many modern BASIC dialects only use latter dynamic approach, there's advantages and disadvantages to both. However often approach you choose, generally comes down to personal preference. Getting A Property Frequently when utilizing the PlayBASIC command sets, we'll commonly be either creating/setting up media or retrieving information from a particular media entity. In PlayBASIC to retrieve information we use the "Get" prefix. Therefore most commands that set media properties can be reversed to retrieve the property, just by appending the Get prefix to the command name. For example, in order to set a sprites collision mode, we'd use the SpriteCollisionMode command to set this property in a sprite. If we want to retrieve this property, we'd append the get prefix to the set command name, which would give us GetSpriteCollisionMode() Exceptions ? Like all the best laid plans there are a few exceptions when comes to the Get prefix rule. Most notably we'll encounter them when we need to retrieve more the one piece of information about a media property. Probably the most common example would be setting and retiring a sprites position. While there a number of commands to position a sprite (PositionSprite, PositionSpriteX,PositionSpriteY, MoveSprite ), these are not reversible, as implementing get just don't make sense linguistically Ie. GetPositionSprite, GetPositionSpriteX etc. So in these case to retrieve it's current position we use Get prefix attached to the media type and the Axis (X,Y,Z) where interested in. Ie GetSpriteX, GetSpriteY, GetSpriteX |
Related Info: | ArrayBasics | Images | Libraries | Loops | Operators | ProgramLayout | Types | Variables : |
|
|||||||||||||||||||||||||||||||||||||||
(c) Copyright 2002 - 2024 - Kevin Picone - PlayBASIC.com |