Previous Blog Next Blog
Prev/Next Blog
by date

Learning C# the insane way

Learning C# the insane way
Name:Tom Bampton
Date Posted:Aug 31, 2006
Rating:3.0 out of 5
Public:YES
Comments:YES
RSS Feed:GarageGames Blog feedor Subscribe with .
Profile Page:View profile page for Tom Bampton

Blog post
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.

Recent Blog Posts
List:08/20/07 - GID23 and NPC Editor
07/25/07 - Fun with Lua
06/11/07 - How NOT to make a game
11/18/06 - Thinking Outside the Box
11/03/06 - Alive and Ticking: Now with exploding ants
10/28/06 - Fun with zips
10/02/06 - Alive and Ticking gets to Beta .... err, almost. (Warning: Screenshot Heavy)
09/08/06 - Internal Name Operator

Submit ResourceSubmit your own resources!

Anton Bursch   (Aug 31, 2006 at 12:08 GMT)   Resource Rating: 5
Why is it that no matter what you do you insist on being awesome? Damn you TomB! Can you let me be good at anything you can't master in 26 minutes?!

I look forward to BrainFuck 2.0 and the BrainFuck.net video tutorials.

BrainFuck. Why can't I be cool and think up badass names like that. :P

Welcome to the wonderful world of c#. I think you'll like it. It's like C++ only it's... C--. huh. not sure about that being so great now that I think of it. :P

But really, glad to finally be able to understand the code you used in your plan. I can learn something from you guys with all the experience now.

Thijs Sloesen   (Aug 31, 2006 at 12:42 GMT)
Nice man, I just wrote an interpreter for BrainFuck myself!

Granted, it wasn't to learn C#, but still, it's a nice to play around with :-)

Cheers!

Matt Huston   (Aug 31, 2006 at 13:13 GMT)
Learning C# is on my to-do list somewhere down the line, though I think Python will come before that. Currently I am freshening up on my C++, I noticed a trend in my Torque coding, I was doing everything I could think of to avoid touching the C++, which is a good and a bad thin in my opinion.

Ron Yacketta   (Aug 31, 2006 at 13:32 GMT)
C# is a great language, use it daily at work. Have yet to use it for fun (GameDev etc), but I am sure that will come soon enough.

-Ron

Anthony Rosenbaum   (Aug 31, 2006 at 13:51 GMT)
I like C# I still don't quite understand all the intricacies but I see potential and I like how VS Express will package an exe with an installer. BTW that iis one scarey Beard
Edited on Aug 31, 2006 13:52 GMT

David Montgomery-Blake   (Aug 31, 2006 at 14:08 GMT)
Heh! I love it. I used BrainFuck to learn Perl and Python because I was sick of HelloWorld as well. That seriously rawks!

Alexander "taualex" Gaevoy   (Aug 31, 2006 at 14:21 GMT)   Resource Rating: 5
[Throwing a bomb in a crowd with a *grin*] C# sucks! I love Java foreva!

