• Hey Guest. Check out your NeoGAF Wrapped 2025 results here!

Your Programming FUCK YEAH moments.

Status
Not open for further replies.
Okay, several C# questions:

First of all, I was trying to use methods from a class from within my main method, like:

Worker.AddWorker(Console.ReadLine());

To use this, I had to spam "static" all over my class Worker because it told me the main class cant use any class method that isnt static (even the variables it uses need to be static?).

Is that a problem? Because as it looks right now EVERY method I am going to touch would need to be static, no idea what it actually does but it sounds wrong. This is one method I'd like to use:

private static int WorkerCounter;
private static Worker[] WorkerList = new Worker[WorkerCounter];

public static void AddWorker(string input)
{

input = input.Replace(" ", "");

WorkerCounter++;

Array.Resize<Worker>(ref WorkerList, WorkerCounter);

string[] inputstring = input.Split(',');

WorkerList[WorkerCounter] = new Worker(inputstring[0], inputstring[1], Convert.ToInt32(inputstring[2]));
}

Next question, right now, this code doesnt work because of an IndexOutOfRangeException in the last line. Why is that? The WorkerList is made bigger everytime I use the AddWorker method and the inputstring gets exactly 3 values ("a,b,3"), so they are big enough, right?
And right after I gave the input the program gives me the IOORE.
 
Static means that it exists from the moment the program starts to the moment it ends, Toma. If you have a static class you will never actually create an instance of that class, it will simply always exist and can be accessed as such. You will want to try to remove all of those static keywords as overuse really conflicts with the entire idea of OOP.

If you want to use a method that's contained in a class, you need to create an object of that class. Think of the class as a blueprint, you can't actually use the blueprint can you? Nope, you have to use your blueprint to first create whatever it's modeled to be. I will make my own class called 'Factory' which is a class that handles the flow and deals with 'Workers'.

IE.

Factory factory = new Factory(); //I'm creating (instantiating) a new factory from my class.
Worker worker = new Worker(); //I'm creating a worker the same way as the factory.
factory.AddWorker(worker); //Using the factory I created to hold the worker.
factory.ProcessWorkers(); //Doing stuff with the workers

Index out of range is just telling you that you're trying to access an element in the array/list that isn't there, I don't have time to look at it now, sorry I have finals!
 
Toma said:
Okay, several C# questions:

First of all, I was trying to use methods from a class from within my main method, like:



To use this, I had to spam "static" all over my class Worker because it told me the main class cant use any class method that isnt static (even the variables it uses need to be static?).

Is that a problem? Because as it looks right now EVERY method I am going to touch would need to be static, no idea what it actually does but it sounds wrong. This is one method I'd like to use:
I wouldn't know what exactly is going on in C#, but static methods are class methods. If you don't declare them static, they are usable only by the objects of that class. So it seems that you are mixing some OOP concepts. The catch of OOP comes from creating objects from some class, whereas the object is in itself a data structure (with the structure you defined when you defined the class) with behavior implemented (in form of methods, which should not be static if you are planning to use within objects).

Beaten by a better explanation.
 
My biggest fuck yeah moment ever was probably when I was writing a sound mixer for GBA and optimised it in assembler to get it running at decent speed. It was my first, and pretty much only, time coding anything in assembler and it was so awesome. I had been coding a bunch of homebrew games on GBA before but had always been at the mercy of it's crappy sound hardware.

The other one was when I got my 3D engine running on Wii homebrew a few years ago.
 
Toma said:
Any hints on how to "get" OOP? My major problem right now.

This answer may come a bit late but the most efficient way to learn an object oriented language is by learning Smalltalk.

All other languages don't require you to actual get the OO concept. In C++, C# or even Java you can get away with procedural programming but not in Smalltalk.
 
My latest "F Yeah" is solving the Project Euler #67 as shown earlier in the thread.

Incidentally, My latest "F Me" was failing the captcha when submitting my answer.

Toma said:
Okay, several C# questions:
To use this, I had to spam "static" all over my class Worker because it told me the main class cant use any class method that isnt static (even the variables it uses need to be static?).

Static methods are class methods that don't require an instance of the object to call. In the class worker:

Code:
public void DoStuff() { ... }
public static void DoStuff() { ... }

The first has to be called on an instance of the Worker class, e.g: Worker bob = new Worker(); bob.DoStuff();.

