Archive for the ‘naming’ Category
objects and web scripting
scripting typically involves creating objects in order to execute certain tasks to achieve a desired outcome. and so … how do i create an object? it sounds silly, really. but, honest … its abstract … a tough concept around which to wrap one’s head. its the core of modern-day programming, though. so i had better start getting it.
object creation involves 2 steps.
(1). create an object definition ~ the code containing methods and properties of the object. methods ~ directions for making the object. properties ~ characteristics that typify the object.
create a constructor function ~ a named group of 1 or more programming statements that can create new objects. note – by convention, capitalize the first letter of a constructor function.
add properties ~ identified by object name “dot” property name. refer to the newly created, not yet instantiated objects as “this”
objectName.propertyName = value
add methods ~ (methods = functions called from within the method.) name the method, assign a function. use action words when naming methods. identified using the syntax below. (argument = input to subroutine … used to assign a value to a property of the new object)
objectName.methodName(arguement)
(2) instantiation ~ create an instance of the newly defined object. specify a unique name for the new object. assign the object to the recently created object definition using the “new” keyword.
steps in object instantion ~ variable assigned a value ~ variable value passed as a parameter (parameters act as local copies of the argument) to the new object ~ parameter used to assign variable value to an object property ~ object property used by the object’s show method ~ show calls the object’s display method, which writs to the browser.
naming conventions
classes ~ nouns, in mixed case with the first letter of each internal word capitalized. Try to keep your class names simple and descriptive. Use whole words-avoid acronyms and abbreviations (unless the abbreviation is much more widely used than the long form
interfaces ~ capitalized like class names.
methods ~ verbs, in mixed case with the first letter lowercase, with the first letter of each internal word capitalized.
constants ~ upper case letters and words separated by underscore
variables ~ mixed case with a lowercase first letter. Internal words start with capital letters. Variable names should not start with underscore _ or dollar sign $ characters, even though both are allowed. Variable names should be short yet meaningful. The choice of a variable name should be mnemonic- that is, designed to indicate to the casual observer the intent of its use. One-character variable names should be avoided except for temporary “throwaway” variables. Common names for temporary variables are i, j, k, m, and n for integers; c, d, and e for characters.
Leave a Comment
Leave a Comment