Treb Connell (formerlyMasterTreb   (Aug 31, 2006 at 15:14 GMT)
I started to learn c# and it seemed pretty similar to c++, but the no global variables thing turned me off of it. Maybe I would get used to it but for now its c++ for me.

Alexander "taualex" Gaevoy   (Aug 31, 2006 at 15:50 GMT)   Resource Rating: 5
@Master

To use global variables, define a global static class, then static variables in it - you will have a full blown global staff!

Like:

namespace Project.Tools
{
public static Globals
{
public static SceneGraph ServerSceneGraph = null;
public static SceneGraph ClientSceneGraph = null;
}
}


Then access it everywhere:

Using  Project.Tools;

...
Globals.ServerSceneGraph = Factory.CreateSceneGraph();
Globals.ServerSceneGraph.Reset();
con = Globals.ServerSceneGraph.GetConnection();
...


Phil Carlisle   (Aug 31, 2006 at 15:59 GMT)
Yeees... ok.. I'd rather have written a calculator or something :) thats what C# really excels at.. toolsies.

I actually ended up making a quick editor for Tiki Tennis Ai in C# as "my first app". It ended up feeling a lot like Borland builder. Not sure wether thats a good thing or not.

I'm guessing my coding usage was probably pretty bad (sticking lots of functions in a form feels wrong to me).

But hey, its a tool like any other. Good and bad in everything.

Treb Connell (formerlyMasterTreb   (Aug 31, 2006 at 16:25 GMT)
@Alexander

ah yes that would work thanks.

I tried managed directX which was interesting but not much different than C++ for me, so I didn't get much farther than that.

David \"Fulcrum\" Wyand   (Aug 31, 2006 at 17:18 GMT)
It seems that we're all learning C#. Coincidence? :o)

Vashner   (Aug 31, 2006 at 17:38 GMT)
ROFL...

Tom Bampton   (Aug 31, 2006 at 17:53 GMT)
The point to writing BF was it requires a lot of stuff that highlights the core stuff that everyone needs to know. A calculator just jumps straight into Windows Forms and completely skips over said basics, which IMHO completely defeats the purpose of the exercise.

However, the thing I have been working on since posting this .plan has a lot more bang for buck and covers the GUI based things ignored by BF. I'm not going to say what it is yet ... but it's a lot bigger, involves a custom class library, a custom control library and a Windows Forms based app. It's probably quite easy to guess what it is, but I'm not saying til it's "done" ;-)

T.

Chris Calef   (Aug 31, 2006 at 18:03 GMT)
Tom, I'm really impressed, but I have to ask, do you have a social life at all?

J Lesko   (Aug 31, 2006 at 18:37 GMT)
*yawn* I would've been more impressed if it was a C# interpreter written in Brainfuck, but I guess you have to start somewhere. =)

Casey Weidner   (Aug 31, 2006 at 19:35 GMT)
yes .. i also decided it was time learn C# with the advent of XNA studio express... except my first project is a little more insane... i've decided to port both an NES And a SNES emulator over to XNA.. not so bad untill you think about the fact that about 90% of the emulators are writen in ASM.. time to pull out that ASM reference manual... LOL

Michael Cozzolino   (Aug 31, 2006 at 20:16 GMT)
Quote:

Tom, I'm really impressed, but I have to ask, do you have a social life at all?



Of course he does it only took him 26 min. :)

David Montgomery-Blake   (Aug 31, 2006 at 20:52 GMT)
As I noted before, this is an excellent way to start with a language and learn the in's and out's of it. Sure, you won't learn the intimate details of the langauge or some of its ease-of-use features, but you will make an application that actually does something more than simply printing to the screen or hide/show forms. It works with an manipulates data and forces the programmer to think in basic algorithms.

When learning (or re-acquainting) syntax, I often create Quines. They're a fun way to get familiar with syntax quickly since the program's function is to print out the program's source code in a delicate and often clever fashion. Sometimes I will do both, beginning with a Quine and then moving it to something like Brainfuck.

Though I am not even a millionth as fast and effective as Tom!

Craig Fortune   (Aug 31, 2006 at 20:54 GMT)
He does have a social life, I saw him last weekend and we worked on... oh no hang on, bollox. No. :D

J. Erick Christgau   (Sep 01, 2006 at 00:37 GMT)
Heh, I learned c# by writing a MUD :)

Nicolas Quijano   (Sep 01, 2006 at 00:40 GMT)
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 ?

Melv May   (Sep 01, 2006 at 08:23 GMT)
You continue to inspire Tom.

- Melv.

Tom Bampton   (Sep 01, 2006 at 09:16 GMT)
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.

Paul Scott   (Sep 01, 2006 at 22:44 GMT)
I'd love to do game scripting in bf. Or Befunge.

Tom Bampton   (Sep 01, 2006 at 22:45 GMT)
@Paul,

You may yet get to, replacing TorqueScript with BF has long been on my useless to-do list ;-)

T.

Anton Bursch   (Sep 02, 2006 at 11:33 GMT)   Resource Rating: 5
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. :)

Tom Bampton   (Sep 02, 2006 at 11:56 GMT)
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.

Anton Bursch   (Sep 03, 2006 at 08:21 GMT)   Resource Rating: 5
...
Edited on Sep 04, 2006 06:57 GMT

You must be a member and be logged in to either append comments or rate this resource.