The Official Programming Thread

MegamanEXE

Well-known member
Dec 7, 2007
1,958
1
43
28
Islamabad
@gullfounder
Unity uses C# and Lua/Boo (can't remember ) so if u want u can make scripts or get experience by working in unity (Me and my friend worked on it and it was a good experience )
secondly if u wanna learn a new language... C++ is there Cryengine uses it.... Thirdly, if u want u can come towards Ruby, RPGMakerVXA uses it and you can try building a nice game
@MegamanEXE
Hmm thanx for the info so after learning from codeacademy can i start making scripts? to use in Rpgmaker vxa engine? :D
I get what you are trying to say i'd like to quote from Rob Miles C# book if you allow....

Spoiler: show
I referred to C as a dangerous language. So what do I mean by that? Consider the chain saw. If I, Rob Miles, want to use a chain saw I will hire one from a shop. As I am not an experienced chain saw user I would expect it to come with lots of built in safety features such as guards and automatic cut outs. These will make me much safer with the thing but will probably limit the usefulness of the tool, i.e. because of all the safety stuff I might not be able to cut down certain kinds of tree. If I was a real lumberjack I would go out and buy a professional chain saw which has no safety features whatsoever but can be used to cut down most anything. If I make a mistake with the professional tool I could quite easily lose my leg, something the amateur machine would not let happen.In programming terms what this means is that C lacks some safety features provided by other programming languages. This makes the language much more flexible.
However, if I do something stupid C will not stop me, so I have a much greater chance of crashing the computer with a C program than I do with a safer language.

I reckon that you should always work on the basis that any computer will tolerate no errors on your part and anything that you do which is stupid will always cause a disaster! This concentrates the mind wonderfully.


I liked how he introduced it :D
I'll agree with you but for the meantime im still learning Ruby and i'll say its High Level and much easier to understand and use....
lel, that's a pretty great way to put what I was trying to say. I'm gonna use this analogy on others :p You know of the heartbleed exploit, right? It was nothing more than this, C doesn't tell you it's causing a buffer overrun, and it's fine. You can use all that power to your advantage or you could cause serious catastrophe. Your call. :)
Ruby's alright, If I remember correctly, The Verge and Polygon is designed in Ruby, and I must say they have one of the best web designing on the internet.

@gullfounder
If you know C# well, I see no reason why you shouldn't go for XNA? If you're going for C++, SFML would be a good choice. It's quite intuitive.

@Gizmo
OOP is more of programming concept, almost all the new and current languages are object-oriented. People don't exactly program EVERYTHING in C++, you have to rely heavily on 3rd party libraries. If you were to do this from scratch, I'm pretty sure you'll take over a week just to show a pixel. If you're interested in game programming, and you're learning C++, I'd also suggest that you give SFML a try later on. To this day, I still don't know how cout and cin work. If you go into the library, you'd have no idea what they're doing. My Stanford PhD teacher also told me he has no idea how cin and cout works.
As an example, this is how the code in SFML would look like:
Code:
class Player
{
Texture protagonistTexture("Assets/lolSprite.png");
Velocity<float> initialVelocity;
//other stuff
}
So, it provides basic utility to read, display images and sound and handle controls etc. It's based on OpenGL, so all OpenGL code can directly work as well.

