Download - Naming methods

Transcript
Page 1: Naming methods

Naming methods

Page 2: Naming methods

Advanced Web Tech specialist

Kwork Innovations

Page 3: Naming methods
Page 4: Naming methods

Differences in meaning

Page 5: Naming methods

Method naming structures

Page 6: Naming methods

Conventions

Page 7: Naming methods

Microsoft Guidelines

Page 8: Naming methods

Not all Microsoft Frameworks follow MS guideline

–.NET BCL (Base Class Library):– String.Substring(), String.IndexOf() …

–LINQ– .First(), .Last().

–HTML Helper– Html.EditorFor(), HTML.LabelFor(), HTML.ValidationSummary()

Microsoft Guidelines

Page 9: Naming methods

Common wisdom

Page 10: Naming methods

Alternatives

Page 11: Naming methods

Top verbs

GetIsSetToCreateAddWriteFromReadCount

TryHasCanFormatUpdateRemoveShowFindSendValidate

ResolveCallMoveRegisterDeleteSerializeSelectLinkBindDrag

FocusEditClearThrowStripProcessExecuteLockCopyCancel

WaitApplyStoreSkipQueueCompareOrderCommitTransformReturn

DownloadExpandSortLimitExportVerifyIncludeMakeRefreshExit

Page 12: Naming methods

Option 1: To verb or not to verb

GetLength() => Length() => Count()

Single-verb is better than single-noun is better than verb+noun

Transactional, I/O operation and state-change need a verb

Email.HTML() => Email.SendHTML()

Noun is better than long sentence for getting a value

GetSquareRootOf => SquareRootOf()

Page 13: Naming methods

Option 2: Always verb

GetLength() => Count()

Specific verb is better than verb+noun

Always use a verb

Email.HTML() => Email.SendHTML()

Page 14: Naming methods

Microsoft Framework Design guidelines: General naming conventions

Page 15: Naming methods

Capitalization Conventions

Page 16: Naming methods

Word Choice

Page 17: Naming methods

Using Abbreviations and Acronyms

Page 18: Naming methods

Avoiding Language-Specific Names

Page 19: Naming methods

Avoiding Language-Specific Names

Page 20: Naming methods

Naming New Versions of Existing APIs

Page 21: Naming methods

Naming API methods

Page 22: Naming methods

REST vs. SOAP

Page 23: Naming methods

http://www.example.com/customershttp://www.example.com/customers/33245

http://www.example.com/products/66432http://www.example.com/customers/33245/orders

REST Representation state transfer

Page 24: Naming methods

SOAP Simple Object Access Protocol

Page 25: Naming methods

Top Related