01-03-2018 03:36 PM
@PrimaryKey wrote:
I will heed your advice - Give us interfaces! 😄
Excellent! Good practice! But I am not the target. Direct your energies toward convincing the NI Powers That Be that I (or someone!) should be allowed to work on it sooner than later.
01-03-2018 04:06 PM
@AristosQueue (NI) wrote:
If you can find me such a monstrous construct in any other professional programming language, I'm happy to take a look at use cases,
Don't they have this? Stolen from the internet somewhere:
Class1 a; Class2 b; if (o is Class1) { Console.WriteLine("o is Class1"); a = (Class1)o; } else if (o is Class2) { Console.WriteLine("o is Class2"); b = (Class2)o; } else { Console.WriteLine("o is neither Class1 nor Class2."); }
01-04-2018 09:55 AM
Yes, they do. And so do we: That code is exactly equivalent to "To More Specific" followed by "Case Structure", nested as needed. What they do not have is any sort of "switch" structure to assist with mass type testing. The reason they do not have any such structure is that the code that you posted is widely discouraged as a bad idea. No one is pushing to make it easier to do. Most developers I know would tell you to use that kind of type testing as a last, somewhat desperate, resort, not a first-class language structure.
01-04-2018 10:32 AM
@AristosQueue (NI) wrote:
Yes, they do. And so do we: That code is exactly equivalent to "To More Specific" followed by "Case Structure", nested as needed.
Ahh, but "nested as needed" is very painful and ugly. The if-elseif structure above isn't as good a "switch" structure, but it is vastly better than the nested nightmare one sometimes has to do in LabVIEW (seen especially with control references, where one cannot use dynamic dispatch).
01-09-2018 12:04 PM
drjdpowell wrote:Ahh, but "nested as needed" is very painful and ugly. The if-elseif structure above isn't as good a "switch" structure, but it is vastly better than the nested nightmare one sometimes has to do in LabVIEW (seen especially with control references, where one cannot use dynamic dispatch).
If I could make it more painful in C#, I would. And I've read papers by the C# designers that suggest they would likewise.
I used to champion this kind of type structure idea -- you can find posts written by me in the forums, I'm sure. There are times when we all have to do this kind of type testing, and it is tedious. But the longer I've worked on this and the more customer code I've evaluated, the more I've come to believe that the pain in those times is rare enough to justify the deterrent aspects. That's my evaluation. Obviously, that's a judgement call, and developers with different experiences may decide differently.