No, that won’t improve performance. In fact, it doesn’t in C, either. Where did you hear that?
not/! reads better and should have more or less the same speed.
And actually tested with gcc -O4:
#include <stdio.h>
int main(int argc, char *argv[]) {
for(int i = 0; i < 1000000000; i++) {
if(!(i < 900000000)) {
putchar('.');
}
}
}
vs.
#include <stdio.h>
int main(int argc, char *argv[]) {
for(int i = 0; i < 1000000000; i++) {
if(i < 900000000);
else {
putchar('.');
}
}
}
#1 took 6.62 seconds and #2 took 6.64 seconds on my computer.
if not some_thing and not some_thing_else: do_somethingits better to read code asif something or something_else: pass else: do_something. The answers here helped! Thanks.if-elif[-...]-elseblock like inif some-long-condition: pass elif one-more-long-condition: pass [elif ...] else: return (exit function with) something-like-abrupt-error-messagesomewhat similar to what @SourabhBhat- shared. It would be much more convenient than negating the conditions toreturn something-like-abrupt-error-messageeach and every if or elif.