dongzhen6554 2015-05-24 15:03
浏览 31

为什么分解式导入语句更好?

The official tour of Go, after exhibiting a factored import like this...

import (
    "fmt"
    "math"
)

... contains the following slightly unclear remark:

You can also write multiple import statements, like:

import "fmt"
import "math"

But it is good style to use the factored import statement.

Is there actually any concrete advantage to using one approach over the other - such as a difference in behaviour or an easy-to-make typo that is only a danger with one of the two syntaxes - or is this just an arbitrary style convention?

  • 写回答

2条回答 默认 最新

  • dty5753 2015-05-24 15:14
    关注

    There is no difference except for the amount of typing you have to do. A good sized program or package can easily have a dozen or more imported packages so why keep typing the same word (import) time and again when you can achieve the same with a pair of ().

    Though most people probably use GoImports nowadays anyway.

    评论

报告相同问题?

悬赏问题

  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程