为什么不推荐在同一个解决方案中混合使用 VB.Net 和 C#?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15706564/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Why is mixing VB.Net and C# in the same solution not recommended?
提问by JMK
I was reading this questionwhen I noticed a curious comment underneath:
当我注意到下面有一条奇怪的评论时,我正在阅读这个问题:
not sure what the question is: you can use VB.NET and C# projects in one solution (though I wouldn't recommend doing so).
不确定问题是什么:您可以在一个解决方案中使用 VB.NET 和 C# 项目(尽管我不建议这样做)。
I do this quite a bit, as we have legacy VB.Net code, and new code is written in C#. Is this really not recommended? Why not?
我经常这样做,因为我们有遗留的 VB.Net 代码,而新代码是用 C# 编写的。这真的不推荐吗?为什么不?
回答by Reed Copsey
There is no real reason to avoid this, other than adding complexity from having two languages in one "solution".
除了在一个“解决方案”中使用两种语言而增加复杂性之外,没有真正的理由来避免这种情况。
Your scenario (working with a legacy product, but adding new features) is a valid reason to have both languages used in a single solution, in my opinion.
在我看来,您的方案(使用旧产品,但添加新功能)是在单个解决方案中使用两种语言的正当理由。
回答by Justin Niessner
The only reason that it wouldn't be recommended is consistency. Most developers prefer to deal with a single language when working on an application. Having a single language also means that your developers only need to know a single language rather than knowing both VB.NET and C# (even though the two are extremely similar).
不推荐它的唯一原因是一致性。大多数开发人员在处理应用程序时更喜欢使用单一语言。拥有一种语言也意味着您的开发人员只需要了解一种语言,而不是同时了解 VB.NET 和 C#(即使两者非常相似)。
If you need to mix legacy VB.NET and C#, there's no reason not to.
如果您需要混合使用旧版 VB.NET 和 C#,没有理由不这样做。
回答by antinescience
It's a matter of "use the best tools available to you for what you're building". Mixing C# and VB withina project isn't recommended (for obvious "it won't compile" reasons), but there's no point in continuing to write old code in VB if you feel your development team can operate faster and in a more maintainable fashion using C#.
这是一个“为你正在构建的东西使用最好的工具”的问题。不建议在一个项目中混合使用 C# 和 VB (出于明显的“它不会编译”的原因),但是如果您觉得您的开发团队可以更快地操作并且更易于维护,那么继续在 VB 中编写旧代码是没有意义的时尚使用 C#。
We've been doing this at my office for the past few months (in a similar legacy code situation) and have yet to run into any major issues (beyond potential lost dev time due to context switching), and we've gained incredibly from working with a language that we all feel more comfortable with.
过去几个月我们一直在我的办公室这样做(在类似的遗留代码情况下)并且还没有遇到任何重大问题(除了由于上下文切换可能导致的开发时间损失之外),我们从使用一种我们都觉得更舒服的语言。
More information on task switching here. I really do feel like the benefits we see on a daily basis from our level of comfort with C# outweighs the cost of occasionally having to dip back into the legacy pool.
有关任务切换的更多信息,请参阅此处。我真的觉得我们每天从我们对 C# 的舒适程度中看到的好处超过了偶尔不得不重新回到遗留池中的成本。
回答by MeTitus
Why would you want to do that? If you have legacy code what you want to use, you keep that code in its own components, you don't mix it with the new code. It is not recommended because it does not promote "Clean Code". It can lead you to have a solution that is difficult to read and maintain.
你为什么想这么做?如果您有想要使用的遗留代码,则将该代码保留在其自己的组件中,不要将其与新代码混合。不推荐这样做,因为它不提倡“清洁代码”。它可能会导致您拥有一个难以阅读和维护的解决方案。
回答by Parimal Raj
Its just a matter of person choice. if you are comfortable with both the languages, You surely can use them in same solution.
这只是个人选择的问题。如果您对这两种语言都感到满意,您当然可以在同一个解决方案中使用它们。
Using a single language in a solution seems easily maintainable. hence it is preferred.
在解决方案中使用单一语言似乎很容易维护。因此它是首选。
回答by Jakob Bowyer
Mixing code in solutions can get real messy real quickly, its never clear what method you are calling from where, to keep it nice. Develop in separate Solutions, it will keep your projects easier to track and make sure you are not confusing languages inside projects
在解决方案中混合代码会很快变得非常混乱,它永远不会清楚你从哪里调用什么方法,以保持良好。在单独的解决方案中进行开发,这将使您的项目更容易跟踪,并确保您不会混淆项目中的语言

