Story Details

  • Do any languages specify package requirements in import / include statements?

    Posted: 2025-01-20 14:21:05

    The Hacker News post discusses whether any programming languages allow specifying package dependencies directly within import or include statements, rather than separately in a dedicated dependency management file. The original poster highlights the potential benefits of this approach, such as improved clarity and ease of understanding dependencies for individual files. They suggest a syntax where version numbers or constraints could be incorporated into the import statement itself. While no existing mainstream languages seem to offer this feature, some commenters mention related concepts like import maps in JavaScript and conditional imports in some languages. The core idea is to make dependency management more localized and transparent at the file level.

    Summary of Comments ( 47 )
    https://news.ycombinator.com/item?id=42768990

    The Hacker News comments discuss the pros and cons of specifying package requirements directly within import statements. Several commenters appreciate the clarity and explicitness this would bring, as it makes dependencies immediately obvious and reduces the need for separate dependency management files. Others argue against it, citing potential drawbacks like redundancy, increased code verbosity, and difficulties managing complex dependency graphs. Some propose alternative solutions, like embedding version requirements in comments or using language-specific mechanisms for dependency specification. A few commenters mention existing languages or tools that offer similar functionality, such as Nix and Dhall, pointing to these as potential examples or inspiration for how such a system could work. The discussion also touches on the practical implications for tooling and build systems, with commenters considering the impact on IDE integration and compilation processes.