Learning C# the insane way
by Tom Bampton · 08/31/2006 (11:50 am) · 29 comments
Learning C# is one thing that I've been putting of for a long time. The only reason for that was I haven't needed it and I knew I could pick it up really quickly.
After finally getting some code working that has been seriously annoying me for the past week, I figured I'd push my luck and see just how quickly I could learn enough C# to be productive.
It is obligatory when learning a new language to write a Hello World program. You are not a real programmer if your first program in every language you know was Hello World. The only problem with Hello World, is when you have learnt as many languages I have Hello World gets really boring.
So, how do we spice this up ? It's obvious! Write a BrainFuck interpreter in C# and implement Hello World in BrainFuck!

I did actually do Hello World before BrainFuck just to make sure I had the project setup correctly and because, well, it's the done thing. Here's a time breakdown:
* Learning enough about C# to get started: 6 minutes
* Project Setup/Writing Hello World: 5 minutes
* Skimming docs to learn what I needed to know for BrainFuck: 15 minutes
* Total Time: 26 minutes
It took me a little over an hour to implement the interpreter, but that would have been the same in terms of time regardless of what language I'd used.
If you want to play around with it, you can download the interpreter here. You'll need .NET 2.0 installed to run it. I haven't included the source because since it's my first C# app and I'm a C++ programmer, I've probably done some things that would cause C# programmers to swear ;-)
It's a command line app, for details on how to use it, see the screenshot. I ganked the example BrainFuck code from the Wikipedia article linked earlier.
After finally getting some code working that has been seriously annoying me for the past week, I figured I'd push my luck and see just how quickly I could learn enough C# to be productive.
It is obligatory when learning a new language to write a Hello World program. You are not a real programmer if your first program in every language you know was Hello World. The only problem with Hello World, is when you have learnt as many languages I have Hello World gets really boring.
So, how do we spice this up ? It's obvious! Write a BrainFuck interpreter in C# and implement Hello World in BrainFuck!

I did actually do Hello World before BrainFuck just to make sure I had the project setup correctly and because, well, it's the done thing. Here's a time breakdown:
* Learning enough about C# to get started: 6 minutes
* Project Setup/Writing Hello World: 5 minutes
* Skimming docs to learn what I needed to know for BrainFuck: 15 minutes
* Total Time: 26 minutes
It took me a little over an hour to implement the interpreter, but that would have been the same in terms of time regardless of what language I'd used.
If you want to play around with it, you can download the interpreter here. You'll need .NET 2.0 installed to run it. I haven't included the source because since it's my first C# app and I'm a C++ programmer, I've probably done some things that would cause C# programmers to swear ;-)
It's a command line app, for details on how to use it, see the screenshot. I ganked the example BrainFuck code from the Wikipedia article linked earlier.
About the author
#22
Is the world ending ?
09/01/2006 (12:40 am)
Tom Bampton doing something because "it's the thing to do" ? (and I don't mean learning C#, but doing Hello World ;))Is the world ending ?
#24
I had a bunch of stuff typed up about this, but the site ate it. Meh. So, here's the screenie:

It's not finished, and its being engineered as something I can actually use to mess around with GoL stuff. It is however much further along then the in-Torque GoL from my previous blog. It's also significantly faster. I was more concerned with making something that I'd actually use rather then doing it quickly, so I have no idea how long it took.
T.
09/01/2006 (9:16 am)
23 comments?!?! Holy shit! I thought this would just have a couple of comments and then fade into obscurity as just another mental thing I've done. I do have a social life, but I have to wonder about you lot ;-)I had a bunch of stuff typed up about this, but the site ate it. Meh. So, here's the screenie:

It's not finished, and its being engineered as something I can actually use to mess around with GoL stuff. It is however much further along then the in-Torque GoL from my previous blog. It's also significantly faster. I was more concerned with making something that I'd actually use rather then doing it quickly, so I have no idea how long it took.
T.
#25
09/01/2006 (10:44 pm)
I'd love to do game scripting in bf. Or Befunge.
#26
You may yet get to, replacing TorqueScript with BF has long been on my useless to-do list ;-)
T.
09/01/2006 (10:45 pm)
@Paul,You may yet get to, replacing TorqueScript with BF has long been on my useless to-do list ;-)
T.
#27
09/02/2006 (11:33 am)
Admit it. C# is pretty. It feels nice and neat to scri... code in C#. All the little helpful things it does for you so you concentrate on the solution and not the code. If C++ is the Lamborghini of game programming languages. Then C# is... the Astin Martin... with Stinger Missles of course. :)
#28
I can see how not having to worry about memory management would help beginner/intermediate programmers work quicker. For an advanced programmer, the difference that makes is so small that it is only really noticable in a substantial codebase and even then it only helps avoid the silly mistakes you make whilst tired. Of course, those silly mistakes can still cost a lot of time ;-)
There are also some things about C# that actually get in the way. As a slightly pedantic example, case blocks not being able to fall through to the next one has already forced me to duplicate some code that wasnt neccessary to duplicate. In that specific (and still pedantic and silly) case it actually took twice as long to write that code in C# then it would have in C++. Sure, being able to fall through case blocks is a good way for some people to hang themselves, but when you know what you're doing it does have a number of uses.
So, in summary, whilst C# is indeed nice it's still just another language. The .NET libraries make it really quick to do things like tools or business apps. However, I've been coding for a long time and thus have built up a large library of C++ code so for most of the things I do it would make no difference in terms of time as to whether I did it in C# or C++.
I will probably do a "proper" C# vs C++ write up at some point. It depends on how much time I have, which is not very much :)
T.
09/02/2006 (11:56 am)
C# is a nice language. However, it's not C# itself that makes things quicker. It's the libraries and handy stuff the IDE does that makes the difference.I can see how not having to worry about memory management would help beginner/intermediate programmers work quicker. For an advanced programmer, the difference that makes is so small that it is only really noticable in a substantial codebase and even then it only helps avoid the silly mistakes you make whilst tired. Of course, those silly mistakes can still cost a lot of time ;-)
There are also some things about C# that actually get in the way. As a slightly pedantic example, case blocks not being able to fall through to the next one has already forced me to duplicate some code that wasnt neccessary to duplicate. In that specific (and still pedantic and silly) case it actually took twice as long to write that code in C# then it would have in C++. Sure, being able to fall through case blocks is a good way for some people to hang themselves, but when you know what you're doing it does have a number of uses.
So, in summary, whilst C# is indeed nice it's still just another language. The .NET libraries make it really quick to do things like tools or business apps. However, I've been coding for a long time and thus have built up a large library of C++ code so for most of the things I do it would make no difference in terms of time as to whether I did it in C# or C++.
I will probably do a "proper" C# vs C++ write up at some point. It depends on how much time I have, which is not very much :)
T.
#29
09/03/2006 (8:21 am)
...
Torque 3D Owner J. Erick Christgau