Bu yazı Kod Gözden Geçirmesi - Code Review sürecinden yola çıkarak başladı. Kod Gözden Geçirmesi sürecinde şöyle bir madde vardı.
1. Source code comments are sufficient :
Yazan cümleler genelde şöyle. İşte burada görecelilik ön plana çıkıyor.
Yazan cümleler genelde şöyle. İşte burada görecelilik ön plana çıkıyor.
Emniyet kritik bazı projelerde her satır için comment olması isteniyor. O zaman iş sanki biraz daha kolay. Sadece her satıra bakmak yeterli. Kod şöyle görünüyor.
- If there is a comment, does it explain why the code does what it does?
- Is each line of the code - in its context - either self-explanatory enough that it does not need a comment, or if not, is it accompanied by a comment which closes that gap?
- Can the code be changed so it does not need a comment any more?
/* Display an error message */
function display_error_message( $error_message )
{
/* Display the error message */
echo $error_message;
/* Exit the application */
exit();
}
/* -------------------------------------------------------------------- */
/* Check if the configuration file does not exist, then display an error */
/* message */
if ( !file_exists( 'C:/xampp/htdocs/essentials/configuration.ini' ) ) {
/* Display an error message */
display_error_message( 'Error: ...');
}Yapılması gerekenlere bazı örnek- Source code conforms to coding standard and is checked by automated tool
- Source code is checked manually by reviewer if automation is not possible
- Source code is checked for memory leaks by a dedicated tool
- Source code is compatible and traceable to SRS
- Source code is checked manually by reviewer if automation is not possible
- Source code is checked for memory leaks by a dedicated tool
- Source code is compatible and traceable to SRS
2. The Pattern I Notice in Every High-Quality Codebase
Daha sonra The Pattern I Notice in Every High-Quality Codebase yazısını gördüm
Yüksek kalite kodlarda bir karar yani "neden" açıklaması vardır. Açıklaması şöyle
1. Business context — Why this business rule existsI've started noticing four types of decision context that great codebases maintain:...Without this context, all code looks equally arbitrary.
Örnek şöyle
// Stripe charges 2.9% + $0.30 per transaction
// We pass this through to users on transactions <$10
// For larger transactions, we absorb it (reduces churn by 8%)
const FEE_THRESHOLD = 1000; // in cents2. Historical context — Why we chose this approachÖrnek şöyle
// We tried async/await here but hit deadlocks under load // See incident post-mortem: docs/incidents/2024-01-15-deadlock.md // Synchronous approach is slower but reliable fn process_batch_sync(items: Vec<Item>) -> Result<()> {
3. Constraint context — What limits our optionsÖrnek şöyle// API rate limited to 100 req/min per docs/api-limits.md
// We batch requests to stay under limit with 20% safety margin
const maxRequestsPerMinute = 80
4. Future context — What we plan to changeÖrnek şöyle// TODO: Move to event-driven architecture
// Blocked on: Kafka cluster provisioning (INFRA-445)
// Timeline: Q2 2024
// This polling approach is temporary
pollForUpdates();
Hiç yorum yok:
Yorum Gönder