期权严格的和.NET的程序员VB6期权、程序员、严格、NET

2023-09-02 10:28:30 作者:十秒性格

我是$ P $上的Visual Basic 2005 pparing一类针对Visual Basic 6的程序员迁移到.NET平台。 我想咨询的话是否要推荐他们始终启用选项严格或没有。 我已经与C风格的编程语言,主要是Java和C#专门的工作,所以对我的明确铸造是我总是希望我必须这样做,因为它从来就不是一个选项。不过,我认识到与已经内置支持的语言工作的价值后期绑定,因为不必过分明确有关在code类型确实节省了时间。这是通过流行的扩散进一步证实动态类型语言,甚至在.NET平台上的动态语言运行时。 考虑到这一点,应该有人谁是接近.NET首次使用VB.NET和VB6的背景被鼓励进入的心态具有编译时类型检查工作,因为那是在CLR的最佳实践?或者是OK继续享受后期绑定的好处是什么?

I'm preparing a class on Visual Basic 2005 targeting Visual Basic 6 programmers migrating to the .NET platform. I would like a word of advice about whether to recommend them to always enable Option Strict or not. I've worked exclusively with C-style programming languages, mostly Java and C#, so for me explicit casting is something I always expect I have to do, since it's never been an option.However I recognize the value of working with a language that has built-in support for late-binding, because not having to be excessively explicit about types in the code indeed saves time. This is further proved by the popular diffusion of dynamic typed languages, even on the .NET platform with the Dynamic Language Runtime. With this in mind, should someone who is approaching .NET for the first time using VB.NET and with a VB6 background be encouraged to get into the mindset of having to work with compile-time type checking because that's the "best practice" in the CLR? Or is it "OK" to continue enjoying the benefits of late-binding?

推荐答案

是的! Option Strict为绝对与.net最佳实践。强调的是,净是它的核心强类型的平台,并将于直到DLR更完全的​​支持。除了少数例外,每个点心功能应宣布去用它一个明确的类型。比如像LINQ或嘘声和JScript是证明该规则的例外。

Yes! Option Strict is definitely a best practice with .Net. Emphasize that .Net is at it's core a strongly typed platform, and will be until the DLR is more completely supported. With few exceptions, every Dim and Function should have an explicit type declared to go with it. Things like LINQ or Boo and JScript are the exceptions that prove the rule.

下面是一些其他的事情要指出。我敢肯定,你也知道了这一切,但我不得不继续努力,保持了很多VB.Net $ C $了C写的前VB6ers,所以这是东西痛处对我来说:

Here are some other things to point out. I'm sure you're well aware of all this, but I've had to work with and maintain a lot of VB.Net code written by former VB6ers, and so this is something of a sore spot for me:

请不要使用旧的字符串函数: LEN() REPLACE() TRIM()等 在匈牙利疣不再推荐。 oMyObject sMyString 不洁净。他们展示微软的设计准则如果他们不相信你。 确保他们了解新 AndAlso / OrElse运算逻辑运算符 参数化查询和现代化的ADO.Net。不能强调不够。他们不应该需要调用的CreateObject()试。 在范围的工作方式不同(而且更重要的是)在.net中比在VB6。 VB.Net还有模块,但他们现在更类似于一个静态类。重要的是要理解如何在真实的面向对象的开发环境是不同的,而不是由VB6提供的部分面向对象的支持。有没有更好的理由了,让方法运行到不敬虔的长度。 确保他们得到介绍泛型和接口(​​包括 IEnumeralbe(对T)),并了解为什么他们不应该使用的ArrayList 试。 Don't use the old string functions: LEN(), REPLACE(), TRIM(), etc Hungarian warts are no longer recommended. oMyObject and sMyString are not kosher. Show them the reference in Microsoft's Design Guidelines if they don't believe you. Make sure they learn about the new AndAlso/OrElse logical operators PARAMETERIZED QUERIES and modern ADO.Net. Can't emphasize that enough. They should never need to call CreateObject() again. Scope works differently (and is more important) in .Net than it was in VB6. VB.Net still has modules, but they're now more analogous to a static class. It's important to understand how developing in a real object oriented environment be different, as opposed to the partial OOP support provided by VB6. There's no good reason anymore to allow methods to run to ungodly lengths. Make sure they get an introduction to Generics and Interfaces (including IEnumeralbe(Of T)), and learn why they should never use an ArrayList again.

我可以继续下去,但我只是点你VB.Net的隐藏功能问题收出这一言论。

I could keep going, but I'll just point you to the Hidden Features of VB.Net Question to close out this rant.