The second is more of just a global method call: Worker.DoStuff();. It won't have any access to non-static members of the Worker class (because it's not actually referring to the object).

You should be doing it the first way more often than not. If you're just calling static methods all over the place then that's more of a procedural programming mindset than an OOP one. If misunderstood and used improperly, static methods can be pretty dangerous.

Toma said:
Next question, right now, this code doesnt work because of an IndexOutOfRangeException in the last line. Why is that? The WorkerList is made bigger everytime I use the AddWorker method and the inputstring gets exactly 3 values ("a,b,3"), so they are big enough, right?
And right after I gave the input the program gives me the IOORE.

I've never used Array.Resize before so I could be wrong about this, but it sounds like you're always trying to access the index WorkerList.Length of WorkerList, which will always be out-of-bounds since in C# array indexes start at 0.

Code:
string[] bob = new string[2];
bob[0] = "a"; // ok
bob[1] = "b"; // ok
bob[2] = "c"; // error, index out of bounds

The quick fix is to change the last line to be WorkerList[WorkerCount-1] = ...

A better solution here would be to use a generic List instead of manually working with an Array, because it was built to do the exact sort of thing you're doing here:

Code:
private static List<Worker> WorkerList = new List<Worker>();
public static void AddWorker(string input)
{
  input = input.Replace(" ", "");
  string[] inputstring = input.Split(',');
  WorkerList.Add(new Worker(inputstring[0], inputstring[1], Convert.ToInt32(inputstring[2])));
}
 
Mister Zimbu said:
Lots of help

Oh god, thank you. (Thanks to all of you)

I'll try using the list for that. I really, really need to practice this. I will probably delete my program and just write it again to get used to writing stuff in classes.

Or does anyone have a small "task" to practice that? I couldnt find such task when searching for it via google.
 
* Achieving a cycle-perfect interrupt on the Commodore 64
* Achieving cycle-perfect code on the Gameboy, and in turn using that for changing the vertical scrolling register at each 8-pixel column of the screen at every line (which ended up in this piece)
* Getting an old school adventure game engine in shockwave/lingo up and running; completely free from states and using the internal string type in a weird way for setting up data and running dynamically loaded game logic at extremely high speed.
* Getting the Super Nintendo to do anything, including loading up the sound chip with an emulator save state to play any good old music.
* Coding up a 2D sprite blitting engine for the PS2 and getting it to run on real hardware. There's really no practical limit on the amounts of sprites that machine can draw...

Programming can be extremely satisfying, and although it's not my main profession I get back to it every couple of years... But I just started to do some summer vacation iPhone coding and I love it.
 
Toma said:
Okay, several C# questions:

Next question, right now, this code doesnt work because of an IndexOutOfRangeException in the last line. Why is that? The WorkerList is made bigger everytime I use the AddWorker method and the inputstring gets exactly 3 values ("a,b,3"), so they are big enough, right?
And right after I gave the input the program gives me the IOORE.

private static int WorkerCounter;
private static Worker[] WorkerList = new Worker[WorkerCounter];

public static void AddWorker(string input)
{

input = input.Replace(" ", "");

WorkerCounter++;

Array.Resize<Worker>(ref WorkerList, WorkerCounter);

string[] inputstring = input.Split(',');

WorkerList[WorkerCounter] = new Worker(inputstring[0], inputstring[1], Convert.ToInt32(inputstring[2]));
}

This is actually not a very elegant solution. Everyone accessing your method has to know that the parameter has to be special formated in order to work propery. If for example someones types

AddWorker("sampleString") or AddWorker("a,b") or even AddWorker("a,b,c")

your method will fail.

You are expecting three parameters, two strings and one int, so why not exactly ask for them?

Code:
public static void AddWorker(string s1, string s2, int i)
{
WorkerCounter++;
WorkerList[WorkerCounter] = new Worker(s1, s2, i);
}

This will do exactly the same but is much more failsafe.
 
Totalriot said:

Seems like I got even more problems than what I am already aware of. But yeah, you are right. I'll rewrite that and try to get used to doing that.
 
The biggest would probably be the "one page website" I developed with PHP. The actual site was a single PHP page but had a bunch of different functions for various types of pages it could generate, the most complex of which was probably the interactive photogallery. Then all of that was controllable through a CMS I built from the ground up complete with full user and data management.

I probably should have kept going with web development, but that burned me out. I still needed to get deeper into security stuff and regular expressions, and I never really learned classes.
 
