in Education by
This question already has answers here: Closed 10 years ago. Possible Duplicate: Best Practices: Option Infer What is the best way to mix VB.NET's Option Strict and the new Option Infer directives? I am developing a old solution, that was translated from VB6 to the VB.NET. Actually, the default options in files are Option Strict On Option Explicit On I want to use LINQ, and found that is easier to use also the Option Infer On. Less to write, less (so, easier) to read. However, a (conservative, from my point of view) part of the team keeps the Option Infer Off and insist do not use it at all, without explicitly explain the causes. In your opinion, what are the "dangers" of using Option Infer On, along with other two options (Strict and Explicit, both On)? JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
Code written with Option Infer on is no different in performance or type safety than code written with the same types explicitly declared. With that in mind, the arguments I could come up with against Option Infer are: Inconsistency between cases when the type must be specified and when it can be inferred. Class fields for one cannot be inferred, even if initialized inline. Variables holding lambdas (Dim f = Function(x) ...) do not always infer types. Variables that are not initialized must be given a type The strength of this argument is directly proportional to the consistency of style in your existing codebase. (For example, I sometimes still use underscores to continue lines when working with older code even when the newer compiler does not require them, if the rest of the code around it uses them.) Sometimes the type is not immediately obvious when looking through code. Dim temp = Foo() 'temp is type of Foo's return, which is... Workaround: Declare the variable's type when you feel the need. This is not a "danger" as much as a potential inconvenience. More so if you are not working in an environment where Intellisense cannot tell you the inferred type. The inferred type may end up being more specific than you really want in that case. Workaround: Specifically declare the type you want in that case. As the compiler catches cases when this is an issue, I wouldn't call it a "danger" per se. The only time I can think of where this would be an issue the compiler doesn't catch would be if you have different overloads of a method for the base and derived types or are shadowing methods in a derived type. I would argue that either of those cases are problems with the existing code and not with Option Infer. The usage of anonymous types that come up in LINQ queries could lead to larger methods than normal as they cannot be passed between methods. Workaround: Define named types when this occurs and break up methods as normal. This is more of a danger in as much as long methods are dangerous. The usual "how long is too long" discussions apply. It makes me look less productive because there are fewer KB in my code files from all those type names I don't have to type. (OK, this one is a joke.)

Related questions

0 votes
    Which of the following analysis are incredibly hard to infer? (a) Inferential (b) Exploratory (c) Causal ... and answers pdf, Data Science interview questions for beginners...
asked Oct 29, 2021 in Education by JackTerrance
0 votes
    A circuit is given in the figure below. We can infer that ________ (a) The circuit follows Reciprocity Theorem (b ... GATE EC Exam, Network Theory MCQ (Multiple Choice Questions)...
asked Oct 20, 2021 in Education by JackTerrance
0 votes
    A circuit is given in the figure below. We can infer that ________ (a) The circuit follows Reciprocity Theorem (b ... GATE EC Exam, Network Theory MCQ (Multiple Choice Questions)...
asked Oct 20, 2021 in Education by JackTerrance
0 votes
    A circuit is given in the figure below. We can infer that ________ (a) The circuit follows Reciprocity Theorem (b ... GATE EC Exam, Network Theory MCQ (Multiple Choice Questions)...
asked Oct 20, 2021 in Education by JackTerrance
0 votes
    What is the difference between correlation and causation? How can we infer the latter?...
asked Feb 5, 2021 in Technology by JackTerrance
0 votes
    To infer that an intervention is the real cause of a change: a.we must make sure that the change preceded ... that avoided the use of random assignment to treatment conditions....
asked Nov 30, 2020 in Technology by Editorial Staff
0 votes
0 votes
    An element is composed of: a. ON tag and OFF tag b. The content between the opening and closing tag c. Both a and b Select the correct answer from above options...
asked Nov 27, 2021 in Education by JackTerrance
0 votes
    What is the use of SET NOCOUNT ON/OFF statement?...
asked Nov 9, 2020 in Technology by Editorial Staff
0 votes
    This question already has answers here: Saving path in String (4 answers) Closed 5 years ago. I'm ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 30, 2022 in Education by JackTerrance
0 votes
    This question already has answers here: Saving path in String (4 answers) Closed 5 years ago. I'm ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 23, 2022 in Education by JackTerrance
0 votes
    This question already has answers here: Generic iterator (3 answers) Closed 7 years ago. Suppose I want to ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 16, 2022 in Education by JackTerrance
0 votes
    This question already has answers here: Generic iterator (3 answers) Closed 7 years ago. Suppose I want to ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 16, 2022 in Education by JackTerrance
0 votes
    This question already has answers here: Generic iterator (3 answers) Closed 7 years ago. Suppose I want to ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 15, 2022 in Education by JackTerrance
0 votes
    This question already has answers here: Generic iterator (3 answers) Closed 7 years ago. Suppose I want to ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 13, 2022 in Education by JackTerrance
...