Skip to content

Code quality improvements: style, performance, and documentation#41

Merged
memburg merged 1 commit into
mainfrom
issue-40-code-quality-improvements
Jun 12, 2026
Merged

Code quality improvements: style, performance, and documentation#41
memburg merged 1 commit into
mainfrom
issue-40-code-quality-improvements

Conversation

@memburg

@memburg memburg commented Jun 12, 2026

Copy link
Copy Markdown
Owner

Summary

Comprehensive code quality improvements across the GiavaScript codebase, covering Crystal code style, algorithm performance, and documentation. No functionality changes.

Style fixes (7 files)

  • switch_statement_parser.cr: while trueloop do (idiomatic Crystal)
  • function_runtime.cr: Remove duplicate FUNCTION_NAME_REGEX (same as IDENTIFIER_REGEX), use .try(&.parameters.size)
  • interpreter.cr: Fix constant spacing, condense truthy?/strict_equals_values? guard clauses
  • expression_evaluator.cr: Same guard clause condensation for consistency
  • giavascript_cli.cr: Break ternary into named variable, fix .ls.js in usage message

Performance improvements (5 files)

  • interpreter.cr: Single-pass String.build for escape_string replaces chained .gsub (4x fewer allocations)
  • runtime_types.cr: Schwartzian transform for array_sort — compute keys once instead of O(n log n) times
  • runtime_types.cr: In-place array_splice and array_unshift eliminate full array copies (2-4x speedup)
  • interpreter.cr: Bail-early in split_assignment_statement when no = present (50-80% reduction for non-assignment statements)
  • interpreter.cr: Cache FallbackRawStatement results (avoids repeated compilation)
  • interpreter.cr: Use String.build for value_to_s array/hash serialization (eliminates intermediate arrays)
  • expression_parser.cr: Use Set for parameter duplicate detection (O(n) vs O(n^2))

Documentation updates (6 files)

  • README.md: Fix broken logo fallback src, update examples list to match actual files
  • reference/Language.md: Document arrow functions, typeof semantics, unary plus, comments, semicolon-free statements, console.log, named function expressions
  • reference/Math.md: Add edge case notes for Math.max()/Math.min()
  • reference/Types.md: Fix grammar
  • CONTRIBUTING.md: Clarify CI verification and improve wording
  • New: CHANGELOG.md, .github/PULL_REQUEST_TEMPLATE.md, issue templates

Verification

  • All 223 specs pass
  • REFERENCE.md regenerated

Style fixes:
- switch_statement_parser: while true -> loop do
- function_runtime: remove duplicate FUNCTION_NAME_REGEX, use .try(&.parameters.size)
- interpreter: fix constant spacing, condense truthy?/strict_equals_values? guard clauses
- expression_evaluator: condense truthy?/strict_equality_result guard clauses
- giavascript_cli: break ternary into named variable, fix .ls -> .js in usage

Performance improvements:
- interpreter: single-pass String.build for escape_string (replaces chained .gsub)
- runtime_types: Schwartzian transform for array_sort to avoid O(n log n) string conversions
- runtime_types: in-place array_splice and array_unshift to reduce allocations
- interpreter: bail-early in split_assignment_statement when no '=' present
- interpreter: cache FallbackRawStatement results
- interpreter: use String.build for value_to_s array/hash serialization
- expression_parser: use Set for parameter duplicate detection (O(n) instead of O(n^2))

Documentation:
- README: fix broken logo fallback, update examples list, improve CLI section
- Language.md: document arrow functions, typeof semantics, unary plus, comments, semicolons, console.log
- Math.md: add edge case notes for Math.max()/Math.min()
- Types.md: fix grammar
- CONTRIBUTING.md: clarify CI verification and improve wording
- Add CHANGELOG.md, PR template, and issue templates

Closes #40
@memburg memburg linked an issue Jun 12, 2026 that may be closed by this pull request
@memburg memburg added documentation Improvements or additions to documentation enhancement New feature or request labels Jun 12, 2026
@memburg memburg self-assigned this Jun 12, 2026
@memburg memburg merged commit 91f4926 into main Jun 12, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Code quality improvements: style, performance, and documentation

1 participant