jump to navigation

Types, types, types! February 27, 2017

Posted by PythonGuy in Uncategorized.
trackback

Of all the arguments against Python, the one that seems to stick at all nowadays is typing. They think Python’s type system is all wrong, that we should instead embrace an archaic type system written back in the day when computers had very limited CPU cycles and memory.

I think I have an argument that should completely obliterate their point of view.

They like their type system because it gives them:

  • Speed
  • Reliability and predictability
  • Control

OK, I give you that. Yes, when the compiler knows in advance what type a variable is, when you can write simple programs to ensure that you don’t have any type mismatch (really, you just push that error out of the program itself), and you feel like you are somehow managing complexity. You win that part of the debate.

However, what do you do with generic types?

If they don’t understand why generic types are important, then you bring up templates, generic functions or classes that can be applied to any kind of type that provides a certain basic level of functionality.

See, when you bring up generics in these type systems, it is a whole ball of wax that they know better than to tangle with. They roll their eyes, they say things like, “When would I ever use generics? They’re so error-prone and a source of so many problems.”

The “Aha!” moment is when they realize that every type system must support the generic type, and their type system does it poorly.

Something like Python, with its dynamic-strong paradigm, handles them effortlessly.

No, you can’t predict how your program will behave, but could you ever, really? All you can do is break it down into little bits that you can test, test those bits (AKA, unit tests) and then see how the parts fit together (AKA integration tests). I mean, you’re going to write your tests anyway, right? What fool would think just because their program compiles it must be correct?

In short: You’re going to have to deal with generic types eventually. It’s better to use a language that can handle them very well, because once you’ve handled generic types, you’ve handled ALL types.

Advertisements

Comments»

No comments yet — be the first.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: