W
wizofaus
Finally decided I could put it off no longer and tried writing my first
C#/.NET app the other day.
Actually I had already written the app in MFC, so I figured it should
be straightforward enough to convert.
Some interesting results...
a) It took me a long time to get the framework up and going under C#.
This wasn't *just* lack of familiarity with the language/platform, but
the lack of integrated support for the Doc/View architecture that MFC
is built for. It mightn't be the perfect architecture, but it happens
to support a hellavu lot of different types of applications mighty
well, including what I was writing.
I had to dig around to find and download toolkits that others had
written for this, then figure out how to manually plug them in (as
opposed to the MFC app wizard which takes all of 3 seconds to use!).
b) I spent a lot of time having to deal with C#'s "strictness". C++
happily lets you convert between ints and doubles, or use functions
like strtod that will work fine on strings containing "improperly"
terminated numbers, whereas C# won't have a bar of it. Everything has
to be converted explicitly (not necessarily a bad thing, but makes the
code harder to read), and I had to write my own version of strtod to be
able to parse the files my app needed to read. I couldn't see any
options to Convert.ToDouble/Double.Parse that would allow me to handle
strings containing numbers directly followed by non-numeric data. For a
start, I really had to make sure it wouldn't throw exceptions, because
at least in the Debug version, this were horribly slow.
c) All in all, it probably took me three or four times as long to write
the C# version as it did the C++ version. One on hand, not so
surprising, given I'd never used C# before (and only had minimal
familiarity with Java, but I did cut my teeth on VB many years ago).
On the other, most of the time for the C++ version was working out the
algorithms/program logic I needed, whereas for the C# port, this was
already done - and it was great to be able to just copy & paste large
slabs of this straight into C#. I also found myself puzzling over some
very bizarre compiler errors - referring to lines of code that had
nothing significant in them, or errors that didn't logically pertain to
my code at all. But as long as you ignored these and fixed the
problems that did make sense (at which point the other errors
mysteriously vanished), the conversion from C++ to C# was reasonably
straightforward.
d) The really surprising part - the C# *debug* version ran miles faster
than the C++ optimized version! I'm actually 99% sure this is because
the C++ version ran off the standard Windows timer (WM_TIMER), which
severely limited the speed. For the C# version, I just used whatever
Timer component was supplied by .NET with a 1 millisecond interval, and
obviously this was firing far more rapidly than under the C++ version.
Still, I was quite impressed here - although the app was never really
CPU bound in the application logic.
The experience didn't particular leave me feeling there was much
advantage in using C# for the sort of work I do at this point, but it's
obviously a technology that can't be ignored completely. I felt more
comfortable with C# than I did with Java, but given it's closer
relationship to C++ this isn't so surprising.
C#/.NET app the other day.
Actually I had already written the app in MFC, so I figured it should
be straightforward enough to convert.
Some interesting results...
a) It took me a long time to get the framework up and going under C#.
This wasn't *just* lack of familiarity with the language/platform, but
the lack of integrated support for the Doc/View architecture that MFC
is built for. It mightn't be the perfect architecture, but it happens
to support a hellavu lot of different types of applications mighty
well, including what I was writing.
I had to dig around to find and download toolkits that others had
written for this, then figure out how to manually plug them in (as
opposed to the MFC app wizard which takes all of 3 seconds to use!).
b) I spent a lot of time having to deal with C#'s "strictness". C++
happily lets you convert between ints and doubles, or use functions
like strtod that will work fine on strings containing "improperly"
terminated numbers, whereas C# won't have a bar of it. Everything has
to be converted explicitly (not necessarily a bad thing, but makes the
code harder to read), and I had to write my own version of strtod to be
able to parse the files my app needed to read. I couldn't see any
options to Convert.ToDouble/Double.Parse that would allow me to handle
strings containing numbers directly followed by non-numeric data. For a
start, I really had to make sure it wouldn't throw exceptions, because
at least in the Debug version, this were horribly slow.
c) All in all, it probably took me three or four times as long to write
the C# version as it did the C++ version. One on hand, not so
surprising, given I'd never used C# before (and only had minimal
familiarity with Java, but I did cut my teeth on VB many years ago).
On the other, most of the time for the C++ version was working out the
algorithms/program logic I needed, whereas for the C# port, this was
already done - and it was great to be able to just copy & paste large
slabs of this straight into C#. I also found myself puzzling over some
very bizarre compiler errors - referring to lines of code that had
nothing significant in them, or errors that didn't logically pertain to
my code at all. But as long as you ignored these and fixed the
problems that did make sense (at which point the other errors
mysteriously vanished), the conversion from C++ to C# was reasonably
straightforward.
d) The really surprising part - the C# *debug* version ran miles faster
than the C++ optimized version! I'm actually 99% sure this is because
the C++ version ran off the standard Windows timer (WM_TIMER), which
severely limited the speed. For the C# version, I just used whatever
Timer component was supplied by .NET with a 1 millisecond interval, and
obviously this was firing far more rapidly than under the C++ version.
Still, I was quite impressed here - although the app was never really
CPU bound in the application logic.
The experience didn't particular leave me feeling there was much
advantage in using C# for the sort of work I do at this point, but it's
obviously a technology that can't be ignored completely. I felt more
comfortable with C# than I did with Java, but given it's closer
relationship to C++ this isn't so surprising.