Perl Best Practices [Electronic resources] نسخه متنی

اینجــــا یک کتابخانه دیجیتالی است

با بیش از 100000 منبع الکترونیکی رایگان به زبان فارسی ، عربی و انگلیسی

Perl Best Practices [Electronic resources] - نسخه متنی

Damian Conway

| نمايش فراداده ، افزودن یک نقد و بررسی
افزودن به کتابخانه شخصی
ارسال به دوستان
جستجو در متن کتاب
بیشتر
تنظیمات قلم

فونت

اندازه قلم

+ - پیش فرض

حالت نمایش

روز نیمروز شب
جستجو در لغت نامه
بیشتر
لیست موضوعات
توضیحات
افزودن یادداشت جدید







6.1. If Blocks


Use block if, not postfix if .


One of the most effective ways to make decisions and their consequences stand out is to avoid using the postfix form of if. For example, it's easier to detect the decision and consequences in:


if (defined $measurement) {
$sum += $measurement;
}

than in:


$sum += $measurement if defined $measurement;

Moreover, postfix tests don't scale well as the consequences increase. For example:


$sum += $measurement
and $count++
and next SAMPLE
if defined $measurement;

and:


do {
$sum += $measurement;
$count++;
next SAMPLE;
} if defined $measurement;

are both

much harder to comprehend than:


if (defined $measurement) {
$sum += $measurement;
$count++;
next SAMPLE;
}

So always use the block form of if.


/ 317