The creator of Python, Guido van Rossum, has talked about how the programming language is borrowing ideas from JavaScript spinoff TypeScript.

Van Rossum was talking at the recent PuPPy charity event in Seattle, where he discussed the early days of Python and also touched on what he thinks the future holds for the language. Last year Van Rossum stepped back from being the language's 'Benevolent dictator for life', a tongue-in-cheek reference to his role guiding the language's development.

During the PuPPy discussion, Van Rossum, said helpful type-annotation features in TypeScript were inspiring the implementation of similar ideas in Python.

"I found TypeScript is actually incredibly useful, so we're adding a similar idea to Python, we're adding it in a slightly different way because we have different context," he said.

Image: PuPPy

After the event Van Rossum confirmed that the TypeScript behavior he was talking about was optional type checking, which is being made possible in Python.

Type checking allows developers to spot a class of bugs that could otherwise slip through into software, by running checks ahead of the code being executed that verify various operations, such as whether the data being passed to and from functions is of the correct type. In statically typed languages, developers typically specify the type of a variable or a function parameter when they're declared, for example, using the keyword int to specify an integer, or str to specify a string of characters, to use two simple examples. In contrast, dynamically typed languages don't require developers to specify a type for variables or function parameters, and so have historically been thought of as reducing the burden on the developer.

However, Van Rossum told the event that dynamic typing is generally not a good fit for large and complex codebases.

"I learned a painful lesson, that for small programs dynamic typing is great, for large programs you have to have a more disciplined approach and it helps if the language actually gives you that discipline, rather than telling you 'Well you can do whatever you want'," he said.

While Python is still a dynamically typed language, in 2015, Python 3.0 gained support for Type Hints, which allow developers to include annotations that allow a type checker like mypy to check whether the correct types are being passed to and from functions.

These annotations are optional and aren't executed, allowing the developer to use a mix of dynamic and static typing, and are designed not to affect the speed at which the code is executed. On top of Type Hints, introduced in Python Enhancement Proposal (PEP) 484, there have been a series of other features added to the language that provide hooks for type checkers to work with, including PEP 526, PEP 544, PEP 561, and PEP 563.

SEE: 10 ways to prevent developer burnout (free PDF) (TechRepublic)

In an earlier talk, Van Rossum said that Dropbox, where he now works as principal engineer, had began introducing type annotations to its Python codebase in 2015, and, by 2018, two million out of about six million lines of code were annotated.

The use of Type Hints in Python code has also been adopted by a wide range of firms, including Facebook, Quora, and Lyft. Type checkers other than mypy also now use Type Hints to verify types in Python.

As indicated by Van Rossum, TypeScript similarly provides type annotations that can verified by a type checker. These type annotations are one of the key additional features that makes TypeScript, a JavaScript superset, a more appealing choice than JavaScript for writing large applications.

Also speaking at the PuPPy event, Anders Hejlsberg, creator of TypeScript, said that, contrary to received wisdom, he believed type systems actually "dramatically" increased developer productivity.

"I am sure you're all accustomed to things like statement completion, refactoring, and code navigation and so forth," he said.

"If you think about it, the thing that powers that is semantic knowledge of your code, and the thing that provides the semantic knowledge of your code is a compiler with a type system.

"Once you add types you can actually dramatically increase productivity, which in some ways seems counterintuitive.

"I thought dynamic languages were easier to approach because you haven't got types that are this bother all the time. Well it turns out that you can actually be more productive by having types if you do it in a non-intrusive manner and if you work hard doing good type inference and so forth."

If you're interested in learning Python, check out this extensive TechRepublic round-up of free resources online, or if you fancy giving TypeScript a try, take a look at this collection of books, videos and guides.

Also see