For beginners (I'm no pro myself), I just found this today on Reddit, I highly suggest you follow this dude. He's a game dev and I found his video quite good and not boring. His pacing is perfect as well (for me, at least).
http://www.reddit.com/r/gamedev/comments/2eb5d8/copenglsdl_game_engine_tutorials_for_an_absolute/
 
Last edited:

EternalBlizzard

Lazy guy :s
Moderator
Oct 29, 2011
2,732
1,195
129
Attractor Field Beta
Code:
class MyClass
  my_variable = "Hello!"
end


puts my_variable  # Result is nothing, Undefined local variable or method
@MegamanEXE
if you can, i need some help in understanding different types of variables....
The above code is an example to show how i can't access the local variable outside the class... i'll have to make that global by inserting "$" before the name of the variable. Awrite i understand uptill here. The thing i don't understand is the difference between instance variable and class variable

In Ruby, we use @ before a variable to signify that it's an instance variable. This means that the variable is attached to the instance of the class.
Class variables are like instance variables, but instead of belonging to an instance of a class, they belong to the class itself. Because there's only one copy of a class variable shared by all instances of a class, we can use them to pull off some cool Ruby tricks. For example, we can use a class variable to keep track of the number of instances of that class we've created.

I don't understand the bold part... plus i don't know what they mean by "instance of that class"
 

MegamanEXE

Well-known member
Dec 7, 2007
1,958
1
43
28
Islamabad
Code:
class MyClass
  my_variable = "Hello!"
end


puts my_variable  # Result is nothing, Undefined local variable or method
@MegamanEXE
if you can, i need some help in understanding different types of variables....
The above code is an example to show how i can't access the local variable outside the class... i'll have to make that global by inserting "$" before the name of the variable. Awrite i understand uptill here. The thing i don't understand is the difference between instance variable and class variable

In Ruby, we use @ before a variable to signify that it's an instance variable. This means that the variable is attached to the instance of the class.
Class variables are like instance variables, but instead of belonging to an instance of a class, they belong to the class itself. Because there's only one copy of a class variable shared by all instances of a class, we can use them to pull off some cool Ruby tricks. For example, we can use a class variable to keep track of the number of instances of that class we've created.

I don't understand the bold part... plus i don't know what they mean by "instance of that class"
Although I don't know Ruby, but I can understand your question and confusion. As you mentioned you know C#, I'll write in C++, which is kinda similar, so you'll understand. Anyway, this is common to all OO languages, common example is that of a car. a Class is just a blueprint, and you make an Object (a car) from that blueprint.

Instance simply means you MAKE something from the blueprint. A car is an instance of its blueprint. You can instantiate 1000s of cars from that one single blueprint. So, when you simply make a class, you make the blueprint, not the car!
I'll write a simple example:
Code:
class Car
{
string Name;
string Color;
int ModelYear;
static int TimesManufactured; (or int* TimesManufactured;)
};

int main() {
 Car Blizzards_Car; 
Car MegamanEXEs_Car;
Car NaNoWs_Car;
}
So until you build a car out of the blueprint, the variable DO NOT EXIST anywhere. A class is just a generalization, you CANNOT give values to a blue print. So when the program is run, all of the 3 cars have theiry own names, colors and Model Year. These are your "Instance Variables".

For class variables, as you mentioned, this is the most common usefor it to keep a track of how many objects were made. All the cars have the same TimesManufactured to keep a track of the number of cars made. This is your Class Variable. And it belongs to the CLASS, not the OBJECTS (cars). If it belonged to the cars, there would be a new TimesManufactured everytime a new car was made, which would make it pretty pointless.

INSTANCE VARIABLES: 10 cars = 10 variables (memory for 10 variables allocated)(Objects own them)
CLASS VARIABLES: 1000 cars = 1 variable (memory for only 1 variable will be allocated)(The blueprint/Class owns them)

Again, this is its most common use; to keep a track of instances. :)
Well, I dunno if this applies in Ruby, but it probably does. Another difference between Instance and Class Variables is this, Instance variables are only created when instantiate(make) an OBJECT and is destroyed when the object is destroyed/deleted.

Whereas CLASS variables are MADE/ALLOCATED when the program starts, and destroyed when the program ends. It doesn't matter if you created even one object or not. Even if you don't make a single Car object, the class variable would still be there, whether you used it or not.

Hope you get it, I can explain further or more analogies if you want. It's no trouble.

Just for extra knowledge, this is how smart pointers work.
 
Last edited:

gullfounder

Phoenix Dawn
Supervisor
Aug 25, 2008
970
3
24
Khanpur
If anything, the above is the only lines of code I've written the whole vacations -_- Should have done more though.
Could you pleas explain the advantages and disadvantages of XNA and Unity? Most people say go for Unity it has more future then XNA!! so i am confused. I wanna invest time on something that makes worth while. Not something that will last few years and phoof gone.
 

MegamanEXE

Well-known member
Dec 7, 2007
1,958
1
43
28
Islamabad
Could you pleas explain the advantages and disadvantages of XNA and Unity? Most people say go for Unity it has more future then XNA!! so i am confused. I wanna invest time on something that makes worth while. Not something that will last few years and phoof gone.
Well, did a little search, it seems that Microsoft has given up support for XNA, and they too, are supporting Unity now. Well, Unity is growing pretty quickly, and it's multi-platform, that's why it's getting so popular as well. If you want something that's "worthwhile and won't last a few years and phoof gone", then almost anyone will suggest you to go for Unity. Since you know C#, you shouldn't have trouble. Going for XNA will probably be TOO deep into the code, and again there's a chance that XNA will "last a few years". Platform-wise, XNA only makes games for Windows and Xbox as far as I know.

The reason everybody's suggesting Unity is because it's getting more and more powerful. A week or 2 ago, this showed up on my Facebook: Unity in Visual Studio, I think you could be comfortable with this, right?

