Always use correct and explicit parameters when calling APIs, rather than relying on defaults or passing incorrect values. This includes passing appropriate objects to API methods, specifying all required parameters explicitly, and using correct operation patterns.
Key practices:
nullptr
instead of *this
when documentation suggests it)--iterator
when you don’t need the previous result)ReplaceAll()
instead of Clear()
followed by multiple Append()
calls)Example from the codebase:
// Instead of passing potentially incorrect object reference
eventArgs.GetCurrentPoint(*this).Properties().IsMiddleButtonPressed()
// Pass the correct parameter as documented
eventArgs.GetCurrentPoint(nullptr).Properties().IsMiddleButtonPressed()
// For programmatic operations, always specify explicit parameters
profile->Commandline(winrt::hstring{
fmt::format(FMT_COMPILE(L"cmd /k winget install --interactive --id Microsoft.PowerShell --source winget & echo. & echo {} & exit"),
RS_(L"PowerShellInstallationInstallerGuidance"))
});
This approach reduces bugs, improves maintainability, and ensures APIs behave as intended rather than relying on potentially fragile default behaviors.
Enter the URL of a public GitHub repository