Identify and extract duplicated code into reusable functions or move common fields to parent structures. This makes the codebase more maintainable and reduces the risk of inconsistencies when code needs to be updated.
Identify and extract duplicated code into reusable functions or move common fields to parent structures. This makes the codebase more maintainable and reduces the risk of inconsistencies when code needs to be updated.
Consider these refactoring approaches:
// Do this:
struct ShiftNode {
state: State,
buffer: Vec
2. **Extract repeated patterns into functions** when similar code appears in multiple locations:
```rust
// Instead of repeating this pattern:
match self.dtype() {
#[cfg(feature = "timezones")]
Datetime(_, Some(tz)) => { /* complex logic */ },
_ => { /* similar complex logic */ }
}
// Create a helper function:
fn process_with_timezone(&self, has_timezone: bool) -> Result {
// Implementation that handles both cases
}
// Use a descriptive constant: Scalar::new(Time, AnyValue::Time(NS_IN_DAY - 1))
4. **Parameterize functions** to handle variation rather than duplicating similar functions:
```rust
// Instead of two nearly identical functions:
fn prepare_expression_for_context() { /* ... */ }
fn prepare_expression_for_context_with_schema() { /* ... */ }
// Create one function with an optional parameter:
fn prepare_expression_for_context(schema: Option<Schema>) { /* ... */ }
These refactorings improve readability, maintainability, and reduce the risk of bugs when one instance of duplicated code is updated but others are missed.
Enter the URL of a public GitHub repository