D
Danny Liberty
Hi,
I've recently encountered some design problems due to the language
limitations of C#.
Here are the scenarios:
1. Suppose I have a numerous number of functions that I would like to
add an optional parameter to. Since C# does not support optional
parameters, I would have to duplicate all these functions and override
each of them with another parameter. Is this really necessary?? Is it
just me or is the result kind of ugly?
2. In C++ I could have defined a macro to instantiate an object and
then make a method call. For example:
#define MY_FUNC(x) MyObj a; a.func(x);
This would have been useful since I could use this macro in any scope
knowing that the destructor of MyObj (or instance a) will be called at
the end of the scope without explictly calling any function. For
example:
void Foo()
{
MY_FUNC(3);
.... more code....
} <-- destructor of MyObj would be called here
Now back to C#, the preprocessor is very limited so I cannot define
that macro.
If I encapsulate these two lines of code in a method I obviously loose
this advantage, and so I'm left copying and pasting that block of code
wherever it's needed.
I know this may sound stupid, it's just being used to C++, these
problems seem rather odd.
If I'm missing a cleaner way to do this please let me know.
Thanks,
Danny
I've recently encountered some design problems due to the language
limitations of C#.
Here are the scenarios:
1. Suppose I have a numerous number of functions that I would like to
add an optional parameter to. Since C# does not support optional
parameters, I would have to duplicate all these functions and override
each of them with another parameter. Is this really necessary?? Is it
just me or is the result kind of ugly?
2. In C++ I could have defined a macro to instantiate an object and
then make a method call. For example:
#define MY_FUNC(x) MyObj a; a.func(x);
This would have been useful since I could use this macro in any scope
knowing that the destructor of MyObj (or instance a) will be called at
the end of the scope without explictly calling any function. For
example:
void Foo()
{
MY_FUNC(3);
.... more code....
} <-- destructor of MyObj would be called here
Now back to C#, the preprocessor is very limited so I cannot define
that macro.
If I encapsulate these two lines of code in a method I obviously loose
this advantage, and so I'm left copying and pasting that block of code
wherever it's needed.
I know this may sound stupid, it's just being used to C++, these
problems seem rather odd.
If I'm missing a cleaner way to do this please let me know.
Thanks,
Danny