Visual Studio Tools for Unity 1.9 - The Visual Studio Blog - Site Home - MSDN Blogs

For the world, people won't really care if you spent over 6 months programming your own engine, they won't appreciate you for your hard work, but for your end-product; whether it took a year, or 4 months. Unity should provide you basic code so you won't have to re-invent the wheel. Again, it's C#, your domain.

I have no knowledge about this but I've seen the word "MonoDevelop" thrown a lot around the C# community, maybe you could search for that if it tickles your fancy.
 

EternalBlizzard

Lazy guy :s
Moderator
Oct 29, 2011
2,732
1,195
129
Attractor Field Beta
Although I don't know Ruby, but I can understand your question and confusion. As you mentioned you know C#, I'll write in C++, which is kinda similar, so you'll understand. Anyway, this is common to all OO languages, common example is that of a car. a Class is just a blueprint, and you make an Object (a car) from that blueprint.

Instance simply means you MAKE something from the blueprint. A car is an instance of its blueprint. You can instantiate 1000s of cars from that one single blueprint. So, when you simply make a class, you make the blueprint, not the car!
I'll write a simple example:
Code:
class Car
{
string Name;
string Color;
int ModelYear;
static int TimesManufactured; (or int* TimesManufactured;)
};

int main() {
 Car Blizzards_Car; 
Car MegamanEXEs_Car;
Car NaNoWs_Car;
}
So until you build a car out of the blueprint, the variable DO NOT EXIST anywhere. A class is just a generalization, you CANNOT give values to a blue print. So when the program is run, all of the 3 cars have theiry own names, colors and Model Year. These are your "Instance Variables".

For class variables, as you mentioned, this is the most common usefor it to keep a track of how many objects were made. All the cars have the same TimesManufactured to keep a track of the number of cars made. This is your Class Variable. And it belongs to the CLASS, not the OBJECTS (cars). If it belonged to the cars, there would be a new TimesManufactured everytime a new car was made, which would make it pretty pointless.

INSTANCE VARIABLES: 10 cars = 10 variables (memory for 10 variables allocated)(Objects own them)
CLASS VARIABLES: 1000 cars = 1 variable (memory for only 1 variable will be allocated)(The blueprint/Class owns them)

Again, this is its most common use; to keep a track of instances. :)
Well, I dunno if this applies in Ruby, but it probably does. Another difference between Instance and Class Variables is this, Instance variables are only created when instantiate(make) an OBJECT and is destroyed when the object is destroyed/deleted.

Whereas CLASS variables are MADE/ALLOCATED when the program starts, and destroyed when the program ends. It doesn't matter if you created even one object or not. Even if you don't make a single Car object, the class variable would still be there, whether you used it or not.

Hope you get it, I can explain further or more analogies if you want. It's no trouble.

Just for extra knowledge, this is how smart pointers work.
Well your code pretty much cleared it up.... tell me if i got it right. ok...
Instance variables are unique i.e they can get different values each time an instance of class is run..? On the other hand we can't do that with class variables, they are defined only once and they are true ( meaning have the same value ) for all instances?

Secondly if you saw my code.... you can see that i can't access a local variable outside the method or class... Can i declare another variable outside the method of the same name as that of INSIDE the method/class but having different value?

Thirdly i don't understand a little thing in this code. I have written blocks explaining the code. If you can understand it then answer my third question :D
Spoiler: show

