jQuery in Action, 3rd edition
The moose likes Jython/Python and the fly likes Think Python: Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Languages » Jython/Python
Bookmark "Think Python: " Watch "Think Python: " New topic

Think Python:

Roman Rodriguez

Joined: Sep 19, 2012
Posts: 7
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

Joined: Sep 07, 2012
Posts: 25

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!


All of my books are available from http://greenteapress.com
I agree. Here's the link: http://aspose.com/file-tools
subject: Think Python:
It's not a secret anymore!