3 ms·
People choose tech based upon the business needs. I don't like Java, still don't. But I don't tell people they were making a huge mistake and they needed to b
by bb88 4y ago
People choose tech based upon the business needs. I don't like Java, still don't. But I don't tell people they were making a huge mistake and they needed to be "schooled" into using C++, e.g. There's usually some business reason to use a particular technology -- one that you may not like.
Back to python. There is no type checking in len() or abs(). The best argument I can make is through code. You, yourself, can make your own len() method. This will behave exactly like len(). Let's call it len2():
def len2(obj):
try:
return obj.__len__()
except AttributeError:
raise TypeError(f"object of type '{type(obj)}' has no len()")
There's no type checking, because there's no need. All that object needs is for __len__() to exist. Further we can add abs() and len() to an object like this:
class X:
def __len__(self):
return 2
def __abs__(self):
return 1
assert len(X()) == 2
assert len2(X()) == 2
assert abs(X()) == 1
Fortunately you can fix the issues with error uniformity by creating your own functions if you choose the method above. I won't judge you -- because there might be a reason you may want that.
> I just posit that most people who like Python only like it because they don't (yet) know better.
I don't know about that. I came from a background of C/C++/Ada/Java/68k Assembly/Perl/Shell Script/Awk/etc. I switched to python about a decade ago. The python community has some of the smartest people I've ever met. To me the smart people seem to have gravitated towards python.