question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Discussion: do we always need two import statements?

See original GitHub issue

So this is just something I thought about when reading the new Ceylon tour page about modules and came to the part about the Gotcha of Ceylon always needing two import statements.

Reading that and remembering that quite a number of times when adding a new import to a module I go like “grrr, why am I basically copying this line twice?” I decided to ask the question:

“Really, why exactly do we always have to have two import statements?”

I mean in a Java world where there is(was) no modularity perhaps I can understand needing to import in each source file (after all there isn’t a central place to put them anyway). But in Ceylon what does that gain us exactly? Especially in a time where almost everybody uses IDEs which make looking up things very easy it doesn’t seem as necessary to have the imports appear at the top of each source file.

So how about adding the possibility to mention the declaration you want to import for all files in a module right in the module descriptor?

Like this:

module mymodule "1.0.0" {
    // Import a Ceylon module
    import ceylon.collection "1.3.0" {
        HashMap
    }
    // Import a native module
    import java.base "8" {
        java.util { JMap = Map, JHashMap = HashMap }
    }
}

You would of course still have the current way. But I see it like this: some people like to specify each and every import, others don’t care so much and just use { ... }. This would just be a power-version of that.

Issue Analytics

  • State:open
  • Created 7 years ago
  • Reactions:3
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

3reactions
LisiLisenokcommented, Nov 3, 2016

The feature might be available for packages also, like:

package mymodule.mypackage "1.0.0" {
    // Import a Ceylon module
    import ceylon.collection "1.3.0" {
        HashMap
    }
    // Import a native module
    import java.base "8" {
        java.util { JMap = Map, JHashMap = HashMap }
    }
}
0reactions
xkr47commented, Nov 3, 2016

I vote for both!

The version number is not supposed to be in the package statement I guess?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Good or bad practice in Python: import in the middle of a file
PEP 8 authoritatively states: Imports are always put at the top of the file, just after any module comments and docstrings, and before ......
Read more >
Import Statement in Java - GeeksforGeeks
An import statement tells the compiler the path of a class or the entire package. It is unlike “#include” in C++, which includes...
Read more >
PEP 8 – Style Guide for Python Code
Imports should usually be on separate lines: · Imports are always put at the top of the file, just after any module comments...
Read more >
Python Import Statements: A Guide | Career Karma
The Python import statement imports code from one module into another program. You can import all the code from a module by specifying...
Read more >
Using Package Members - Java™ Tutorials
The Static Import Statement ... There are situations where you need frequent access to static final fields (constants) and static methods from one...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found