Better obfuscation?
-
In the MS doc "New features in C# 4.0" there is this example of applying "Betterness rules" to overload resolution... Given these overloads of M.. M(string s, int i = 1); M(object o); M(int i, string s = “Hello”); M(int i); which does M(5) use? Given these overloads, we can see the working of the betterness rules. M(string,int) is not applicable because 5 doesn’t convert to string. M(int,string) is applicable because its second parameter is optional, and so, obviously are M(object) and M(int). M(int,string) and M(int) are both better than M(object) because the conversion from 5 to int is better than the conversion from 5 to object. Finally M(int) is better than M(int,string) because no optional arguments are omitted. Thus the method that gets called is M(int). Ok, clear enough for this example...but I hope I don't have to debug code that uses this feature a lot!
73
-
In the MS doc "New features in C# 4.0" there is this example of applying "Betterness rules" to overload resolution... Given these overloads of M.. M(string s, int i = 1); M(object o); M(int i, string s = “Hello”); M(int i); which does M(5) use? Given these overloads, we can see the working of the betterness rules. M(string,int) is not applicable because 5 doesn’t convert to string. M(int,string) is applicable because its second parameter is optional, and so, obviously are M(object) and M(int). M(int,string) and M(int) are both better than M(object) because the conversion from 5 to int is better than the conversion from 5 to object. Finally M(int) is better than M(int,string) because no optional arguments are omitted. Thus the method that gets called is M(int). Ok, clear enough for this example...but I hope I don't have to debug code that uses this feature a lot!
73
-
In the MS doc "New features in C# 4.0" there is this example of applying "Betterness rules" to overload resolution... Given these overloads of M.. M(string s, int i = 1); M(object o); M(int i, string s = “Hello”); M(int i); which does M(5) use? Given these overloads, we can see the working of the betterness rules. M(string,int) is not applicable because 5 doesn’t convert to string. M(int,string) is applicable because its second parameter is optional, and so, obviously are M(object) and M(int). M(int,string) and M(int) are both better than M(object) because the conversion from 5 to int is better than the conversion from 5 to object. Finally M(int) is better than M(int,string) because no optional arguments are omitted. Thus the method that gets called is M(int). Ok, clear enough for this example...but I hope I don't have to debug code that uses this feature a lot!
73
That's no feature, more like a disaster waiting to happen, well maybe not quit a disaster. I just hope you can turn up the warnings to point this kind of thing out, like when you don't explicitly cast a float to an int for example.
My current favourite phrase: I've seen better!
-SK Genius
Source Indexing and Symbol Servers Vehicle Simulation Demo - Mostly Works
-
In the MS doc "New features in C# 4.0" there is this example of applying "Betterness rules" to overload resolution... Given these overloads of M.. M(string s, int i = 1); M(object o); M(int i, string s = “Hello”); M(int i); which does M(5) use? Given these overloads, we can see the working of the betterness rules. M(string,int) is not applicable because 5 doesn’t convert to string. M(int,string) is applicable because its second parameter is optional, and so, obviously are M(object) and M(int). M(int,string) and M(int) are both better than M(object) because the conversion from 5 to int is better than the conversion from 5 to object. Finally M(int) is better than M(int,string) because no optional arguments are omitted. Thus the method that gets called is M(int). Ok, clear enough for this example...but I hope I don't have to debug code that uses this feature a lot!
73
Can you imagine the reaction if you were doing a code review and came across something like that, the writer of such crap would be howled out of the building. Just b/c a language will allow you to write crap does not mean you should.
Never underestimate the power of human stupidity RAH
-
Can you imagine the reaction if you were doing a code review and came across something like that, the writer of such crap would be howled out of the building. Just b/c a language will allow you to write crap does not mean you should.
Never underestimate the power of human stupidity RAH
Mycroft Holmes wrote:
Just b/c a language will allow you to write crap does not mean you should.
That would make the lounge largely superfluous ;)
It's an OO world.
-
In the MS doc "New features in C# 4.0" there is this example of applying "Betterness rules" to overload resolution... Given these overloads of M.. M(string s, int i = 1); M(object o); M(int i, string s = “Hello”); M(int i); which does M(5) use? Given these overloads, we can see the working of the betterness rules. M(string,int) is not applicable because 5 doesn’t convert to string. M(int,string) is applicable because its second parameter is optional, and so, obviously are M(object) and M(int). M(int,string) and M(int) are both better than M(object) because the conversion from 5 to int is better than the conversion from 5 to object. Finally M(int) is better than M(int,string) because no optional arguments are omitted. Thus the method that gets called is M(int). Ok, clear enough for this example...but I hope I don't have to debug code that uses this feature a lot!
73
don't do funny things - there are certain ways to protect your software: ProGuard Obfuscator @ sourceforge[^] How-to obfuscate with ProGuard[^] and if you want to make sure your software is only used correctly, use dongles: Dongle @ wikipedia[^] regards Torsten
I never finish anyth...
-
In the MS doc "New features in C# 4.0" there is this example of applying "Betterness rules" to overload resolution... Given these overloads of M.. M(string s, int i = 1); M(object o); M(int i, string s = “Hello”); M(int i); which does M(5) use? Given these overloads, we can see the working of the betterness rules. M(string,int) is not applicable because 5 doesn’t convert to string. M(int,string) is applicable because its second parameter is optional, and so, obviously are M(object) and M(int). M(int,string) and M(int) are both better than M(object) because the conversion from 5 to int is better than the conversion from 5 to object. Finally M(int) is better than M(int,string) because no optional arguments are omitted. Thus the method that gets called is M(int). Ok, clear enough for this example...but I hope I don't have to debug code that uses this feature a lot!
73
I'd rather have an "that's ambigous, make up your mind" for the last two cases.
FILETIME to time_t
| FoldWithUs! | sighist | WhoIncludes - Analyzing C++ include file hierarchy -
In the MS doc "New features in C# 4.0" there is this example of applying "Betterness rules" to overload resolution... Given these overloads of M.. M(string s, int i = 1); M(object o); M(int i, string s = “Hello”); M(int i); which does M(5) use? Given these overloads, we can see the working of the betterness rules. M(string,int) is not applicable because 5 doesn’t convert to string. M(int,string) is applicable because its second parameter is optional, and so, obviously are M(object) and M(int). M(int,string) and M(int) are both better than M(object) because the conversion from 5 to int is better than the conversion from 5 to object. Finally M(int) is better than M(int,string) because no optional arguments are omitted. Thus the method that gets called is M(int). Ok, clear enough for this example...but I hope I don't have to debug code that uses this feature a lot!
73
-
In the MS doc "New features in C# 4.0" there is this example of applying "Betterness rules" to overload resolution... Given these overloads of M.. M(string s, int i = 1); M(object o); M(int i, string s = “Hello”); M(int i); which does M(5) use? Given these overloads, we can see the working of the betterness rules. M(string,int) is not applicable because 5 doesn’t convert to string. M(int,string) is applicable because its second parameter is optional, and so, obviously are M(object) and M(int). M(int,string) and M(int) are both better than M(object) because the conversion from 5 to int is better than the conversion from 5 to object. Finally M(int) is better than M(int,string) because no optional arguments are omitted. Thus the method that gets called is M(int). Ok, clear enough for this example...but I hope I don't have to debug code that uses this feature a lot!
73
VE2 wrote:
M(int i, string s = “Hello”);
M(int i);Is that actually valid code in C#? In C++ it wouldn't hold, because, like you said, M(5) would invoke M(int), and the only way to invoke M(int,string) would be to use two arguments, making the default argument "Hello" obsolete!