Toma said:
Seems like I got even more problems than what I am already aware of. But yeah, you are right. I'll rewrite that and try to get used to doing that.

No worries, you are definitely on the right track. The most important thing when learning a programming language on your own is to actually try it and then let other people review your code. You seem to do that :)

Earlier on, you have asked for programming tasks. A good source are university programming exercises. Many university professors have these for their courses online, although you will find more examples for Java than for C#, as Java is a more popular learning language.

Try googeling "exercises c#" or "exercises c# solutions" and see what you'll find. For example this one seems OK but does not offer any solutions: http://www.cs.aau.dk/~bt/JAVA-CSHARP/CSharpExercises.pdf
 
Totalriot said:
No worries, you are definitely on the right track. The most important thing when learning a programming language on your own is to actually try it and then let other people review your code. You seem to do that :)

Earlier on, you have asked for programming tasks. A good source are university programming exercises. Many university professors have these for their courses online, although you will find more examples for Java than for C#, as Java is a more popular learning language.

Try googeling "exercises c#" or "exercises c# solutions" and see what you'll find. For example this one seems OK but does not offer any solutions: http://www.cs.aau.dk/~bt/JAVA-CSHARP/CSharpExercises.pdf

Thanks! That looks perfect. I already asked in our university but they dont have any C# courses, and somehow I wasnt able to find a somewhat structured exercise.
 
I've just finished a computer science degree in which I realised that a career in programming probably isn't for me. I'm not a good programmer by any stretch of the imagination, and I don't think I adjust well to programming things to deadline, because I like to tweak things, and also as a result of not being a good programmer, make more mistakes than most.

However I do like to do the odd bit of programming in my spare time, where I can just work on it here and there, when I feel like, without a deadline hanging over me. Means that when I inevitably hit a part where I get stuck and frustrated, I can leave it and come back when I feel like as opposed to feeling that I have to keep working at it to fix it in time.

Currently programming a simple football/soccer management game to get myself back up to speed, and it also provides scope for me to expand its features if I finish it and want to continue improving it.

So to answer the actual question of the thread, I think my proudest moment was the realisation of how classes work. Having said that, I still make stupid mistakes, which is why I decided it was probably best if I didn't go into programming as a career
3AQmK.gif
 
It's been a while since I actually programmed anything, but I still remember some good moments.

First one is easy:
On my good old Commodore 64

10 PRINT"Hello World!"
20 GOTO 10

That's always a good one. I got up to making sprites move with a joystick on my C64, but I couldn't get it to work from scratch.

Second one, high school, basic programming in Visual Basic. That was where I learned Object Oriented Programing. But the crowing moment of that is one I remember quite clearly. Final project, me and a friend decided to make a Pac-Man clone. Seeing my programming plus a plaintext input file draw that maze the first time was so awesome. Why did we do it like that? So we could change the maze easily just by editing the text file, of course.

The latest one is much simpler though. I got fed up with some behavior of my Sims in The Sims 3. I downloaded the mod tools for the game and went at it. That's when I made my first standalone mod for any game. And it worked perfectly, too. Then that behavior was patched out by EA later, but I still have a few mods of my own installed. Sure it's just some XML changes, the conversion to the proper format is done by the tool, but I'm still happy. It's not someone else's mod doing that for me. It's mine. I've been meaning to try out going at the core of Sims 3 on my own, too. But that way lies Assembler Code. On the other hand, if I can get to that, the game is mine to do whatever I want to do with. As long as I remember to add the latest changes from patches and expansions to my core. Plus, learning some Assembler Code could be fun in some ways.
 
Making a roman blockshift algorithm for encryption took 2 days of 10 hours programming could have made it in 5 hours if i wasn't so stubborn to make it work with only arrays and math for traversing it.

And when we won the public price of best top down race game in period 1 with XNA felt really good.
 
Toma said:
Any hints on how to "get" OOP? My major problem right now.
I find it best to consider what in your program you will want to have multiple instances of that you want manipulate separately. Take your dungeon generator as an example: the dungeon itself might be something you want to be able to make multiple instances of (different levels) and give its own properties and methods (size, number of rooms, generating the rooms, treasure and enemies etc.).

Enemies is another good thing to make a class out of, as that allows you to instantiate a lot of enemies who will have their own properties (current position, speed, health etc.).

