r/programming • • Nov 25 '15

Don't use the OWASP PHPSec Crypto Library

https://gist.github.com/paragonie-scott/91893fdb18ee4d1a1b95
35 Upvotes

80 comments sorted by

View all comments

Show parent comment

0

u/[deleted] Nov 26 '15

[deleted] — view deleted comment

4

u/ajmarks Nov 26 '15

That's my point, is has enough corner cases where it "works"

Unless you're doing something fancy, is has exactly three corner cases: True, False, and None (because those are singletons).

1

u/[deleted] Nov 26 '15

If you are a new programmer and comparing ints with 'is', some weird stuff can occur. Not that 'is' should be used, but if someone uses it by mistake very weird things can happen.

x = 5
x is 5  # true
x = 826
x is 826  # false

http://stackoverflow.com/questions/306313/pythons-is-operator-behaves-unexpectedly-with-integers

3

u/[deleted] Nov 26 '15

Have you ever used Twisted Deferreds? Compare how verbose and confusing following a chain of deferred functions/methods is to Javascript Promises.

Yeah, but IMO using deferreds with actual callbacks is iffy. Just use @inlinecallbacks - that's async/await implemented in pure-python waaaay waaay before it was cool. And it's also awesome that you can implement async/await in pure python btw. Anyway, are you really trying to argue that JavaScripts callback hell is a good thing?? Worst example you could have used.. That's exactly why lambdas are single line only.

That's my point, is has enough corner cases...

No, it has incorrect usage, see the other comment. No tutorials use is to compare ints, never seen much code. But yeah, perhaps a very minor wart. But at the end of the day, is is for exact equality (this thing IS this other thing), whereas == compares if the two operands are equal ([] == False). Not complicated.

Python 3's problem is that it enforces unicode strings in places that are definitely NOT unicode.

Then they are bytes. Yeah, I've read the post, but never ran into those issues. In any case unicode everywhere is far far better than any alternative. Anyway, his point is not "assuming unicode in places where they are definitely NOT", it's that some outside external systems can't handle unicode everywhere and it's somewhat cumbersome to encode and decode at those boundaries. Deal with it.