<p>i'm building a framework, and i want to use the import dot feature lightly,<br/>
it just will make the API looks great<br/>
so what limitations i could restrict myself to it, to not facing any errors doing this?</p>
<hr/>**评论:**<br/><br/>quiI: <pre><p>I would recommend against it. Just obfuscates where a function/struct/whatever comes from when reading code. </p></pre>kpmy: <pre><p>Just like "make" or "append".</p></pre>nemith: <pre><p>If you are using import . a lot then maybe you are trying to hard to make packages more like fancy name spaces. </p>
<p>I find a lot of go programs i find on Github use WAY too many packages. One is probably enough. </p></pre>junajted: <pre><p>One limitation (main?) is there can't be two exported identifiers (structs, functions,...) with the same name (i.e. <code>pkg1.Man</code> and <code>pkg2.Man</code>, assuming both packages will be imported with dot), but that doesn't apply for unexported identifiers.</p></pre>mrwnmonm: <pre><p>yeah, i know this is the main idea<br/>
but because the go team doesn't recommend using it, i thought there are other things could cause errors</p></pre>barsonme: <pre><p>That's pretty much the worst reason. Why do it?</p>
<p>Is writing</p>
<pre><code>bytes.Compare
</code></pre>
<p>That much more work than</p>
<pre><code>Compare?
</code></pre>
<p>Edit: I meant to type "only" instead of "worst" but autocorrect hates me. </p></pre>junajted: <pre><p>Maybe this library will be a big and OP will want to refactor it to multiple files (possibly creating sub-packages too) and at the end of the day he's going to offer library's API under a single namespace.</p></pre>[deleted]: <pre><p>I think if you are writing code that other people (including yourself a few months later) will read then you shouldn't use dot imports. Instead give your package an easy to read name that combines well with function names inside the package.</p></pre>robbles: <pre><p>I believe some of the common code tooling, like "godef", will have trouble with this practice as well.</p>
<p>Recently I used a package whose github repo didn't match it's package name, and the resulting implicit name broke several of these tools. I'm guessing godef and oracle would not be able to find the definitions with an " import dot"</p></pre>THUNDERGROOVE: <pre><p>I only do it when I'm importing my own packages</p></pre>
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码`
- 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传