Treasure would be another one, that would also do well as a base class for more specific classes (inheritance). I.e a weapon is a treasure, so you could have a Weapon class that inherits from the Treasure class, and to take it even further you could have a Sword class that inherits from the Weapon class.

The use of this would be to have properties and methods common among all treasures defined in the Treasure class (all treasure will have a name, position etc.), likewise with the Weapon class (all weapons does damage) and the Sword class (all swords have a specific ability maybe).

Keep in mind that I've just been programming full-time, so to speak, for a little less than a year (school, internship), so take my advice with a grain of salt :)
 
deadbeef said:
Compiler writers do! :)

Well gibberish into even more gibberish, I guess.

Thought of my other one - writing my own scripting language and interpreter.

lol, compilers have two stages of gibberish writing. Creating the object files, then linking them all together.
 
In my first days of programming, writing a program to inverse the input in motherfucking PLT Scheme (Racket). It felt good.

For example, 14567 would become 76541, 165 would become 561, etc.

That day I understood I would be dividing stuff by 10 for the rest of my life.
 
This isn't really the thread for it, but if I wanted to get started in simple game design, where should I start? I'm already fairly proficient in C++ and by extension I can hold my own in Java, and I've heard Python is something to look into. Any other tips?
 
iphoneAppFya.png


I'm not that good a programmer (especially compared to you guys) so it was kind of a big deal for me when I figured it out.
 
Anyway, I'd say my first "fuck yeah" moment was creating a graphical RPG in QBasic. I created my own sprite editor and my own level editor. It had six overworlds, a town in each overworld and a dungeon in each overworld.

The towns had people you could talk to, buildings and you could buy weapons and items in them. There was a leveling up system, random enemy encounters, the works. Each dungeon had a boss battle.

It was completely tile-based graphics. I stopped it when QBasic ran out of memory.
 
The_Technomancer said:
This isn't really the thread for it, but if I wanted to get started in simple game design, where should I start? I'm already fairly proficient in C++ and by extension I can hold my own in Java, and I've heard Python is something to look into. Any other tips?

I'd say either take a class, or get a getting started game programming book. Since you already know C++, try to get one in that language.

Edit - Perhaps you can get a beginners DirectX book. Game programming is really rewarding, but there are a lot of little nuances you will never even think games had until you start programming them.

I'd say game programming is the funnest of all the programming fields. Which probably explains the pay....

Edit 2 - My problem is that I don't work at a game programming firm. So it's all home-bred stuff. And... well... I can't draw or do sound or music. So the stuff I can accomplish is very limited and I can't afford to hire anybody. I've contemplated starting a game company, where everybody does it on the side. Money would only be distributed after the game ships where each person gets their %. But its hard to convince people to work for free for months on end with a variable pay-out in the end.
 
SlipperySlope said:
I'd say either take a class, or get a getting started game programming book. Since you already know C++, try to get one in that language.

Edit - Perhaps you can get a beginners DirectX book. Game programming is really rewarding, but there are a lot of little nuances you will never even think games had until you start programming them.

I'd say game programming is the funnest of all the programming fields. Which probably explains the pay....
Well I've found I pick up languages fairly quickly, so I'm willing to invest 3 or 4 months into something I don't have experience in if its better for handling game programming. Yeah, I'll definitely check for some books at the library. I've had vague ideas about how to do a turn based strategy game using simple classes, but I have no idea if thats anywhere on the right track or not.
 
SlipperySlope said:
I'd say game programming is the funnest of all the programming fields. Which probably explains the pay....

Depends entirely. I don't fancy the idea of being a 24/7 engine programmer.
KuGsj.gif
 
The_Technomancer said:
Well I've found I pick up languages fairly quickly, so I'm willing to invest 3 or 4 months into something I don't have experience in if its better for handling game programming. Yeah, I'll definitely check for some books at the library. I've had vague ideas about how to do a turn based strategy game using simple classes, but I have no idea if thats anywhere on the right track or not.

You have two routes really for game programming. Flash for web-based junk. Or C++ like the big boys use :)

Some people like to use managed code, but there is a performance issue doing that.

For your question of "better for handling game programming", then definitely C++.
 
SlipperySlope said:
Some people like to use managed code, but there is a performance issue doing that.

Will this really matter in a beginner/indie project? Terraria, Magicka, CSTW seem to be doing just fine to me.
 
Kalnos said:
Will this really matter in a beginner/indie project? Terraria, Magicka, CSTW seem to be doing just fine to me.

