angular-package
TwitterGitHub
Designing
Designing
  • Introduction
  • Definitions
    • Adjective: noun
    • Cohesion: noun
    • Cohesive: adjective
    • Cohesiveness: noun
    • Complex: adjective, noun
    • Complexity: noun
    • Consistency: noun
    • Consistent: adjective
    • Constantly: adverb
    • Diagnosis: noun
    • Functional: adjective
    • Functionality: noun
    • Get: verb
    • Have: verb
    • Immutable: adjective
    • Independent
    • Interdependence
    • Intuition: noun
    • Intuitive: adjective
    • Intuitiveness: noun
    • Is: verb
    • Logic: noun
    • Minimalism: noun
    • Mutable: adjective
    • Noun: noun
    • Phrase: noun, verb
    • Prefix: noun, verb
    • Preposition: noun
    • Purpose: noun
    • Replace: verb
    • Set: verb
    • Simplicity: noun
    • Suffix: noun, verb
    • Text: noun, verb
    • To: preposition
    • Verb: noun
  • Principles
    • String Wrapper Objects
  • Design processes
    • String Wrapper Objects
      • Methods usage analysis
      • Relevant questions
      • Investigation
      • Method names analysis
    • Wrap {}
      • Analysis
      • Accessors
      • Properties
      • Methods
        • hasOpening()
        • isWrapped()
    • Wrapper
  • Benefits
    • String Wrapper Object
      • Explanation
  • Other
    • @ Contact
    • ฿ Donate
Powered by GitBook
On this page
  • Possible actions
  • Approaches
  • One
  • Two
  • Three
  • Four
  • Five
  • Six
  • Seven
  • Eight
  • Nine
  • Conclusion

Was this helpful?

  1. Design processes
  2. String Wrapper Objects

Method names analysis

PreviousInvestigationNextWrap {}

Last updated 3 years ago

Was this helpful?

It is worth checking only the method name, not including the object and its functionality, because then it's possible to achieve constant intuitive method names, at first sight, indicating its meaning. The need is also to have the same parameters.

This page covers building the method names using the approaches of the page ''. Method names consist of selected words, and among others, there are verbs, prepositions, and nouns in a specific order, where can be found and . The methods perform actions, and the first step is to create a small list of them.

Possible actions

There are possible actions that can be performed on an instance, and the following list contains a few general words that are used to build method name structures below.

  • exec ()

  • get () Indicates a direction pick-out.

  • has () (Indicating possibility) Indicates a direction pick-check-out.

  • is (a state of being ) Indicates a direction pick-check-out.

  • replace () Indicates a direction pick-change-out.

  • set () Indicates a direction pick-change-in.

  • to () Indicates a direction pick-(change)-out.

  • wrap ( or ) Indicates a direction pick-change-out.

Approaches

The nine following approaches show possible name structures that clarify the method naming methodology. The method name structure is built from a few simple brackets, with the description and type, like in the following example.

[ action: verb | noun ][ what: noun | verb ]([ parameter: noun ])

One

The method without parameters gets the primitive value and returns a primitive value.

get()

[ get: verb ]()

new Wrap('<', '>', 'span').get(); // Returns <span>

getPrimitive()

[ get: verb ][ Primitive: noun ]()

new Wrap('<', '>', 'span').getPrimitive(); // Returns <span>

getWrap()

[ get: verb ][ Wrap: noun ]()

new Wrap('<', '>', 'span').getWrap(); // Returns <span>

toPrimitive()

[ to: preposition ][ Primitive: noun ]()

new Wrap('<', '>', 'span').toPrimitive(); // Returns <span>

toString()

[ to: preposition ][ String: noun ]()

new Wrap('<', '>').toString(); // Returns <>

valueOf()

[ value: noun ][ Of: preposition ]()

new Wrap('<', '>').valueOf(); // Returns <>

Conclusion

The simple method names with prefixes like a verb, preposition, or even noun return the primitive value of a specified object.

  • The actions assigned to this approach are get and to indicate getting the primitive value.

  • The action get without the following word indicates the return of the primitive value.

Two

The method without parameters gets the primitive value and performs an action on it based on the intuitive method name, and returns the changed primitive value.

big()

[ big: verb ]()

new String('text').big() // Returns <big>text</big>
new Wrap('<', '>').big(); // Returns <big><></big>

bold()

[ bold: verb ]()

new String('text').bold(); // Returns <b>text</b>
new Wrap('<', '>', 'span').bold(); // Returns <b><span></b>

Conclusion

  • One of the exceptions is the 'wrap' word cause it's a verb and noun.

Three

The method with parameters gets the primitive value and performs an action on it based on the intuitive method name with the use of its parameters and returns the changed primitive value.

replace(searchValue: string, replaceValue: string)

