.net bcl
As web programmers, we use a lot of strings to move data around the web. Often we’ll use a string to represent a date or an integer or a boolean. Basically "1" in instead of 1, or "April 1, 2009" rather than a proper ISO-8601 formatted culture-invariant date.
作为Web程序员,我们使用许多字符串在Web上移动数据。 通常,我们将使用字符串来表示日期,整数或布尔值。 基本上是“ 1”而不是1,或者是“ 2009年4月1日”,而不是正确的ISO-8601格式的文化不变日期。
While these strings are flying around via HTTP it's not a huge deal, but sometimes this loose, even sloppy, use of strings can leak into our own code. We might find ourselves leaving the data times as strings longer and longer, or not even bothering to convert them to their proper type at all. This problem is made worse by the proliferation of JSON, and schema-less/namespace-less XML (that I've often called "angle-bracket delimited files" as they're no more useful than CSVs in that point.
尽管这些字符串是通过HTTP传递的,但这并不是什么大问题,但是有时,这种松散甚至是草率的字符串使用可能会泄漏到我们自己的代码中。 我们可能会发现自己将数据时间留给字符串的时间越来越长,甚至根本不愿意将它们转换为正确的类型。 JSON和无模式/无命名空间的XML(我经常称其为“用尖括号分隔的文件”)使该问题变得更加严重,因为在那一点上它们比CSV更有用。
.NET 4.0 is pretty much locked down, but version 4.1 still has some really cool "Futures" features that are being argued about. If we don't know the type of a string, or we want to leave the string, as a string, longer than usual, what if we had an class that could be both a string and another type, essentially deferring the decision until the variable is observed. For example:
.NET 4.0几乎处于锁定状态,但4.1版仍具有一些很酷的“ Futures”功能,这些功能正在争论中。 如果我们不知道字符串的类型,或者我们想将字符串作为字符串保留,比平常更长,那么如果我们拥有一个既可以是字符串又可以是另一种类型的类,将决定推迟到观察到变量。 例如:
StringOr<int> userInput= GetUserInput("Quantity");
string szUserInput=userInput.StringValue;
int intUserInput=userInput.OtherValue;
Sometimes you just don't know, or can't know.
有时您只是不知道,或者不知道。
This reminds me of a similar, but orthogonal physics concept, that of the Heisenberg Uncertainty Principle. Sometimes you know that an object is a string, and sometimes you know how long it is, but you can’t know both at the same time.
这让我想起了类似的但正交的物理概念,即海森堡不确定性原理。 有时您知道一个对象是一个字符串,有时您知道该对象有多长,但是您无法同时知道它们。
One of my favorite jokes goes:
我最喜欢的笑话之一是:
Heisenberg gets pulled over by the police. The officer asks, “Do you know how fast you were going?” Heisenberg answers, “No, but I know exactly where I am!”
海森堡被警方拦下。 警官问:“你知道你要走多快吗?” 海森堡回答:“不,但我确切地知道自己在哪里!”
This library doesn't solve THAT issue, with respect to strings, but we’ve got folks in DevDiv working on this and many other metaphysical - and physical - problems as they apply to computer science.
该库无法解决关于字符串的THAT问题,但是在DevDiv中,我们让人们正在研究此问题以及许多其他应用于计算机科学的形而上学和物理问题。
Big thanks to Eilon, who's working hard to get this pushed into the .NET 4.1 Base Class Library. Visit Eilon's blog for more details on this new library, more code, graphics and details on how Intellisense will handle this new case.
非常感谢Eilon ,他正努力将其推送到.NET 4.1基类库中。 请访问Eilon的博客,以获取有关此新库的更多详细信息,更多代码,图形以及Intellisense将如何处理此新案例的详细信息。
Hopefully, someone is working to make this important new library Open Source.
希望有人正在努力使这个重要的新库开源。
Your thoughts, Dear Reader?
您的想法,亲爱的读者?
Related Posts
相关文章
Rob Conery on StringOr<T> and Duck Typing and the Probably() extension
Rob Conery在StringOr <T>和Duck打字以及Probably()扩展上
Eilon Lipton's RFC and Analysis with Pictures and Code Samples
Eilon Lipton的RFC和带有图片和代码示例的分析
Jonathan Carter on the ramifications to String-based User Input
乔纳森·卡特的后果 到基于字符串的用户输入
翻译自: https://www.hanselman.com/blog/net-41-preview-new-base-class-library-bcl-extension-methods-rfc
.net bcl