How Do Developers Use Type Inference: An Exploratory Study in Kotlin
- URL: http://arxiv.org/abs/2410.23360v1
- Date: Wed, 30 Oct 2024 18:07:21 GMT
- Title: How Do Developers Use Type Inference: An Exploratory Study in Kotlin
- Abstract summary: Kotlin is the default language for Android development, one of the largest software marketplaces.
We conduct a large-scale empirical study using Boa, a tool for mining software repositories.
Our findings reveal that type inference is frequently employed for local variables and variables with method calls declared outside the file.
- Score: 3.382017614888546
- License: http://creativecommons.org/licenses/by-nc-sa/4.0/
- Abstract: Statically typed languages offer numerous benefits to developers, such as improved code quality and reduced runtime errors, but they also require the overhead of manual type annotations. To mitigate this burden, language designers have started incorporating support for type inference, where the compiler infers the type of a variable based on its declaration/usage context. As a result, type annotations are optional in certain contexts, and developers are empowered to use type inference in these situations. However, the usage patterns of type annotations in languages that support type inference are unclear. These patterns can help provide evidence for further research in program comprehension, in language design, and for education. We conduct a large-scale empirical study using Boa, a tool for mining software repositories, to investigate when and where developers use type inference in 498,963 Kotlin projects. We choose Kotlin because it is the default language for Android development, one of the largest software marketplaces. Additionally, Kotlin has supported declaration-site optional type annotations from its initial release. Our findings reveal that type inference is frequently employed for local variables and variables initialized with method calls declared outside the file are more likely to use type inference. These results have significant implications for language designers, providing valuable insight into where to allow type inference and how to optimize type inference algorithms for maximum efficiency, ultimately improving the development experience for developers.
Related papers
- Type Hints in Python Libraries and Frameworks: An Empirical Analysis of Adoption and Maintenance [0.29332247106953097]
We investigate the adoption, usage, maintenance, and rationale of type hints in Python libraries and frameworks.<n>Of the analyzed repositories, 91% of libraries use type hints at least once, although adoption is inconsistent.<n>When modified, annotations tend to migrate to more expressive types.
arXiv Detail & Related papers (2026-09-02T16:15:09Z) - TypeProbe: Recovering Type Representations from Hidden States of Pre-trained Code Models [0.0]
State-of-the-art code models achieve impressive performance, yet the extent to which they internally encode type information remains poorly understood.<n>We probe the residual streams of pretrained code models for internal type representations using a parallel dataset of Java and Python code examples.<n>Our results show that cross-lingual type representations emerge even from untyped code.
arXiv Detail & Related papers (2026-07-09T10:29:15Z) - TypePro: Boosting LLM-Based Type Inference via Inter-Procedural Slicing [6.017183469774327]
Type inference for dynamic languages has become a popular research area.<n>Existing approaches typically achieve type inference through static analysis, machine learning, or large language models.<n>This paper proposes a method called TypePro, which leverages LLMs for type inference in dynamic languages.
arXiv Detail & Related papers (2026-04-03T03:52:46Z) - Do Developers Read Type Information? An Eye-Tracking Study on TypeScript [4.249448869949738]
Statically-annotated types have been shown to aid developers in a number of programming tasks.<n>It is hypothesized that this is because developers use type annotations as in-code documentation.
arXiv Detail & Related papers (2026-02-04T18:12:59Z) - RightTyper: Effective and Efficient Type Annotation for Python [0.7673339435080445]
RightTyper generates precise type annotations based on actual program behavior.<n>RightTyper is fast and space-efficient, imposing just 30% performance overhead on average.
arXiv Detail & Related papers (2025-07-21T20:37:35Z) - Type-Constrained Code Generation with Language Models [51.03439021895432]
Large language models (LLMs) produce uncompilable output because their next-token inference procedure does not model formal aspects of code.
We introduce a type-constrained decoding approach that leverages type systems to guide code generation.
Our approach reduces compilation errors by more than half and increases functional correctness in code synthesis, translation, and repair tasks.
arXiv Detail & Related papers (2025-04-12T15:03:00Z) - Inferring Pluggable Types with Machine Learning [0.3867363075280544]
This paper investigates how to use machine learning to infer type qualifiers automatically.
We propose a novel representation, NaP-AST, that encodes minimal dataflow hints for the effective inference of type qualifiers.
arXiv Detail & Related papers (2024-06-21T22:32:42Z) - Language Models for Text Classification: Is In-Context Learning Enough? [54.869097980761595]
Recent foundational language models have shown state-of-the-art performance in many NLP tasks in zero- and few-shot settings.
An advantage of these models over more standard approaches is the ability to understand instructions written in natural language (prompts)
This makes them suitable for addressing text classification problems for domains with limited amounts of annotated instances.
arXiv Detail & Related papers (2024-03-26T12:47:39Z) - Learning Type Inference for Enhanced Dataflow Analysis [6.999203506253375]
We propose CodeTIDAL5, a Transformer-based model trained to reliably predict type annotations.
Our model outperforms the current state-of-the-art by 7.85% on the ManyTypes4TypeScript benchmark.
We present JoernTI, an integration of our approach into Joern, an open source static analysis tool.
arXiv Detail & Related papers (2023-10-01T13:52:28Z) - Generative Type Inference for Python [62.01560866916557]
This paper introduces TypeGen, a few-shot generative type inference approach that incorporates static domain knowledge from static analysis.
TypeGen creates chain-of-thought (COT) prompts by translating the type inference steps of static analysis into prompts based on the type dependency graphs (TDGs)
Experiments show that TypeGen outperforms the best baseline Type4Py by 10.0% for argument type prediction and 22.5% in return value type prediction in terms of top-1 Exact Match.
arXiv Detail & Related papers (2023-07-18T11:40:31Z) - TypeT5: Seq2seq Type Inference using Static Analysis [51.153089609654174]
We present a new type inference method that treats type prediction as a code infilling task.
Our method uses static analysis to construct dynamic contexts for each code element whose type signature is to be predicted by the model.
We also propose an iterative decoding scheme that incorporates previous type predictions in the model's input context.
arXiv Detail & Related papers (2023-03-16T23:48:00Z) - On The Ingredients of an Effective Zero-shot Semantic Parser [95.01623036661468]
We analyze zero-shot learning by paraphrasing training examples of canonical utterances and programs from a grammar.
We propose bridging these gaps using improved grammars, stronger paraphrasers, and efficient learning methods.
Our model achieves strong performance on two semantic parsing benchmarks (Scholar, Geo) with zero labeled data.
arXiv Detail & Related papers (2021-10-15T21:41:16Z) - Type4Py: Deep Similarity Learning-Based Type Inference for Python [9.956021565144662]
We present Type4Py, a deep similarity learning-based type inference model for Python.
We design a hierarchical neural network model that learns to discriminate between types of the same kind and dissimilar types in a high-dimensional space.
Considering the Top-1 prediction, Type4Py obtains 19.33% and 13.49% higher precision than Typilus and TypeWriter, respectively.
arXiv Detail & Related papers (2021-01-12T13:32:53Z) - How to Probe Sentence Embeddings in Low-Resource Languages: On
Structural Design Choices for Probing Task Evaluation [82.96358326053115]
We investigate sensitivity of probing task results to structural design choices.
We probe embeddings in a multilingual setup with design choices that lie in a'stable region', as we identify for English.
We find that results on English do not transfer to other languages.
arXiv Detail & Related papers (2020-06-16T12:37:50Z) - LambdaNet: Probabilistic Type Inference using Graph Neural Networks [46.66093127573704]
This paper proposes a probabilistic type inference scheme for TypeScript based on a graph neural network.
Our approach can predict both standard types, like number or string, as well as user-defined types that have not been encountered during training.
arXiv Detail & Related papers (2020-04-29T17:48:40Z)
This list is automatically generated from the titles and abstracts of the papers in this site.
This site does not guarantee the quality of this site (including all information) and is not responsible for any consequences.