[ replace: verb ]([ searchValue: noun ], [ replaceValue: noun ])

new String('text').replace('e', 'E'); // Returns tExt
new Wrapper('<', '>', 'span').replace('a', 'A'); // Returns <spAn>

wrap(opening: string, closing: string)

[ wrap: verb ]([ opening: noun ], [ closing: noun ])

new Wrapper('<', '>', 'span').wrap('{', '}'); // Returns {<span>}
new Wrapper('', '', 'span').wrap('{', '}'); // Returns {span}

wrapText(opening: string, closing: string)

[ wrap: verb ][ Text: noun ]([ opening: noun ], [ closing: noun ])

new Wrapper('<', '>', 'span').wrapText('{', '}'); // Returns <{span}>

wrapOpening(opening: string, closing: string)

[ wrap: verb ][ Opening: noun ]([ opening: noun ], [ closing: noun ])

new Wrapper('<', '>', 'span').wrapOpening('{', '}'); // Returns {<}span>
new Wrapper('', '>', 'span').wrapOpening('{', '}'); // Returns {}span>

What should be returned in this method, the primitive value with changed opening or wrapped opening? The following method could be an answer.

openingWrap(opening: string, closing: string)

[ opening: noun ][ Wrap: verb ]([ opening: noun ], [ closing: noun ])

// Returns {<}span> or {<}
new Wrapper('<', '>', 'span').openingWrap('{', '}'); // Returns {<}

The action(verb, preposition) following the object indicates performing this action on the primitive value. The noun indicates getting the property to perform on it. The result of this method should be a wrapped opening {>}.

replaceOpening(opening: string)

[ replace: verb ][ Opening: noun ]([ opening: noun ])

new Wrapper('<', '>', 'span').replaceOpening('{'); // Returns {span>
new Wrapper('<', '', 'span').replaceOpening('{'); // Returns {span>
new Wrapper('<', '>', 'span').replaceOpening('{{{'); // Returns {{{span>

replaceClosing(closing: string)

[ replace: verb ][ Closing: noun ]([ closing: noun ])

new Wrapper('<', '>', 'span').replaceClosing('}'); // Returns <span}
new Wrapper('<', '', 'span').replaceClosing('}'); // Returns <span}
new Wrapper('<', '>', 'span').replaceClosing('}}}'); // Returns <span}}}

replaceText(text: string)

[ replace: verb ][ Text: noun ]([ text: noun ])

new Wrapper('{', '}', 'span').replaceText('div'); // Returns {div}

Conclusion

  • The actions assigned to this approach are replace, wrap.

  • If the object is followed by a verb the method changes the primitive value or its parts and returns the changed primitive value.

  • If the object is followed by a noun the method changes the primitive value part and returns it.

Four

The method without parameters gets part of the primitive value and returns it.

getOpening()

[ get: verb ][ Opening: noun ]()

new Wrapper('<', '>', 'span').getOpening(); // Returns <
new Wrapper('', '>', 'span').getOpening(); // Returns empty string

getClosing()

[ get: verb ][ Closing: noun ]()

new Wrapper('<', '>', 'span').getClosing(); // Returns >
new Wrapper('<', '', 'span').getClosing(); // Returns empty string

getText()

[ get: verb ][ Text: noun ]()

new Wrapper('<', '>', 'span').getText(); // Returns span
new Wrapper('<', '>', '').getText(); // Returns empty string
new Wrapper('<', '>').getText(); // Returns empty string

Conclusion

  • The action assigned to this approach is get.

  • The action get following the object name with the following noun indicates return value is a part of the primitive value.

Five

The method without parameters checks the existence of the part of the primitive value in the object and returns the result.

hasOpening()

[ has: verb ][ Opening: noun ]()

new Wrap('<', '>', 'span').hasOpening(); // Returns true
new Wrap('', '>', 'span').hasOpening(); // Returns false

hasClosing()

[ has: verb ][ Closing: noun ]()

new Wrapper('<', '>', 'span').hasClosing(); // Returns true
new Wrapper('<', '', 'span').hasClosing(); // Returns false

hasText()

[ has: verb ][ Text: noun ]()

new Wrapper('<', '>', 'span').hasText(); // Returns true
new Wrapper('<', '>', '').hasText(); // Returns false
new Wrapper('<', '>').hasText(); // Returns false

isWrapped()

[ is: verb ][ Wrapped: noun ]()

new Wrapper('<', '>', 'span').isWrapped(); // Returns true

openingHas()

[ opening: noun ][ Has: verb ]()

new Wrap('<', '>', 'span').openingHas();

The method name without a noun after the verb has seems useless.

