Zokyo Informational Vulnerabilities
  • 📚Tutorials
    • đŸ›Ĩī¸Informational Vulnerability 1: Floating Pragmas
    • â˜šī¸Informational Vulnerability 2: "Magic" Numbers
    • 🎁Informational Vulnerability 3: Missing Events
    • â˛ī¸Informational Vulnerability 4: Timelocks
    • â˛ī¸Informational Vulnerability 5: Transition from now to block.timestamp
    • âœī¸Informational Vulnerability 5: Managing Nonces for Signature Validity
    • đŸ—Ŗī¸Informational Vulnerability 6: Ensuring Accurate and Helpful Comments
    • 📲Informational Vulnerability 7: Minimizing Import Clutter by Excluding Unused Files
    • âœī¸Informational Vulnerability 8: Grouping Related Data in Structs or Similar Data Structures
    • đŸ•ļī¸Informational Vulnerability 9: Open TODOs
    • đŸ–ŧī¸Informational Vulnerability 10: Naming Convention
    • â›ī¸Informational Vulnerability 11: `require` vs `assert`
    • 😴Informational Vulnerability 12: Missing NatSpec
    • 🍊Informational Vulnerability 13: Public to External functions
    • 🤝Informational Vulnerability 14: Public to External functions
    • 🕐Informational Vulnerability 15: Time units
Powered by GitBook
On this page
  1. Tutorials

Informational Vulnerability 10: Naming Convention

PreviousInformational Vulnerability 9: Open TODOsNextInformational Vulnerability 11: `require` vs `assert`

Last updated 1 year ago

Introduction: Naming conventions are a cornerstone of effective software development, fostering readability, consistency, and a unified coding style. Solidity, as a prominent language for writing Ethereum smart contracts, is no exception. Adopting established naming conventions in Solidity is essential for producing clean, maintainable, and standardized codebases. This tutorial aims to guide developers through the prevalent naming conventions in Solidity, promoting best practices for crafting clear and comprehensible smart contracts.

1. Contract and Library Names

  • PascalCase: Contract and library names should be written in PascalCase, meaning that each word is capitalized without spaces or punctuation.

    solidityCopy codecontract AssetManager {...}

2. Function Names

  • camelCase: Function names should adopt the camelCase format, starting with a lowercase letter followed by uppercase initials for subsequent words.

    solidityCopy codefunction getTotalAssets() public view returns (uint256) {...}

3. Event Names

  • PascalCase: Similar to contracts, event names should also be in PascalCase to ensure they are easily distinguishable and readable.

    solidityCopy codeevent AssetAdded(address indexed assetOwner, uint256 assetValue);

4. Modifier Names

  • camelCase: Modifiers should follow the same convention as function names, utilizing camelCase for consistency.

    solidityCopy codemodifier onlyOwner() {...}

5. Variable Names

  • camelCase: Variables, including state variables and local variables, should be named using camelCase to maintain uniformity across the code.

    solidityCopy codeuint256 totalSupply;

6. Constants and Enum Types

  • UPPER_CASE_WITH_UNDERSCORES: Constants and enum types should be named using uppercase letters, separated by underscores to denote spaces.

    solidityCopy codeuint256 constant MAX_SUPPLY = 10000;
    enum AssetState { ACTIVE, INACTIVE, PENDING }

7. Struct Names

  • PascalCase: Structs should adopt PascalCase to maintain a clear and distinguished naming style.

    solidityCopy codestruct AssetInfo {...}

Conclusion and Best Practices

Adherence to a coherent naming convention is instrumental in enhancing code readability and maintainability. It fosters a professional coding environment, facilitating collaboration and communication among developers.

  • Consistency: Ensure that naming conventions are consistently applied throughout the codebase.

  • Clarity: Choose names that convey the purpose or functionality of the contracts, functions, or variables clearly and concisely.

  • Documentation: Complement the naming conventions with adequate documentation to further elucidate the code's purpose and functionality.

Embarking on your Solidity development journey with these conventions as your guide will ensure a well-organized, professional, and highly maintainable codebase, setting a solid foundation for successful and secure smart contract deployment and execution.

📚
đŸ–ŧī¸
Book an audit with Zokyo