Code:
class Language  def initialize(name, creator)                                               # You define methods using "def method_name(parameter)"
    [MENTION=27317]name[/MENTION] = name
    @creator = creator
  end
	
  def description
    print "I'm # [MENTION=27317]name[/MENTION]} and I was created by #{@creator}!"    {  #{variable_name} puts the value of the variable may it be string, fixnum or any other data }
  end
end


ruby = Language.new("Ruby", "Yukihiro Matsumoto")                { you create instances of class by calling ".new" on class name } 
python = Language.new("Python", "Guido van Rossum")
javascript = Language.new("JavaScript", "Brendan Eich")


ruby.description                                                                { calling "description" method on varaible "Ruby" }
python.description
javascript.description


So you saw that... in the last part we used
Code:
Language.new("Ruby" , "Yukihiro Matsumoto")
What i learnt previously was that
we define methods by
Code:
def method_name(parameter)
we call it by
Code:
method_name(argument)
so that the argument we give goes into the parameter and in the method we play with it as we like but here we gave the argument to the CLASS instead of the METHOD "Initialize(name, creator)" so how did it know to put the arguments in the method...?
 

gullfounder

Phoenix Dawn
Supervisor
Aug 25, 2008
970
3
24
Khanpur
Well, did a little search, it seems that Microsoft has given up support for XNA, and they too, are supporting Unity now. Well, Unity is growing pretty quickly, and it's multi-platform, that's why it's getting so popular as well. If you want something that's "worthwhile and won't last a few years and phoof gone", then almost anyone will suggest you to go for Unity. Since you know C#, you shouldn't have trouble. Going for XNA will probably be TOO deep into the code, and again there's a chance that XNA will "last a few years". Platform-wise, XNA only makes games for Windows and Xbox as far as I know.

The reason everybody's suggesting Unity is because it's getting more and more powerful. A week or 2 ago, this showed up on my Facebook: Unity in Visual Studio, I think you could be comfortable with this, right?

Visual Studio Tools for Unity 1.9 - The Visual Studio Blog - Site Home - MSDN Blogs

For the world, people won't really care if you spent over 6 months programming your own engine, they won't appreciate you for your hard work, but for your end-product; whether it took a year, or 4 months. Unity should provide you basic code so you won't have to re-invent the wheel. Again, it's C#, your domain.

I have no knowledge about this but I've seen the word "MonoDevelop" thrown a lot around the C# community, maybe you could search for that if it tickles your fancy.
Monodevelop is tool to make andriod app or game using c#. They have fully integrated it with unity. So it give us very powerfull function in unity. We need to make game once and convert to every major platform.
 

MegamanEXE

Well-known member
Dec 7, 2007
1,958
1
43
28
Islamabad
Well your code pretty much cleared it up.... tell me if i got it right. ok...
Instance variables are unique i.e they can get different values each time an instance of class is run..? On the other hand we can't do that with class variables, they are defined only once and they are true ( meaning have the same value ) for all instances?

Secondly if you saw my code.... you can see that i can't access a local variable outside the method or class... Can i declare another variable outside the method of the same name as that of INSIDE the method/class but having different value?

Thirdly i don't understand a little thing in this code. I have written blocks explaining the code. If you can understand it then answer my third question :D
Spoiler: show

Code:
class Language  def initialize(name, creator)                                               # You define methods using "def method_name(parameter)"
    @[B][U][URL="http://www.pakgamers.com/forums/member.php?u=27317"]name[/URL][/U][/B] = name
    @creator = creator
  end
    
  def description
    print "I'm # @[B][U][URL="http://www.pakgamers.com/forums/member.php?u=27317"]name[/URL][/U][/B]} and I was created by #{@creator}!"    {  #{variable_name} puts the value of the variable may it be string, fixnum or any other data }
  end
end


ruby = Language.new("Ruby", "Yukihiro Matsumoto")                { you create instances of class by calling ".new" on class name } 
python = Language.new("Python", "Guido van Rossum")
javascript = Language.new("JavaScript", "Brendan Eich")


ruby.description                                                                { calling "description" method on varaible "Ruby" }
python.description
javascript.description


So you saw that... in the last part we used
Code:
Language.new("Ruby" , "Yukihiro Matsumoto")
What i learnt previously was that
we define methods by
Code:
def method_name(parameter)
we call it by
Code:
method_name(argument)
so that the argument we give goes into the parameter and in the method we play with it as we like but here we gave the argument to the CLASS instead of the METHOD "Initialize(name, creator)" so how did it know to put the arguments in the method...?

Quite simple, really.
1) Yes, you're completely right.
2) I tried a test code, and it was possible to create a new variable i.e. modelYear in a method (or function, you can call it) even though a instance variable called modelYear already exists. This is possible in C/C++. Although I don't know if it's common to all languages. But remember, just because you CAN doesn't mean you SHOULD. It's almost never a good idea to give same names. In C++, if I want to give the new modelYear the value of the instance Variable in the class, I'd have to write:
Code:
int modelYear = this->modelYear
the 'this->modelYear' is the instance variable. The one on left side in the new one. You should do what I do. I give a prefix called 'arg' or 'temp'. So, I'd write
Code:
int tempModelYear = modelYear
or
Code:
modelYear = argModelYear
This is cleaner and you can immediately understand what's being assigned.

