A
A
AVAtarMod2021-10-25 10:59:28
C++ / C#
AVAtarMod, 2021-10-25 10:59:28

What to choose: clarity or brevity of logical conditions?

There are two options for writing boolean conditions with pointers in C++
1)

while (a_ptr || b_ptr) {
        uint currentDataA = (a_ptr) ? a_ptr->data : 0;
        uint currentDataB = (b_ptr) ? b_ptr->data : 0;
        ....
}

2)
while (a_ptr != nullptr || b_ptr != nullptr) {
        uint currentDataA = (a_ptr != nullptr) ? a_ptr->data : 0;
        uint currentDataB = (b_ptr != nullptr) ? b_ptr->data : 0;
        ....
}

Previously, I usually chose the 2nd case, but now I see that it is probably better to use implicit type conversion? What are your thoughts on this?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vasily Bannikov, 2021-10-25
@vabka

Explicit is better than implicit.
Code is more often read than written.
So the second option is better.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question