|
 |
I wanted to look into this C# and XNA malarkey so downloaded the free
express edition of C# and XNA from MS. Yes I know this should go in a blog
but I don't have one and don't plan to write much like this.
Firstly, the code auto-complete and general "text editor" part of the IDE is
amazing, a big step forward from the C++ Express edition I had been using.
The auto-complete list remembers multiple things at multiple levels that you
have typed before and jumps to them first as you type, this saves *a lot* of
time when you have lots of "using" statements (ie the auto-complete list is
quite long). Also it seems to dynamically compile (or at least parse
somehow) your code in realtime, if you mis-spell a variable or use one
without initialising it, it gets underlined in red the same spelling
mistakes do in Word. You can then either hover over the error or look in
the error list window to see what's up *very useful*. Warning are
underlined in green, things like unused variables.
There is some basic code refactoring built in which is pretty handy. You
can select some lines of code and tell it to pull it out in its own
function, parameters and return values will be handled automatically. You
can do the same by just typing in a call to a non-existant function (which
will get underlined in red), then clicking to tell it to make the definition
for that function. Also if you rename one occurrence of a variable
manually, it will get the little "option box" next to it that lets you
rename all other occurrences of it automatically - nice.
About the actual language of C#, I've never used any really expert features
of C++ so can only give a basic comparison, but essentially C# is *way*
easier to program and much less prone to mistakes. Maybe part of the reason
why is that you can instantly see if you've made a mistake. For example I
didn't know the syntax for declaring an array, yet after a few seconds of
trial and error I got something that worked based on what I knew about
C++.net (would have taken longer to open up help and search for array).
Also no need for any pointers or *'s and &'s dotted about, all handled for
you. If you want to pass a variable by reference to a function then just
write "ref" before it, very simple.
Also if you are using multiple source files this is very much simplified in
C#. In C++ you need to mess about with #includes and hacks to stop files
being included more than once when referenced from multiple source files -
not with C#, no need for any include statement, if it's in the project you
have access to it. There is also no concept of "order" when files are
included, every file has visibility of every other source file, so you don't
get circular reference problems. The same applies within files, so you can
write:
struct Line { Point n1 , Point n2 }
struct Point { int x , int y }
And this is fine.
One little niggle I had to start with was that when you define a class, you
need to write the code for all the methods of that class in the definition
too (in C++ I would usually put the actual method code in a separate file).
Actually after a few days of coding it doesn't really bother me now, I got
into the habit of "collapsing" the code in the IDE using the +/- icon so
that there is just a list of methods. If you want to view or edit the code
for a certain method you can just expand it temporarily. I'm even
contemplating that this is actually a better way to manage classes than
always having two separate files for each class that must be kept in sync
(eg to add an extra parameter to a function you always have to change it in
both files).
I've just started to dig the surface of XNA, but it seems to me to be
basically DirectX.net, which is not a bad thing. I got a simple 2D and then
3D program up and running in very little time, I'd say maybe 4 or 5 times
quicker than I ever managed with C++ and DirectX. XNA programs can also be
built to run on the xbox - it almost makes me want to get one just so I can
play some game I wrote on a console! There's a whole host of cool build
tools, like automatically converting images, fonts and mesh data into
optimal formats at compile time - this is genius.
Post a reply to this message
|
 |