3 ms·
As for 1), if you can use Python 3.5+, and the native type hins, you can use mypy to do type checking, and give hints to developers/ide's about acceptable input
by 8fingerlouie 9y ago
As for 1), if you can use Python 3.5+, and the native type hins, you can use mypy to do type checking, and give hints to developers/ide's about acceptable inputs :
def greeting(name: str) -> str:
return 'Hello ' + name
https://www.python.org/dev/peps/pep-0484/#non-goals https://www.python.org/dev/peps/pep-0484/#non-goals
- sarabande 9y agoAgreed -- definitely possible. The issue is more than in organizations I've seen, the group of data scientists does not agree on using type hints, because a lot of them want to "move fast," and not be bothered with what they consider irrelevant, low-level details. This, sadly, brings us back to the problem. I'm of the opinion nowadays that these rules need to be mandatory at a group level (i.e. either enforced by the compiler or by convention at your workplace) to be useful.
- icebraining 9y agoPython typing has the advantage of being gradual, so you can introduce types in certain places (e.g. core packages) without being forced to type everything.
- cies 9y agoThis may bring it to more-less Go's level, but is nothing close to what Haskell can do for you type-wise.
- stewbrew 9y agoAFAIK this doesn't imply static type checking though. The types are at best checked at runtime, aren't they? If so, it doesn't really help much.
- icebraining 9y agoNo, it's static. You run the "mypy" command, which statically analyzes the Python code.
- zeugmasyllepsis 9y agoMypy is a static type checker for Python. From the intro in the MyPy docs. MyPy is a legitimate static type checker for Python, with similar capabilities and limitations as other statically typed languages. There's an escape hatch to get you back to dynamic land (the `Any` type) and you can do naughty things at runtime if you use it (in the same way that you can in languages like C#), but using Mypy you can get decent type checking without actually running your program.
- 8fingerlouie 9y agoIt doesn't check runtime (AFAIK neither does Go, it checks compile time). In fact, Python fully ignores any type hints. When coupled with mypy (http://mypy-lang.org/ http://mypy-lang.org/) they can be used to do type checking at "compile time", and with DropBox's pyannotate (https://github.com/dropbox/pyannotate https://github.com/dropbox/pyannotate), they can even be auto generated for existing code. I'm not saying Python with type hints is better than a statically typed language, merely suggesting a possible solution if Python ends up being the preferred language. Personally i love Go for the things i've used it for, and i've written and maintained large code bases in Python, and hated every minute of it. The same can be said for large code bases i've written in C, or even Java. I've written kernels for GSM mobile phones, software for sortation devices (airport baggage sorters, mail sorters, etc), banking software, and despite our teams best intentions, given enough time and customization to meet customer demands, there is always some remote corner of the code that ends up as a "steaming pile"