my-ai-tools

Software Development Best Practices

Context

Comprehensive development guidelines for Agent OS projects, based on Kent Beck’s “Tidy First?” principles and Kent C. Dodds’ programming wisdom.

“Software design is an exercise in human relationships” - Kent Beck

Core Principles

Tidy First Philosophy

Code Quality Fundamentals

Change-Friendly Design

Dependencies

Choose Libraries Wisely

When adding third-party dependencies:

Tidying Practices

When to Tidy

Before making a change:

Core Tidying Techniques

Guard Clauses

Move preconditions to the top and return early:

// ❌ Nested conditions
function processUser(user) {
  if (user) {
    if (user.isActive) {
      if (user.hasPermission) {
        // main logic
      }
    }
  }
}

// ✅ Guard clauses
function processUser(user) {
  if (!user) return;
  if (!user.isActive) return;
  if (!user.hasPermission) return;

  // main logic
}

Dead Code Elimination

Delete code that isn’t executed or referenced.

Normalize Symmetries

Use consistent patterns throughout the codebase.

Helper Variables and Functions

Extract complex expressions into well-named variables:

// ❌ Complex expression
if (user.subscription.plan.tier === 'premium' &&
    user.subscription.status === 'active' &&
    user.subscription.expiresAt > new Date()) {
  // logic
}

// ✅ Helper variable
const hasActivePremiumSubscription =
  user.subscription.plan.tier === 'premium' &&
  user.subscription.status === 'active' &&
  user.subscription.expiresAt > new Date();

if (hasActivePremiumSubscription) {
  // logic
}

Testing Strategy

The Testing Trophy Approach

Based on Kent C. Dodds’ testing philosophy:

    🏆 End-to-End (E2E)
      ↑ High confidence, slow, expensive
   🥉 Integration Tests
      ↑ Good confidence, moderate speed
  🥈 Unit Tests
      ↑ Low confidence, fast, cheap
 🏅 Static Analysis

Testing Guidelines

Write Tests That Give Confidence

Test Structure

// ✅ Clear test structure
test('should increment counter when button is clicked', () => {
  // Arrange
  render(<Counter />);
  const button = screen.getByRole('button', { name: /increment/i });
  const counter = screen.getByTestId('counter-value');
  
  // Act
  expect(counter).toHaveTextContent('0');
  fireEvent.click(button);
  
  // Assert
  expect(counter).toHaveTextContent('1');
});

Avoid Testing Implementation Details

Performance Practices

Optimize for the Right Metrics

Progressive Enhancement

Performance Patterns

// ✅ Lazy loading with Suspense
const HeavyComponent = lazy(() => import('./heavy-component'));

function App() {
  return (
    <Suspense fallback={<Skeleton />}>
      <HeavyComponent />
    </Suspense>
  );
}

Collaboration Practices

Code as Communication

Pull Request Guidelines

For Authors:

For Reviewers:

Continuous Improvement