Why there's a not operator in programming? [closed] - if-statement

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 3 years ago.
Improve this question
Regardless of the programming language, Why there's a not operator while I may compare the expression with false and that will do the work needed.
For example, if I have a function called valid that returns boolean (true if valid and false if not) and I want to check if it's not valid then I will write it like this:
if not valid():
print("Not Valid")
While I can simply check if valid equals false like this:
if valid() == false:
print("Not Valid")

not is shorter and it is easier to understand. if not valid is simpler and closer to English than if valid equals false

Related

String comparison function (c++) [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I am looking for a function to compare the two strings. A functional similar to strcmp in CString with the difference that takes two strands in the input.
You can use std::string::compare (it returns 0 if values are the same). Also be aware that in fact you can use strcmp in c++, but if you want modern c++ version i would go with std::string::compare.

How to handle multiple OR condition in IF [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
bool A=false;
bool B=true;
if(!A || !B)
{
.....
}
In this condition when A is true, it didn't checks the B but I want to check B instead of A .
In this condition I want to execute if any one is true(A or B), But If A is true I want to check B also. is there any other logic to resolve this apart from using different if conditions?
You may turn off short-circut evaluation in your compiler. If you work with your own types, you may overload || and &&. Overloaded logical operators are not short-circuted.
Both things are really bad. Programmers expect logical operators to behave in certain way and are very likely to get super confused with this unexpected behavior. You should stick to short-circuting.

Is it ok to change request.POST._mutable [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 5 years ago.
Improve this question
Django 1.11.2
Do you think this is a good style or not:
In CBV:
request.POST._mutable = True
request.POST['{}_date_day'.format(prefix)] = ceil_day(day=day, month=month, year=year)
request.POST._mutable = False
The program works well. I'm satisfied. What troubles me is whether this is ok or not. Maybe it is really a bad practice.
I mean, is it acceptable that we should change the private property _mutable?
The first argument to a Form is simply a dictionary, it's not necessary to use the request.POST querydict, and it's a bad practice to interfere with the inner workings of the framework, you'll make your code much more portable if you do:
my_querydict = request.POST.copy() #creates a mutable copy
my_querydict['{}_date_day'.format(prefix)] = ceil_day(day=day, month=month, year=year)
form = WhateverForm(my_querydict)
You'll feel better about yourself later :-)

c++ evaluating string expression with variables [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I want to do evaluate for example something like:
int x=10, y=2;
x=eval('x+(y*10)');
i can give you the code which i made, but would like you to try yourself. Here are the steps :
replace all the unknowns with their values
convert the expression to postfix
try to evaluate postfix expression using stacks

Regex pattern to not equal 0 [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I want to pass values those are not equal zero (0). What is the best performing regex pattern for this ?
[^0]+
Means: Any character besides zero must occur at least once