Back to all reviewers

Design for compatibility

pytorch/pytorch
Based on 4 comments
C++

When evolving APIs, prioritize backward compatibility to minimize disruption for existing users. Add new functionality using default arguments rather than creating overloaded methods that could cause ABI compatibility issues. For example:

API C++

Reviewer Prompt

When evolving APIs, prioritize backward compatibility to minimize disruption for existing users. Add new functionality using default arguments rather than creating overloaded methods that could cause ABI compatibility issues. For example:

// Prefer this:
void set_device(DeviceIndex device, bool force = false);

// Over this:
void set_device(DeviceIndex device);
void set_device(DeviceIndex device, bool force);

When introducing version-dependent features, implement appropriate version checks and fallbacks:

#if defined(CUDA_VERSION) && (CUDA_VERSION >= 12050)
  // Use newer API version
#else
  // Fallback implementation for older versions
#endif

Keep internal implementation details hidden from public-facing interfaces by clearly distinguishing between public APIs and internal functionality. For evolving ABIs, provide transition mechanisms that support both old and new versions simultaneously, allowing consumers to opt into newer versions explicitly while maintaining backward compatibility.

4
Comments Analyzed
C++
Primary Language
API
Category

Source Discussions