添加/替换/修补标准库

huangapple go评论86阅读模式
英文:

Adding/replacing/patching std libraries

问题

我有一个(自己编写的)运行时库,多年来在各种编程项目中使用过。它最初是一个Pascal库,在Turbo Pascal的早期阶段开始,并且后来经历了C、Perl和Lua的演变。我现在正在考虑将其转移到Go语言(不仅仅是因为Go和Lua之间有一些有趣的相似之处)。Go的标准库的很大一部分与我的库做的事情差不多(例如,flag包或正则表达式等),在这种情况下,我可以直接使用它们,或者写一个小的接口层来隐藏差异。

问题出现在那些我自己的模型与Go的模型差异太大,简单的接口层无法隐藏差异的包(一个例子是目录遍历函数)。我看到两种前进的方式:重新实现我的代码作为一个Go包;或者修补一些现有的Go运行时包。

我倾向于选择第一种选项,不仅仅是因为这将帮助我掌握这门语言。另一方面,我经常为了满足自己的需求修补源代码,对于这种方法我感到很舒适。修改将是局部的,将来将Go的运行时库的新版本与我的修改合并起来也不应该太困难。

所以,这样做可行吗?建议这样做吗?还是我必须将Go的源代码视为只读的?

英文:

I have a (self-written) runtime library which I have used in various programming projects over the years. It started life as a Pascal library in the early days of Turbo Pascal and has since progressed through incarnations in C, Perl and Lua. I am now contemplating to move this over to Go (not least because there are some interesting parallels between Go and Lua). A good part of Go's std library does more or less what my own libraries do (for instance, the flag package or the regex stuff) in which case I can either use them directly or get away with writing a small interface layer.

Problems start with those packages where my model is too different from Go's for a simple interface layer to hide the differences (a case in point are the directory-walking functions). I see two ways forward: re-implement my code as a Go package; or patch some of the existing Go runtime packages.

I am leaning towards the first option, not least because this will help me to get to grips with the language. Then again, I've often patched source code for my own requirements and I am comfortable with that approach. The changes would be localised and it shouldn't be too difficult to merge future version of Go's runtime library with my changes.

So is it feasible, advisable to do that or do I have to regard the Go sources as read only?

答案1

得分: 1

> 那么这样做可行吗?

不行。一旦你修改Go标准库,所有依赖于标准库的包都会出问题。

> 那么这样做是否明智?

不,一点也不明智。

> 我需要将Go源代码视为只读吗?

是的。

请注意,你所称之为“runtime”的不是Go运行时,而是Go的标准库。

英文:

> So is it feasible ... ?

No. Everything will break once you touch the Go stdlib as every package out there relies on the stdlib.

> So is it ... advisable to do that ...?

No, not at all.

> [D]o I have to regard the Go sources as read only?

Yes.

Note that what you call "runtime" is not the Go runtime but the Go's standard library.

huangapple
  • 本文由 发表于 2017年3月23日 18:29:46
  • 转载请务必保留本文链接:https://go.coder-hub.com/42973424.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定