Conclusion

  • The actions assigned to this approach are has, is.

  • When a verb follows the object and a noun follows the verb, the method checks the part of the primitive value.

  • When a noun following the object refers to the primitive value part, the following verb indicates perform on it.

Six

The method with parameters checks the existence of the part of the primitive value in the object and returns the result.

hasOpening(opening: string)

[ has: verb ][ Opening: noun ]([ opening: noun ])

new Wrap('<', '>', 'span').hasOpening('<'); // Returns true
new Wrap('<', '>', 'span').hasOpening('{'); // Returns false
new Wrap('', '>', 'span').hasOpening('<'); // Returns false

hasClosing(closing: string)

[ has: verb ][ Closing: noun ]([ closing: noun ])

new Wrapper('<', '>', 'span').hasClosing('>'); // Returns true
new Wrapper('<', '>', 'span').hasClosing('{'); // Returns false
new Wrapper('<', '', 'span').hasClosing('>'); // Returns false

hasText(text: string)

[ has: verb ][ Text: noun ]([ text: noun ])

new Wrapper('<', '>', 'span').hasText('span'); // Returns true
new Wrapper('<', '>', 'span').hasText('div'); // Returns false
new Wrapper('<', '>', '').hasText(''); // Returns false
new Wrapper('<', '>').hasText(''); // Returns false

isWrapped(opening: string, closing: string)

[ is: verb ][ Wrapped: noun ]([ opening: noun, closing: noun ])

new Wrapper('<', '>', 'span').isWrapped('<', '>'); // Returns true
new Wrapper('<', '>', 'span').isWrapped('{', '>'); // Returns false
new Wrapper('<', '>', 'span').isWrapped('<', '}'); // Returns false
new Wrapper('<', '>', '').isWrapped('<', '>'); // Returns true

Conclusion

  • The actions assigned to this approach are has, is.

Seven

The method without parameters checks the existence of the part of the primitive value in the part of the primitive and returns the result.

textHasOpening()

[ text: noun ][ Has: verb ][ Opening: noun ]()

new Wrap('<', '>', 'span').textHasOpening(); // Returns false
new Wrap('<', '>', '<span').textHasOpening(); // Returns true
new Wrap('<', '>', '<span').textHasOpening(); // Returns true

The method checks whether the span text has the opening <.

textHasClosing()

[ text: noun ][ Has: verb ][ Closing: noun ]()

new Wrapper('<', '>', 'span').textHasClosing(); // Returns false

The method checks whether the span text has the closing >. Let's add a parameter to the method.

textHasOpening(opening: string)

[ text: noun ][ Has: verb ][ Opening: noun ]([ opening: noun ])

new Wrap('<', '>', 'span').textHasOpening('<'); // Returns false
new Wrap('<', '>', '<span').textHasOpening('<'); // Returns true

The method gets the text and checks whether it contains the given opening chars.

isTextWrapped(opening: string, closing: string)

[ is: verb ][ Text: noun ][ Wrapped: noun ]([ opening: noun, closing: noun ])

new Wrapper('<', '>', '<span>').isTextWrapped('<', '>'); // Returns true
new Wrapper('<', '>', '{span}').isTextWrapped('{', '}'); // Returns true
new Wrapper('<', '>', 'span').isTextWrapped('<', '>'); // Returns false
new Wrapper('<', '>', '').isTextWrapped('<', '>'); // Returns false
new Wrapper('<', '>').isTextWrapped('<', '>'); // Returns false

The method checks whether the span text has the opening < and closing >.

Conclusion

  • The actions assigned to this approach are has, is.

  • If the object is followed by a noun the method changes the primitive value part and returns it.

Eight

The method with parameters gets the parts of the primitive value to perform action appropriate to the intuitive method name on given method parameter(s).

For example, let's try to wrap the text given in the method's parameter with the opening and closing of the Wrapper object.

wrapText(text: string)

[ wrap: verb ][ Text: noun ]([ text: noun ])

// The text is wrapped and returns wrapped text.
new Wrapper('{', '}', 'span').wrapText('div'); // Returns {div}

Even by swapping the words, the method name is still not intuitive. Cause of thinking that the text span is picked from the object, and the action Wrap is performed on it.

textWrap(text: string)

[ text: noun ][ Wrap: verb ]([ text: noun ])

// Returns divspan or {div}
new Wrapper('{', '}', 'span').textWrap('div'); // Returns {div}

The question is how to properly differentiate method names to achieve intuitiveness and consistency in method naming for both approaches. The method's name should indicate the use of opening and closing chars to wrap the text given in the method's parameter.

The meaningful solution is the use of in and on prepositions, then the methods meaning should indicate use of primitive value parts.

For example, adding at the end of the replaceOpening name the In preposition results in the replaceOpeningIn method name. The name suggests replacing the opening in something, and the something is the given text.

replaceOpeningIn(text: string)

