Code Elegance Rubric

This rubric provides detailed criteria for assessing code quality. It is referenced by the Module Rubric and applies to all Python code submitted.

Point Scale

ScoreDescription
4Exceeds expectations. Professional quality. No meaningful improvements needed.
3Meets expectations. Solid work with minor issues.
2Partially meets expectations. Functional but with notable weaknesses.
1Below expectations. Significant problems, but evidence of effort.
0Missing or fundamentally inadequate.

Criteria

1. Naming Conventions

Are variable, function, class, and module names clear and consistent?

ScoreDescription
4Names are descriptive, consistent, and follow PEP 8 conventions. Names reveal intent without needing comments. Abbreviations avoided or universally understood.
3Names are generally clear and consistent. Minor issues with occasional vague names or slight inconsistency.
2Names are functional but often unclear, inconsistent, or overly abbreviated. Reader must infer meaning.
1Names are confusing, misleading, or highly inconsistent. Single-letter variables used inappropriately.
0Naming is incomprehensible or no meaningful code submitted.

2. Function and Method Design

Are functions appropriately sized with clear, single responsibilities?

ScoreDescription
4Functions are concise and focused. Each function does one thing well. Parameters are minimal and well-chosen. No function exceeds reasonable length (roughly 20–30 lines for most cases).
3Functions are generally well-designed. Occasional functions are slightly too long or have mixed responsibilities.
2Functions are often too long or try to do too much. Some refactoring would improve clarity.
1Functions are monolithic. Hundreds of lines in single functions. Responsibilities unclear.
0No meaningful function structure. Code is one large block or incomprehensible.

3. Abstraction and Modularity

Is code appropriately abstracted—neither too shallow nor over-engineered?

ScoreDescription
4Abstraction is well-judged. Classes and modules have clear purposes. Code is reusable where appropriate. No unnecessary complexity or premature generalization.
3Abstraction is reasonable. Minor instances of under- or over-abstraction.
2Abstraction issues present. Code is either too monolithic or unnecessarily complex with excessive class hierarchies.
1Significant abstraction problems. Everything in one file or conversely, trivial operations spread across many classes.
0No meaningful structure.

4. Style Consistency

Is the code style consistent throughout?

ScoreDescription
4Consistent style throughout. Follows PEP 8. Indentation, spacing, and formatting are uniform. Would pass a linter with no or minimal warnings.
3Generally consistent with minor deviations. A few style inconsistencies.
2Inconsistent style. Mixed conventions, irregular spacing, inconsistent indentation.
1Style is chaotic. No apparent conventions followed.
0Unreadable due to formatting issues.

5. Code Hygiene

Is the code free of dead code, duplication, and magic numbers?

ScoreDescription
4Clean codebase. No dead code, commented-out blocks, or duplication. Constants are named and defined in one place. No magic numbers or strings.
3Mostly clean. Minor instances of duplication or a few magic numbers.
2Notable hygiene issues. Dead code present, copy-paste duplication, several magic numbers scattered throughout.
1Significant hygiene problems. Large blocks of dead code, extensive duplication, magic numbers everywhere.
0Codebase is cluttered and unmaintainable.

6. Control Flow Clarity

Is the control flow readable and easy to follow?

ScoreDescription
4Control flow is clear and logical. Nesting is minimal (generally ≤3 levels). Early returns used appropriately. Complex conditions are broken into well-named variables or functions.
3Control flow is generally clear. Occasional deep nesting or complex conditionals.
2Control flow is difficult to follow. Deep nesting, convoluted conditionals, or unclear branching logic.
1Control flow is confusing. Spaghetti code, goto-like patterns, or incomprehensible branching.
0Control flow cannot be understood.

7. Pythonic Idioms

Does the code use Python idioms appropriately?

ScoreDescription
4Code leverages Python idioms effectively: list comprehensions, context managers, generators, unpacking, enumerate, zip, etc. Uses standard library appropriately. Avoids reinventing built-in functionality.
3Generally Pythonic. Uses common idioms. Occasional missed opportunities.
2Code works but is not idiomatic. Writes explicit loops where comprehensions would be clearer. Ignores useful standard library functions.
1Code fights the language. Java-style or C-style patterns. Does not leverage Python's strengths.
0Code does not demonstrate knowledge of Python.

8. Error Handling

Are errors handled appropriately and informatively?

ScoreDescription
4Errors are handled thoughtfully. Exceptions are specific, caught at appropriate levels, and provide useful messages. Fails gracefully where appropriate. Does not silence errors inappropriately.
3Error handling is reasonable. Most errors handled. Occasional bare except or overly broad exception catching.
2Error handling is inconsistent. Some errors caught, others ignored. Generic exceptions used.
1Error handling is poor. Errors silenced, crashes on common inputs, or no error handling at all.
0No error handling. Code crashes unpredictably.

Overall Code Elegance Score

Calculate the average across all 8 criteria. The overall score informs the "Code Elegance and Quality" criterion in the Module Rubric.

AverageModule Rubric Score
3.5–4.04
2.5–3.43
1.5–2.42
0.5–1.41
0.0–0.40