7 ms·
They're probably laughing because a) you're suggesting manually doing the work static typing does in a dynamic language because its untenable not to for large p
by arc619 5y ago
They're probably laughing because a) you're suggesting manually doing the work static typing does in a dynamic language because its untenable not to for large projects, and b) you can't easily add type hints to other people's libraries.
- vanusa 5y agoNo - (a) is not what I'm suggesting. And (b) while disappointing, just doesn't slow one's work down very frequently in daily practice. Look, I just don't buy the suggestion that static typing magically solves a huge set of problems (or that it does so without imposing negative tradeoffs of its own -- the very topic of the original article). Or that dynamic languages are plainly crippled, and that one has to be a kind of a simpleton not to see this obvious fact.
- yakshaving_jgt 5y ago> I just don't buy the suggestion that static typing magically solves a huge set of problems // compiles and runs, but does bad things function foo(x, y) { someDangerousEffect(); return x + y; } -- does not compile; huge sets of problems magically solved foo :: Int -> Int -> Int foo x y = someDangerousEffect >> pure $ x + y
- vanusa 5y agoA problem but not a huge one in practice. And you're neglecting the part of my statement you conveniently truncated.
- yakshaving_jgt 5y ago> not a huge one in practice. Our experiences have been wildly different :)
- vanusa 5y agoYeah, life sometimes gets that way.
- arc776 5y ago> just doesn't slow one's work down very frequently in daily practice. Well, maybe you don't feel it slows you down, but it is manual work you must do to get a reliable product only because of dynamic typing. Not only that, but you have to then refer to these docs to check you're not creating a type calamity at some nebulous point down the run time road. Static languages just won't let you mess that up, and often have utilities to generate this documentation for you at no effort. > I just don't buy the suggestion that static typing magically solves a huge set of problems Static typing really does "magically" solve a whole class of problems without any negative tradeoffs, assuming the language has decent type inference. Not all problems, but a specific class of them that you should do extra work to guard against in dynamic languages. Whether that is extra documentation that has to be reliably updated and checked, or run time code to check the types are what you expect at the point of use. Take for example JavaScript, where typing is not only dynamic, but weak. Numbers in particular can be quite spicy when mixed with strings as I'm sure you know. Strong, static typing forces you to be explicit in these cases and so removes this problem entirely. By the way, no one's saying anyone is a simpleton. The reality is our field is wide and varied, and different experiences are valid. Dynamic languages can do some things that static languages can't. For example, you can return completely different types from different execution paths in the same function. This has been something that has confused me when reading Python, but it does make it easier for stuff like tree parsing. In a static language you need to specify some variant mechanism that knows all data possibilities ahead of time to allow this. From my perspective the dynamic typing trade off isn't worth these bits of 'free' run time flexibility, but YMMV! It really depends what arena you're working in and what you're doing.
- vanusa 5y agoI think I've said about 3 times in this thread that I'm firmly in the "pro" camp as regards the net positives of static typing, and for precisely the reasons you've detailed. I just don't see its absence (or instances where it less than algebraically perfect) as the crippling dealbreakers that others seem to regard it as. What I was referring to as "not slowing one's work down very frequently" was the corner case situation that someone brought up 4 comments above yours, which (in their view) renders the general type checking capabilities of Python >= 3.5 moot. I don't buy that logic, but that was their argument, not yours. But to shift gears: if there are languages besides JS that you feel get their type system "just right", I'd be curious as to what they are, for the benefit of that future moment when I have the luxury of time to think about these things more.
- maxwell86 5y agoYou suggested that Python type hints are useful. I laughed hard at that suggestion. Can you maybe just show how to type a Python function such that it does the absurdly simple thing of taking a numpy array of integers? def fun(nump_array_of_ints: ???): ... Just to show everyone just how "useful" type hints in Python _actually_ are.
- vanusa 5y agoimport numpy as np import numpy.typing as npt x = np.array([1, 2, 3]) def foo(x: npt.NDArray[np.int_]) -> bool: return True