[ replace: verb ][ Opening: noun ][ In: preposition ]([ text: noun ])

new Wrapper('{', '}', 'span').replaceOpeningIn('{div}', '<'); // Returns <div}

Use the On preposition after the verb Wrap should intuitively indicate wrap on something outside.

wrapOn(text: string)

[ wrap: noun ][ On: preposition ]([ text: noun ])

new Wrapper('<', '>', 'span').wrapOn('div'); // Returns

isClosingIn(text: string)

[ is: verb ][ Closing: noun ][ In: preposition ]([ text: noun ])

new Wrapper('{', '}', 'span').isClosingIn('{div}'); // Returns true
new Wrapper('{', '>', 'span').isClosingIn('{div}'); // Returns false
new Wrapper('{', '', 'span').isClosingIn('{div'); // Returns false

The method checks whether the given text has the closing of the Wrapper instance. It's possible to get part of the primitive value first, and then perform an action on it in the direction specified by the In preposition with the name closingIsIn.

closingIsIn(text: string)

[ closing: noun ][ Is: verb ][ In: preposition ]([ text: noun ])

new Wrapper('{', '}', 'span').closingIsIn('{div}'); // Returns true
new Wrapper('{', '>', 'span').closingIsIn('{div}'); // Returns false
new Wrapper('{', '', 'span').closingIsIn('{div'); // Returns false

The method checks whether the picked closing of the Wrapper instance is in the given text.

Conclusion

  • Prepositions indicate directions.

  • Intuitively an action without a noun following the object indicates the change on the primitive value, but the following noun indicates the pick of the primitive value part for possible perform change.

  • There is a constant value in the Wrapper object, and the difference is in the method's parameters. The Wrapper can wrap multiple texts or wrap the part of the primitive value text with multiple opening and closing chars.

Nine

The method without parameters converts the part of the primitive value into another form, for example, object or array.

toArray()

[ to: preposition ][ Array: noun ]()

new Wrapper('<', '>', 'span').toArray(); // Returns ['<', 'span', '>']

toWrap()

[ to: preposition ][ Wrap: noun ]()

new Wrapper('<', '>', 'span').toArray(); // Returns Wrap {'<span>'}

Conclusion

Analysis of possible structures above gives answers that can help prepare some method names useful in the Wrap and Wrapper objects.

I see it also as a material for creating general principles of designing primitive wrapper objects for angular-package.

Especially the method name indicates that the noun value is like a property picked with the following action performed on it. This way of thinking where the method name first word denotes getting the property is helpful in and .

These methods are native methods of the object, and their meaning is to transform the primitive value to the bold or big. No words in their names are informing about how they behave. They could have added prepositions, for example, '' to get toBig() or toBold(), but are they necessary? However, these methods are denoted as deprecated.

It seems better to have a instead of a in the method name of one word because nouns are reserved names for properties or accessors.

Following intuitiveness of native method the wrap method should return the primitive value of the Wrapper after replacing.

Previous teaches that a noun after the verb, for example, returns the primitive value, not part of it. The following examples behave differently cause they return part of the primitive value, having the same method name structure.

These method names refer to primitive value parts and return them. We would say the action of get returns part of the primitive value, but the examples of make it ambiguous.

Including the action get does not indicate the return value, but the following noun does. The action get without the following word indicates the return of the primitive value.

The method names seem to be obvious, instead of the last one. If the words are swapped their meaning is changed. The method indicates the opening has something, and that something should be provided as the method's parameter.

The use of such methods is questionable. A noun following the object indicates the obtaining action similar to the method.

An interesting thing about this approach is, it seems the same as approach '' above. It also changes the primitive value, but not exactly, because its idea is to use part of the primitive value to change the given method's parameter.

The method from indicates that the object followed by action means the use method's parameters to wrap the primitive value. Because this approach's way of thinking and conflicted parameters with the method from approach , the method is not intuitive.

We could think the method wraps the text span with the provided opening div, as in approach '' example above. However, this forces to achieve that the div text is wrapped by the opening { and closing } resulting {div}. The method name should indicate its functionality.

The method works like a with the exact meaning of a specific replace in name, and it should return a changed primitive value, like the method.

Crucial question is what the method should return, the Wrap instance or the primitive value. Because the Wrapper contains all the needed properties it seems no sense to return the Wrap instance and better to return the primitive value.

methods usage analysis
intuitiveness
functionality
noun
verb
verb
verb
verb
verb
preposition
verb
noun
String
to
verb
noun
replace()
valueOf()
approach eight
approach three
approach three
replaceText()
approach one
approach one
openingHas()
openingWrap()
three
intuitively
wrap()
approach three
wrapText()
three
wrapText()
three
replace()
replaceText()
wrapOn()