Golang中的println与fmt.Prinltn的区别与输出顺序问题

引言

在Go的学习过程中,发现多数文章中的代码中输出都是使用fmt.Println(),而自己在IDE中测试时,发现可以像一些语言中一样直接使用print或者println来输出内容,于是好奇既然有更加方便的输出方式,那么为何大家仍然使用需要有依赖的fmt包中的输出呢?于是在网上查了一下相关的资料。

print(ln)与fmt.print(ln)

在[http://golang.org/ref/spec#Bootstrapping]中的文档中,对于内置的输出函数printprintln等有如下描述

Current implementations provide several built-in functions useful during bootstrapping. These functions are documented for completeness but are not guaranteed to stay in the language. They do not return a result.

简单翻译一下,就是说在Go当前的实现中,提供了一些自举过程中有用的内置函数,这些函数已经被完整地记录,但是Go的设计者并不保证这些函数会一直保留在语言中。

因此,可以看到,目前阶段,println被设计出来并不是主要为了支持各种不同的输出模式,而是主要被用作一个debug工具。对于开发人眼来说是非常好用的,因为它们比不需要依赖项,已经被内置在编译器中,但是并不适用于生产环境。

如果在生产环境的代码中需

你可能感兴趣的:(Go,Go,Golang,println,fmt.println,顺序)