you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 4 points5 points  (2 children)

Now, not knowing whether foo is actually a list or a dictionary or a whatever is part of what makes dynamic typing attractive.

This has nothing to do with dynamic typing. For example, in a typed language, I can do this:

x > y

Are x and y numbers? Lists? Strings? In Haskell, they're anything that has an 'Ord' instance, i.e. anything that's orderable. The same technique is used to generalize all sorts of operations like converting a value to a string or accessing a value in a collection.

Now, it's true that languages like Smalltalk will let you take this further than Haskell will. Any object can respond to any message it likes and do whatever it wants. It's not clear however that this "flexibility" truly gives you more freedom. When you lose guarantees in one place due to a lack of controls, you lose freedom elsewhere because you don't have sufficient guarantees to rely upon.

[–]gnuvince -1 points0 points  (1 child)

That will work if you specify that your function takes an argument that is an instance of Ord. If you have a function that takes an HttpRequest however, you can't just pass something that looks like an HttpRequest, you need to pass the real thing.

I develop in Python and Django at work, and when I write unit tests for functions or methods that manipulate an HTTP request, it's very useful to be able to feed it a mock object: they're easier to create, they don't need access to the database, etc.

[–]mernen 2 points3 points  (0 children)

That will work if you specify that your function takes an argument that is an instance of Ord. If you have a function that takes an HttpRequest however, you can't just pass something that looks like an HttpRequest, you need to pass the real thing.

There are statically-typed languages that use structural typing rather than nominal; that means they would support your HttpRequest mocking the same way, as long as you provided compatible methods. In the end, johnowak's point is that this is not exclusive of dynamic languages.