Urgent.News

What's breaking now, across thousands of outlets.

AI

Type inference has usability problems (2019)

Type inference, a feature present in many modern programming languages, is a double-edged sword. It can simplify code, making it cleaner and easier to read, but it may also introduce complexities that hinder comprehension and increase cognitive load for programmers. While languages like Go, Rust, Swift, Scala, Kotlin, Zig, and Nim, as well as older languages like C++11, C# 3.0, and Java 10, all support type inference, the question remains: is it truly beneficial?

At first glance, code using type inference appears cleaner. However, there's limited evidence to support the claim that it makes programming tasks easier. In fact, it may lead to more confusion, as programmers may struggle to discern the types of variables without explicit declarations. This can be particularly challenging when working with poorly named variables or functions, leaving programmers to navigate through code to uncover the type information they need.

Cognitive load, the mental effort required to comprehend code, can be exacerbated by relying on type inference. Even simple arithmetic can become taxing when performed verbally, requiring active memory of the expression and performing calculations. Similarly, when trying to understand code that employs type inference, programmers must constantly remember variable types or constantly jump to different parts of the codebase to verify them.

This additional mental effort can be overwhelming, especially when programmers are already juggling numerous details while comprehending code.

Some argue that type inference improves readability by eliminating redundant information, and that the minor time saved by not typing explicit types is negligible compared to the benefits. However, a more compelling argument is that explicit typing serves as valuable code documentation, aiding in understanding and following a Test-Driven Development process. Microsoft, for example, has even shifted its stance on using explicit types in C# to improve code readability.

Despite the supposed benefits of reduced typing, the necessity of explicit typing should not be underestimated. If programmers spend valuable time worrying about variable types, they may become less efficient and more prone to errors. A more productive approach, as suggested by some developers, is to refactor convoluted code rather than relying on type inference as a crutch.

Given the potential drawbacks of type inference, it is crucial to conduct empirical studies to determine its true impact on programming productivity and comprehension. Researchers in programming language (PL), software engineering (SE), and human-computer interaction (HCI) communities are well-equipped to tackle this intriguing topic. Hopefully, future studies will shed light on the effectiveness of type inference and help guide language designers in making informed decisions about its use.

Written by urgent.news from Lobsters's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at austinhenley.com →

More in AI

Scaling your money safely with AI

Ryan chats with Srini Venkatesan, CTO at PayPal, about validating AI-generated deterministic code for security, developing autonomous SDLC harnesses with iterative feedback loops, and creating a…

More from Tuesday 8 September →