Double syntax doesn't sound like V.
Is there a reason for 2 syntaxes for import?
Indeed it goes against V's philosophy of having it in one-way but it's also unnecessary to type too many import keywords when importing multiple modules and at the same time wasting whitespaces and parentheses when you are just gonna import a single module.
In short, there are specific cases wherein you would use the former and the latter.
@nedpals
I see your point.
I think that we could have a golden rule:
only one import statement per file (or none at all).
So for multiple imports the only syntax would be:
import (
module_a
module_b
)
For a single import there are 3 possibilities:
style A:
import ( // the only valid syntax for single import
my_module
)
style B:
import my_module // the only valid syntax for single import
style C:
import ( // valid syntax for single import
my_module
)
import my_module // also valid syntax for single import
At least this kind of code would be rejected by the compiler if using the only-one-import rule:
import module_a
import (
module_b
module_c
)
import module_d
import module_e
import (
module_f
)
import (
module_g
module_h
)
Yes, this has been discussed before, and I had the same thought.
It will be handled by vfmt. import foo if there's only one import, import (...) otherwise.
Tooling would get simpler, if the only supported syntax was a single line import module.
Normally v files do not import many things, so I think import ( list_of_modules ) does not save many keystrokes.
Compare:
import (
net.http
os
json
filepath
)
to
import net.http
import os
import json
import filepath
In the second variant, you can find all the imports that a file uses just by grepping for ^import .
I agree with you @spytheman
Just today I had to find where a certain module was imported, but it was impossible to do with grep.
I think
grep -E '^(\s+module.name|import module.name)$'
# -or-
grep -E '^(\s+|import )module.name$'
should do it, no?
@runeimp yes, your grep pattern will work for most cases. It however may have false positives, if your modules have enums in them, because enums also use the same syntax of list of identifiers, each on a separate line.
Closed. import () was deprecated in favor of grep-able import syntax (aka import modulea).
Most helpful comment
Tooling would get simpler, if the only supported syntax was a single line
import module.Normally v files do not import many things, so I think
import ( list_of_modules )does not save many keystrokes.Compare:
to
In the second variant, you can find all the imports that a file uses just by grepping for ^import .