Re: sparse (static analyzer) report

Поиск
Список
Период
Сортировка
От Greg Stark
Тема Re: sparse (static analyzer) report
Дата
Msg-id 87hdliu26n.fsf@stark.xeocode.com
обсуждение исходный текст
Ответ на Re: sparse (static analyzer) report  (Tom Lane <tgl@sss.pgh.pa.us>)
Ответы Re: sparse (static analyzer) report  (Bruno Wolff III <bruno@wolff.to>)
Список pgsql-hackers
Tom Lane <tgl@sss.pgh.pa.us> writes:

>     if (ptr)
>
> Can anyone mount a good readability argument for one over the other?

My argument in favour of "if (ptr)" as well as "if (integer)" and "if (!ptr)"
is simply that all else being equal the shorter expression is clearer. Forcing
the reader to slog through additional syntax to read the code has a cost.

Obviously that argument is subject to abuse and it's very dependent on whether
you consider all else equal. 

For a reduction argument, pretending there's a boolean type with no casts
leads to the excessively verbose java-ish syntax like:
if (foo != 0 && bar != null && baz != 0)

which you can't tell me is easier to read than
if (foo && bar && baz)


What I miss most in both C and Java is the lispish ability to write
expressions like:
foo = bar() || baz() || qux();

instead you have to write out things like this (except worse since you have to
start storing things in temporary variables):
if (bar() != null) {  foo = bar();} else if (baz() != 0) {  foo = baz()} else {  foo = qux();}

I've seen code that consists of a dozen or so of these things repeated. When
the code starts getting so verbose that what could be 12 very simple and clear
lines no longer fits on the screen because you're trying to make it easier to
understand, well, I think you've lost the battle.

-- 
greg



В списке pgsql-hackers по дате отправления:

Предыдущее
От: Alvaro Herrera
Дата:
Сообщение: Re: sparse (static analyzer) report
Следующее
От: "Marc G. Fournier"
Дата:
Сообщение: Re: FATAL: catalog is missing 1 attribute(s) for relid