Pseudocode Style Guide for Codexis Project
Introduction
This style guide provides conventions for writing pseudocode files in the Codexis project to ensure consistency, readability, and maintainability across all components.
File Structure
Algorithm Declaration
All pseudocode files should use the ALGORITHM keyword to declare the beginning of an algorithm and END ALGORITHM to mark its end:
ALGORITHM AlgorithmName
// Algorithm contents go here
END ALGORITHM
Do not use START / END format for algorithm declarations.
Algorithm Inputs and Outputs
When applicable, specify algorithm inputs and outputs after the algorithm declaration:
ALGORITHM AlgorithmName
INPUT: param1 (type), param2 (type)
OUTPUT: resultType
// Algorithm contents
END ALGORITHM
Procedure and Function Declarations
Use PROCEDURE for All Methods
For consistency, use PROCEDURE instead of FUNCTION for all method declarations:
PROCEDURE MethodName(param1, param2)
// Method body
END PROCEDURE
Main Entry Point
Each algorithm should have a Main() procedure that serves as the entry point:
PROCEDURE Main()
TRY
// Main execution logic
CATCH error
// Error handling
END TRY
END PROCEDURE
Naming Conventions
PascalCase for Methods and Classes
Use PascalCase (UpperCamelCase) for all procedure names, class names, and algorithm names:
PROCEDURE Initialize()
CLASS UserManager
ALGORITHM MetadataHandler
Variables and Parameters
Use camelCase for variables and parameters:
SET fileName = "document.tex"
PROCEDURE ProcessFile(inputFile, outputDirectory)
Constants
Use UPPER_SNAKE_CASE for constants:
SET MAX_ITERATIONS = 100
SET DEFAULT_TIMEOUT = 30
Control Structures
Conditional Statements
Format conditional statements with clear indentation:
IF condition THEN
// Code to execute if condition is true
ELSE IF otherCondition THEN
// Code to execute if otherCondition is true
ELSE
// Code to execute otherwise
END IF
Loops
Format loops with consistent indentation:
FOR EACH item IN collection
// Process item
END FOR
WHILE condition
// Process while condition is true
END WHILE
Error Handling
Use consistent error handling with TRY/CATCH blocks:
TRY
// Code that might cause an error
CATCH error OF TYPE ErrorType
// Handle specific error
CATCH error
// Handle any error
END TRY
Comments and Documentation
Header Comments
Include a brief description at the top of complex procedures:
// Converts SVG file to multiple formats (PNG, PDF, JPG)
// Returns a map of output file paths
PROCEDURE ConvertSvgToAllFormats(svgPath)
Inline Comments
Use inline comments for complex logic:
// Calculate the weighted average based on priority
SET weightedScore = (score * priority) / totalPriority
Imports and Dependencies
When referencing other algorithms, use explicit IMPORT statements:
IMPORT SetupBookTemplates FROM "template_setup.pseudocode"
Code Style
Indentation
Use 2 space indentation for all code blocks.
Line Length
Try to keep lines under 80 characters for better readability.
Spacing
Use spaces around operators for better readability:
SET total = price * quantity + taxRate
Example
ALGORITHM FileProcessor
INPUT: filePath (string), outputDir (string)
OUTPUT: ProcessedResult
// Main entry point
PROCEDURE Main()
TRY
SET processor = NEW FileProcessor(filePath, outputDir)
SET result = processor.Process()
OUTPUT "Processing completed successfully"
RETURN result
CATCH error OF TYPE FileNotFoundError
OUTPUT "Error: The specified file was not found"
RETURN Failure
CATCH error
OUTPUT "Error: " + error.message
RETURN Failure
END TRY
END PROCEDURE
PROCEDURE Initialize(filePath, outputDir)
SET @filePath = filePath
SET @outputDir = outputDir
ValidateInputs()
END PROCEDURE
PROCEDURE ValidateInputs()
IF NOT File.Exists(@filePath) THEN
THROW FileNotFoundError("File not found: " + @filePath)
END IF
IF NOT Directory.Exists(@outputDir) THEN
CREATE_DIRECTORY(@outputDir)
END IF
END PROCEDURE
PROCEDURE Process()
// Processing logic
RETURN ProcessedResult
END PROCEDURE
END ALGORITHM