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
#2
Granted, it wasn't to learn C#, but still, it's a nice to play around with :-)
Cheers!
08/31/2006 (12:42 pm)
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!
#3
08/31/2006 (1:13 pm)
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.
#4
-Ron
08/31/2006 (1:32 pm)
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
#5
08/31/2006 (1:51 pm)
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
#6
08/31/2006 (2:08 pm)
Heh! I love it. I used BrainFuck to learn Perl and Python because I was sick of HelloWorld as well. That seriously rawks!
#7
08/31/2006 (2:21 pm)
[Throwing a bomb in a crowd with a *grin*] C# sucks! I love Java foreva!
#8
08/31/2006 (3:14 pm)
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.
#9
To use global variables, define a global static class, then static variables in it - you will have a full blown global staff!
Like:
Then access it everywhere:
08/31/2006 (3:50 pm)
@MasterTo 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(); ...
#10
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.
08/31/2006 (3:59 pm)
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.
#11
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.
08/31/2006 (4:25 pm)
@Alexanderah 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.
#12
08/31/2006 (5:18 pm)
It seems that we're all learning C#. Coincidence? :o)
#13
08/31/2006 (5:38 pm)
ROFL...
#14
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.
08/31/2006 (5:53 pm)
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.
#15
08/31/2006 (6:03 pm)
Tom, I'm really impressed, but I have to ask, do you have a social life at all?
#16
08/31/2006 (6:37 pm)
*yawn* I would've been more impressed if it was a C# interpreter written in Brainfuck, but I guess you have to start somewhere. =)
#17
08/31/2006 (7:35 pm)
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
#18
Of course he does it only took him 26 min. :)
08/31/2006 (8:16 pm)
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. :)
#19
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!
08/31/2006 (8:52 pm)
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!
#20
08/31/2006 (8:54 pm)
He does have a social life, I saw him last weekend and we worked on... oh no hang on, bollox. No. :D
Torque Owner Anton Bursch
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.