Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Think Python:

 
Roman Rodriguez
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Allen,

I am beginning with Python, and the thing that bothers me most is variables. I mean, at first it looks easy not having to declare what kind of variable 'a' is: it is just automatized depending of what kind of value are you storing. But when using third party modules, sometimes it is not clear enough what kind of variable is that one which is being returned, or if it even makes sense to make a "cast" to get that variable to be the type you want.

How can you avoid these kind of doubts? How can you be sure what kind of variable is being returned anywhere?
 
Allen Downey
Author
Greenhorn
Posts: 28
Java Python Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Roman,

I agree that this is a problem. In statically typed languages like Java you can tell a lot about a function just by looking at the signature.

In Python, this information has to be in the documentation, so if the quality of the docs is poor, you are in trouble.

Actually, it can be even worse than that because of "duck typing" which says that a function argument can be any type as long as it provides the methods (and operators) that are used in the function. So when I write the documentation of a function that operates on lists, it is not the best style to say that the argument has to be a list; to be strictly correct, I should say that the function operates on any mutable, iterable type. But if people really did that, it would make docs really hard to read, especially for beginners.

So a short answer to your questions is that dynamic typing makes some things easier, but it means that good quality documentation is even more important!

Allen
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic