/
Column formatted code for clarity
Column formatted code for clarity
There is a power in giving more clarity to code by taking advantage of the human eye’s desire to seek patterns. Compare this code:
void APPcreateNonblockingPipe(int Pipe[2]){
BAS_FUNCTION(APPcreateNonblockingPipe);
if (-1 == pipe(Pipe)) { BASerrorMessage(errno); }
if (-1 == fcntl(Pipe[0], F_SETFL, O_NONBLOCK)) { BASerrorMessage(errno); }
if (-1 == fcntl(Pipe[1], F_SETFL, O_NONBLOCK)) { BASerrorMessage(errno); }
To this code:
void APPcreateNonblockingPipe(int Pipe[2]){
BAS_FUNCTION(APPcreateNonblockingPipe);
int Result = pipe(Pipe);
if (Result == -1){
BASerrorMessage(errno);
}
Result = fcntl(Pipe[0], F_SETFL, O_NONBLOCK);
if (Result == -1){
BASerrorMessage(errno);
}
Result = fcntl(Pipe[1], F_SETFL, O_NONBLOCK))
if (Result == -1){
BASerrorMessage(errno);
}
}
The former form is easier to comprehend what we are doing because we can visually see we are doing the same operation to the parts of the pipe.
The code creates a pipe and makes both the read and write end nonblocking.
, multiple selections available,
Related content
Regular expressions in code are confusing for other programmers
Regular expressions in code are confusing for other programmers
Read with this
See the this pointer for C++ objects
See the this pointer for C++ objects
More like this
Why do we need blocking and non blocking functions?
Why do we need blocking and non blocking functions?
More like this
Unix processes were designed to be piped together
Unix processes were designed to be piped together
More like this
How do you use tracing?
How do you use tracing?
More like this
HL7 Delimiter Redefinition
HL7 Delimiter Redefinition
More like this