Could you explain why "managed" code is even regarded as a problem? Beginner here. I read up a bit about it, but didnt find much.
 
Nearly all of my programming "fuck yeah!" moments involved applying math to get where I wanted to go, and make up for my lack of ability in other respects. There's so much one can accomplish with a solid understanding of math, and choosing to minor in the subject has given me a LOT to play with that most programmers prefer (sometimes reasonably) to shy away from.

So, basically, anything that involves analysis, 3d, game development, and things of that ilk have tons of little fuck yeah moments hidden inside of them.

If I had to pick something else... maybe finally understanding recursion well enough to use it practically, or the first time I used a reinterpret cast when dynamic cast was crashing my program and I knew there was solidly good reason why, but the assignment was due within a few minutes and I knew it would be a totally sneaky, underhanded, and perfectly reasonable thing for a dirty programmer to do to make the grade :D
 
iapetus said:
What don't you 'get' about it? The basic concepts? How to apply it?

Its seems like a lot is... I wouldnt say an unneccessary burden, but I tend to fall back to use ways NOT OOP even when trying to exercise OOP. Somewhere on this page I wrote that I used static methods to do stuff in my class and people just told me that with that I was basically undoing what OOP is for. Sigh.

Anyway, what the people were saying about it, already helped a great deal. Now I only need to concentrate on trying to use OOP concepts, but its hard if you programmed a while before without using OOP.
 
Toma said:
Could you explain why "managed" code is even regarded as a problem? Beginner here. I read up a bit about it, but didnt find much.


It doesn't teach you good memory management skills, which generally leads to people being much sloppier programmers.

When you do something like create an object on the heap in C#, and then finish using it, the memory allocated for the object will get removed by the garbage collector eventually. If you were to create an object in C++ and finish using it without manually de-allocating the memory, you'd have a memory leak. C++ is unforgiving when it comes to memory allocation/de-allocation.

For instance, before I understood a bit about how that all worked, I was working on a homebrew Xbox game. Everything would go fine for the first few minutes, but then it would bog itself down more and more until the Xbox crashed. Someone on here enlightened me to the fact that each enemy I created and then killed was still lingering in memory because I wasn't de-allocating the memory for them after they were killed. I learned the bad habit in C#, which always took care of deleting the leftover crap for me.
 
When I finally made a multiplayer game in Unity with vehicles Battlefield/crysis-like, that you can use as driver, passenger, transport other people...
 
I had my first personal "FUCK YEAH" moment when I finally understood the pointers in C.

The last one I had was while programming an AVR ATMega 8 and our robot (just a little one, which can't do much more than driving around) finally did what we wanted and I realised how the registers, the interrupts, the flags and stuff worked. Awesome. I like it a lot more now to program in Assembler then in C(++).
 
In a similar way as the OP several months ago I wrote in a couple of hours a simple image scraper so that I could download 30GB of images from a site.
Going page by page would have required me to much time.

When I was young I promised that I would create a breakout game in Pascal to show off at school the next day and I did it.
 
Ecrofirt said:
It doesn't teach you good memory management skills, which generally leads to people being much sloppier programmers.

When you do something like create an object on the heap in C#, and then finish using it, the memory allocated for the object will get removed by the garbage collector eventually. If you were to create an object in C++ and finish using it without manually de-allocating the memory, you'd have a memory leak. C++ is unforgiving when it comes to memory allocation/de-allocation.

If you think that you can't have 'memory leaks' in C# then you're sadly mistaken, it isn't as simple as 'I stopped using it so the garbage collector came and took it away!' though it's not quite the same as C++ either. With C# you have the problem of resources still being referenced even though you, the user, think you're not referencing them. If a resource is still being referenced anywhere the garbage collector will not come and free the memory.

I agree with the point that learning to manage memory is important but I don't think that diving into C++ game development is necessarily the best way to learn that. If you to make a game I recommend you stick with C#/XNA, Python/Pygame, or even something like Unity to save yourself the frustration.
 
I just thought of what was probably my most 'recent' Fuck YEA moment.

A few years back, I decided to re-create the Windows Starfield screensaver in C# using XNA.

I sat down and figured out the math needed to make everything work properly. Made me feel like a boss. The only thing I didn't figure out how to do was make the stars elegantly fly offscreen the same way they do in the Windows version.
 
Status
Not open for further replies.
Top Bottom