Intersting Stuff. The media length looked too much but it was a short discussion at the end with many things left unaddressed.
Handling Overloaded Function
For overloaded function(s), there must be a single case specification, or each function must be addressed seperately.
Moreover, Unlike Java, C# allows funtion overloading based upon return types, which When called in code, tend to confuse reader/compiler.
For example,to multiply 2 integers, a class can include following overloaded functions:
..
int mult(int, int); // call if result is less than max (int), return int
long mult(int, int); // call if max (int) <=result<=max (long), return long
float mult(int, int); // call if max (long) <=result<=max (float), return float
double mult(int, int); // call if max (long) <=result<=max (double), return double
...
Compiler Intelligence conflicting software design principles
This is a Programmer responsibility and Compiler responsibility case, that is, what a programmer need to specify and what a compiler must assume.
This C/C++ code is self explanatory without any documentation/comments
...
unsigned x=[some expresion];
..
if (x)
...
...
The C/C++ compilers are intelligent enough to assume that condition will execute if x is a positive integer, and Java/ C# compilers require an explicit condition for that adding burden to programmer.
A fun case
As discussedm, Spec is applied on C code to catch/handle every possible case. Learning the languaage, this is the first piece of code developers eneter:
#include <stdio.h>
int main()
{
printf("xyz"); //xyz can be any string
return 0;
}
Going deep in the language, at a stage programmer discover that printf() in fact returns a value, which is usually a positive integer but in the most rare case, it can be negative indicating an exception. Applying spec on rare cases like this, perhaps once in a lifetime sort of case...