Go是“进口”吗?语法特殊且独特? [英] Is the Go "import" syntax special and unique?

查看:175
本文介绍了Go是“进口”吗?语法特殊且独特?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

http://golang.org/ref/spec#Import_declarations

  importpackage1

import(package1;package2)

import (
package1
package2

导入语法特别是用于导入包的东西?它看起来像一个函数调用,使用;而不是,来进行参数化。它似乎甚至可能是一个ruby-esque方法调用(即:sans())。b
$ b

PS
以为我会问这个以获得一些观点。我非常喜欢和Go一起工作,但它的一些语法看起来有点不一致,有时冗长。让我想知道为它创建一个预处理器是多么困难,就像C ++是/正在C来清理一些语法一样。称它为Go ++(走得更快)。我在考虑Objective C 2.0作为改善程序员工作流程的一个很好的例子(例如:dictionary / array / number literals)。 Go ++在概念上也类似于exlixir-lang.org(在Erlang之上的一个语法增强)。

import 是特殊的。它需要位于文件的顶部,它的参数始终是文字。这必须发生,因为尝试管理依赖关系以加快构建时间的工作非常艰巨。



它也不能只是一个常规环境,因为它将变量注入当前范围,这是其他函数无法做到的。



至于语法,是的,有些部分并不令人愉快。但对于我和其他大多数写Go的人来说,这是我所遇到的一个非常小的问题。另一方面,语法的解析非常简单,所以工具相对简单,这就是为什么我只是为了几个按键而改变语法的原因。


http://golang.org/ref/spec#Import_declarations

import "package1"

import ("package1";"package2")

import (
        "package1"
        "package2"
       )

Is the "import" syntax something especially made for importing packages? It looks like a function call that uses ";" instead of "," for parameterization. It seems that it could even have been a ruby-esque method call (ie: sans "()")

PS Thought I'd ask this to get some perspective. I'm really enjoying working with Go, but some of its syntax seems a bit inconsistent and sometimes verbose. Makes me wonder how hard it would be to create a pre-processor for it like C++ is/was to C to clean up some of the syntax. Call it Go++ (go faster). I'm thinking of Objective C 2.0 as a great example to improving the programmer's workflow (eg: dictionary/array/number literals). Go++ would also be similar in concept to exlixir-lang.org (a syntactical enhancement on top of Erlang).

解决方案

Yes import is special. It's required to be at the top of the file and it's arguments are always literals. This has to happen because go does a lot with trying to manage dependencies to speed up build times.

It also can't just be a regular environment because it injects variables into the current scope, something no other function can do.

As for the syntax, yeah some parts are not exactly pleasant. But it's a pretty minor concern to me and most other people who write Go that I've encountered. On the upside, the syntax is dead simple to parse so tooling is relatively straightforward which is why I worry about just changing the syntax for a few keystrokes.

这篇关于Go是“进口”吗?语法特殊且独特?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