General and Web Programming Fundamentals
  • Introduction
  • Program creation and design
    • Program design
      • Algorithms
      • Pseudocode
    • Programming conventions
    • Writing programs
      • Source code editors
      • Integrated Development Environments
      • Code repositories/Version control
      • Compilers/Interpreters
  • Programming Fundamentals
    • Operators
      • Arithmetic
      • Logical
      • Assignment
    • Constants and Variables
    • Datatypes
      • Primitive Datatypes
        • Character
        • Integer
        • Boolean
        • Floating point
        • Nothing (Null)
      • Composite Datatypes
        • Arrays
        • Strings
        • Classes
        • Structs
      • Literals
    • Data structures
      • Lists
      • Queues
      • Stacks
      • Map/dictionary
      • Trees
      • Graphs
    • Control structures
      • Selection (Conditional)
        • If/Else
        • Ternary
        • Switch
      • Iteration (Loops)
        • For loops
        • While loops
        • Do-While loops
        • For-Each loops
    • Functions
      • Parameters and arguments
      • Lambda expressions
      • Higher Order Functions
    • Space and Time
    • Scope
    • Standard libraries
  • Programming Paradigms
    • Procedural (Imperative) Programming
    • Object-oriented programming
    • Functional Programming
    • Declarative Programming
    • Event Driven programming
  • Programming Languages
    • Short history of programming
    • Low-level programming languages
    • High-level programming languages
  • Web Development
    • What is the web?
      • Web browsers (clients)
      • Webservers (serving web pages)
      • W3C
    • Markup languages
      • HTML
        • HTML Tags
      • Cascading Style Sheets (CSS)
        • CSS Properties
      • XML
      • Markdown
    • Scripting Languages
      • JavaScript
      • TypeScript
    • JSON
    • JavaScript Frameworks
  • Acknowledgements
    • About the author(s)
  • License
Powered by GitBook
On this page

Was this helpful?

Export as PDF
  1. Program creation and design

Programming conventions

The general practices in computer programming, such as naming conventions, indentation, comments, and others, play a crucial role in ensuring code readability, maintainability, and overall quality. These practices may vary slightly depending on the programming language and the team's or project's guidelines, but there are widely accepted standards in the industry.

1. Naming Conventions

  • Camel Case: Used in languages like Java and JavaScript. Starts with a lowercase letter, and each new word starts with a capital letter, e.g., myVariableName.

  • Pascal Case: Similar to Camel Case, but starts with an uppercase letter, e.g., MyVariableName. Common in C# for class and method names.

  • Snake Case: Uses underscores to separate words, all lowercase, e.g., my_variable_name. Often seen in Python.

  • Kebab Case: Uses hyphens to separate words, all lowercase, e.g., my-variable-name. Common in URLs and file names.

2. Indentation

  • Spaces vs. Tabs: Consistency is key. The choice between spaces and tabs for indentation is often a matter of preference or team standards. Python, for instance, strongly recommends spaces.

  • Indentation Level: Typically, 2-4 spaces per indentation level or a single tab per level. Python enforces indentation as part of its syntax.

3. Comments

  • Inline Comments: Used for brief explanations or notes right next to the code. They should be concise and to the point.

  • Block Comments: For detailed descriptions, often placed at the beginning of a function or a complex code block.

  • Documentation Comments: Special comments that can be processed into documentation, e.g., Javadoc in Java or docstrings in Python.

  • Avoid Obvious Comments: Comments should explain the "why" rather than the "what". Avoid stating what is obvious from the code.

4. Code Structure

  • Consistent Bracing Style: Whether you use the "Egyptian" style where the opening brace is on the same line as the statement, or the "Allman" style where the opening brace is on the next line, consistency is key.

  • Logical Grouping: Group related lines of code together, and separate different sections logically.

  • Limit Line Length: Aim for a reasonable line length, like 80-120 characters, for better readability.

5. File and Directory Structure

  • Organize Logically: Group related files in directories. Naming should reflect the content or purpose.

  • Separate Code from Resources: Keep code files separate from resources like images, data files, etc.

6. Other Best Practices

  • Use Meaningful Names: Choose names that reflect the purpose of the variable, function, class, etc.

  • Avoid Deep Nesting: Deeply nested code can be hard to read and maintain. Aim to simplify complex conditions or loops.

  • Consistent Syntax: Be consistent in your use of syntax elements like commas, semicolons, etc.

By adhering to these general practices, developers can create code that is easier to understand, maintain, and collaborate on. It's also essential to adapt to and respect the coding standards of the specific project or team you are working with.

PreviousPseudocodeNextWriting programs

Last updated 1 year ago

Was this helpful?

Page cover image