3) This is quite simple, I don't know Ruby but I knew what to search and I was right. the initialize() method is what we call a CONSTRUCTOR. Basically, a constructor is just a method that is called automatically when you create an object. It's not necessary, but we do it just to give initial values to variables in a class. For example, in ruby, a bank account class would be something like (I'm not sure of the syntax but bear with me for a while)

Code:
class Account
balance
end
Wouldn't it be nice (and logical) to give it an initial value of 0 instead of some random number like -8654552. But as far as programming languages go, you (probably) cannot do something like (Although this was possible in the older C, but this was depracated/removed from the standards):
Code:
balance = 0
Because you shouldn't give values to a blueprint. Blueprints are general-purpose.

How ruby handles it is when it creates a new object, it automatically calls the initialize() method. In C/C++/C#, the constructor method name is usually the class name itself.

So, the simple answer is, the initialize method is called automatically, you don't have to do something like
Code:
ruby.initialize("blabla","meh")
Constructors and destructors, you should look them up. :)
 
Last edited:

staticPointer

PG LEGENDARY
Dec 7, 2012
3,266
0
41
افغانستان
www.pakgamers.com
lets make this thread more widely .. uuhhhh.. any one needs help regarding digital image processing (dip/matlab/simulation), machine learning (ml), comp graphics, comp vision (cv) or robotics .. just ask for the help ... im always there !!!
 

sufi

Well-known member
Member Sellers
Jul 22, 2012
1,780
25
45
Karachi
www.facebook.com
lets make this thread more widely .. uuhhhh.. any one needs help regarding digital image processing (dip/matlab/simulation), machine learning (ml), comp graphics, comp vision (cv) or robotics .. just ask for the help ... im always there !!!
Im in 6th semester , love Matlab , but still couldn't learn it syntax or its matrix stuff .. Loops specially .. Can You help me .?
whats your skype .?
 

staticPointer

PG LEGENDARY
Dec 7, 2012
3,266
0
41
افغانستان
www.pakgamers.com
Im in 6th semester , love Matlab , but still couldn't learn it syntax or its matrix stuff .. Loops specially .. Can You help me .?
whats your skype .?
sure...ask me here openly so that others can also learn ...

- - - Updated - - -

Thanks for opening this thread .. It will shine the skills of programmers :)
InShaa Allah

- - - Updated - - -

i have a questions that why in pak "php", "c#", "java" & "asp.net" pe kam ho rha ..? why are not in robotics, machine learning ?? i need some serious reply from the currently working coders (s/w houses) ...
 

mubaidr

Me Gusta
Jan 15, 2010
1,859
3
44
Rawalpindi
mubaidr.github.io
i have a questions that why in pak "php", "c#", "java" & "asp.net" pe kam ho rha ..? why are not in robotics, machine learning ?? i need some serious reply from the currently working coders (s/w houses) ...
This is because most of the work being done here is outsourced by the contractors from other countries, which, obviously, is not favorable for mentioned type of projects (robotics + machine learning). Plus we do not have any applications of these fields, result is we have no industries here. Even, i think, Machine learning is less adopted in research fields too.

This is what i think, please correct me if i am wrong.
 

gullfounder

Phoenix Dawn
Supervisor
Aug 25, 2008
970
3
24
Khanpur
sure...ask me here openly so that others can also learn ...

- - - Updated - - -



InShaa Allah

- - - Updated - - -

i have a questions that why in pak "php", "c#", "java" & "asp.net" pe kam ho rha ..? why are not in robotics, machine learning ?? i need some serious reply from the currently working coders (s/w houses) ...
I agree on your point. There is not interest in these types projects. Also its true that sw here are just out sourceing. So, there is no real research going on here nor any type of work.

In my last year. I programmed atml chip to communicate over radio wave with computer. Using this i created a simple car with on board camera gps and ir. Camera would send live video over radio too. But i used seprate channel for that. Atml was programmed in c and c# app was developed to controll it from laptop or pc.

Since then i never touched any hardware project. Although i love to work on arduion board or .net hardwarea.
 

EternalBlizzard

Lazy guy :s
Moderator
Oct 29, 2011
2,732
1,195
129
Attractor Field Beta
Guys i just learnt Ruby... still have to learn OOP in Ruby but before that i was thinking of making some simple programs so that i can use the knowledge i have gained and you know i will be able to memorize it all... So i want some ideas on what program should i make...Code academy had an exercise where i made program which
1) stores My Movies and their ratings
2) Updates existing content
3) Delete existing content

So yeah programs like these will help me use all the knowledge making it easier to memorize all the methods etc.... Unfortunately i can't think of any... :p If anyone can help give some ideas it'll be great
 
General chit-chat
Help Users
We have disabled traderscore and are working on a fix. There was a bug with the plugin | Click for Discord
  • No one is chatting at the moment.
    faraany3k faraany3k: Tears of Kingdom saal pehle shuru ki thee, ab tk pehle area se nai nikla. Life sucks donkey balls.