Python does not have an 'is_even' method or anything of the sort for integers.
Why is this the case?
Additionally, should I write is_even functions in my code for the sake of readability?
For example:
if integer_value % 2 == 0:
# Do something
It is not apparent what exactly that is supposed to do.
Whereas this is instantly more understandable:
if is_even(integer_value):
# Do something
This however means that I have to write an is_even function where I want it.
def is_even(integer):
if integer % 2 == 0:
return True
else:
return False
What is the better option? Have code that is itself readable and with apparent purpose, or have comments everywhere?
To quote a recent blog entry that is doing the rounds:
"Notice also how much stronger this approach is than using comments. If you change the logic there is immediate pressure on you to change the variable names. Not so with comments. I agree with DHH, comments are dangerous and tend to rot - much better to write self-documenting code." - http://peternixey.com/post/83510597580/how-to-be-a-great-software-developer
Am I taking this too far?