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: | or 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.
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 your own resources!| Anton Bursch (Aug 31, 2006 at 12:08 GMT) Resource Rating: 5 |
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) |
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) |
| Ron Yacketta (Aug 31, 2006 at 13:32 GMT) |
-Ron
| Anthony Rosenbaum (Aug 31, 2006 at 13:51 GMT) |
Edited on Aug 31, 2006 13:52 GMT
| David Montgomery-Blake (Aug 31, 2006 at 14:08 GMT) |
| Alexander "taualex" Gaevoy (Aug 31, 2006 at 14:21 GMT) Resource Rating: 5 |
| Treb Connell (formerlyMasterTreb (Aug 31, 2006 at 15:14 GMT) |
| Alexander "taualex" Gaevoy (Aug 31, 2006 at 15:50 GMT) Resource Rating: 5 |
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) |
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) |
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) |
| Vashner (Aug 31, 2006 at 17:38 GMT) |
| Tom Bampton (Aug 31, 2006 at 17:53 GMT) |
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) |
| J Lesko (Aug 31, 2006 at 18:37 GMT) |
| Casey Weidner (Aug 31, 2006 at 19:35 GMT) |
| 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) |
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) |
| J. Erick Christgau (Sep 01, 2006 at 00:37 GMT) |
| Nicolas Quijano (Sep 01, 2006 at 00:40 GMT) |
Is the world ending ?
| Melv May (Sep 01, 2006 at 08:23 GMT) |
- Melv.
| Tom Bampton (Sep 01, 2006 at 09:16 GMT) |
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) |
| Tom Bampton (Sep 01, 2006 at 22:45 GMT) |
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 |
| Tom Bampton (Sep 02, 2006 at 11:56 GMT) |
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.



3.0 out of 5


