News for hackers. Stuff that matters.
Re:Why Is Python Growing So Quickly? by outworlder on Thursday September 14, 2017 @01:57PM (#15250646)
> Write function in module A that expects some complex data structure that comes in. In a static typed language, you put a type on the argument and thus guarantee, to some degree, the data in the object can be safely manipulated.

Let's question some of the assumptions. Do you NEED the entire thing to be passed around? If your functions are small and only do one thing, can't they be fed the portion of the data they need and only manipulate that? If they are getting unnecessary data, soon someone will like the convenience and that piece of data will now become necessary.

I have seen Java projects with humongous "DAO" objects being passed across all apps. Even if Java had Haskell's type system, at some point it breaks down.

So, you do not enforce that on Python itself. Rather, you have to apply due diligence and ensure your data structures are clean, and functions do what they are supposed to do and no more.

> I can pass in some type of data structure that might behave well in many situations, but in some that function is going to fail because I didn't properly construct the data structure.

Then you construct the structure in a single place, and that should have some sanity checks and sane defaults.

Even if you are using a static typed language, there's no guarantee that what's inside the data structure even makes sense, only that the right type of structure is being passed on. That's helpful, but not as much as people would think.

And you write tests. Lots of tests. It is amazing the amount of Python code that gets written without proper testing. And Java, for that matter. Only Python programmers have less excuses, it's easier to replace what you need for testing.

Re:Why Is Python Growing So Quickly? by simion314 on Thursday September 14, 2017 @02:55PM (#15251285)
>Even if you are using a static typed language, there's no guarantee that what's inside the data structure even makes sense.

You should always put validation in constructor so you are 100% sure that the object created is valid.

Re:Why Is Python Growing So Quickly? by xapata on Thursday September 14, 2017 @06:46PM (#15253108)
How can you be sure your validation covered all cases?
Re:Why Is Python Growing So Quickly? by simion314 on Friday September 15, 2017 @01:13AM (#15254813)
Say you have a Circle class, you need a center point so you validate that the center is not null and you check that radius is greater then zero. Do you have an example where is impossible to validate all cases? if so how will your unit tests validate/test all those cases?
Re:Why Is Python Growing So Quickly? by xapata on Friday September 15, 2017 @04:18AM (#15255524)
In your example, you can't anticipate that center points approximately but not quite equal to pi will cause a ... whatever bug in ... whatever downstream use of the class. One can never really know what states are acceptable.
Re:Why Is Python Growing So Quickly? by simion314 on Friday September 15, 2017 @06:47AM (#15256041)
The circle is valid, what you say is a bug in other section that crashes with valid circles,so types could prevent invalid inputs to functions. What you describe is a bug in an algorithm I don't think that is possible for a compiler to prevent bugs in algorithms, division by zero or precision errors
Re:Why Is Python Growing So Quickly? by xapata on Friday September 15, 2017 @12:54PM (#15258637)
Type systems can do some pretty miraculous things. For example, you could distinguish between a connected and disconnected socket with types so that you don't accidentally send on a disconnected socket.

I guess I'm arguing both sides now. My point is that one needs to root out the weird cases somehow and that it's often hard to have "100%" validation of inputs. One's initial understanding of what is the valid and invalid state space is often incorrect.