I've recently used typescript, and I think the ability to mention or not types is great. It greatly reduces the debugging time while also giving you the advantages of an untyped language. I could imagine a python language superset with the same functionalities, I'm sure the type specifications could be used to greatly speed up the runtime while reducing the debugging hustle. What do you think?
Python – Why python doesn’t provide optional types
python
Related Solutions
My team ends up writing long functions and we don’t have many classes, which I think makes sense because the code is not meant to be reused by external programmers but rather only to complete a known task.
You may be misunderstanding the purpose of classes and short functions.
- Classes are a way of managing complexity. By packaging a group of related state and functionality together, and by creating methods that do things with that state (so that callers can tell a class instance to do something, instead of callers having to directly manipulate all of the necessary state themselves), you can encapsulate details and abstract away some of a problem's complexity.
- A function lets you attach a name to a piece of behavior. Code reuse is one benefit of functions, but attaching a name to a particular piece of code and having a structure to indicate what are the inputs, local state, and outputs of that code is of great benefit, even if you only ever call that function once.
In other words, using classes and short functions to structure your code and manage complexity is generally better design, even if the code doesn't need to be reused. You mentioned that your software only needs to complete a known task, but in my experience, even completing a known task often requires going back and revisiting the code, as bugs are found or as the task changes or as new, related tasks are added. I suspect that, if your single-task code used more, shorter functions and the occasional class, you'll find it easier to write, easier to understand, and easier to revisit.
Now, obviously, software development is all about trade-offs. Some design activities (such as some of the heavier OO techniques) may be worth the cost for heavily reused library code but not for single-use application code. Other design activities (such as trying to design for reuse before you actually have a need for reuse) are downright misguided. Other techniques, though, such as writing more, shorter functions, take very little effort once you've learned and practiced them, and I'd recommend them for almost any programming.
TL;DR: Short functions and good OO classes are good design. Whether the code is a reusable library or a single-use private application may affect which design criteria predominate and how design trade-offs are made, but good design is good design regardless.
Best Answer
I don't know whether TypeScript enforces type constraints at compile or run time. But Python does support type hints.
Python 3.0 introduced function annotations as defined in PEP 3107. They work like this:
You can annotate the parameters and the return value with any object.
This can be used to implement type hints. Python 3.5 introduces the
typing
module. You can implement a decorator that'd perform run-time type checking.