SFML community forums

General => General discussions => Topic started by: kolofsson on April 14, 2010, 02:44:32 pm

Title: Which language to use?
Post by: kolofsson on April 14, 2010, 02:44:32 pm
Hello. I am a hobbyist programmer. I do not have academic programming knowledge, only the things I learned on my own.

I would like to write a 2D racing game of my own, and I really like SFML. However, there are many obstacles when I try to write it in C++. I lack the flexibility of PHP, I can't really grasp the whole low-level programming stuff, like memory management, pointers. Converting numbers to strings is a real pain in the ass.

I have heard about Python, although I do not know how to program in this language.

So I would like to have some advice from more advanced programmers. For a hobbyist programmer, who does not like to fiddle much with the source code to get things done, which programming language should I use? Are the SFML bindings fully functional? Or should I stick with C++?
Title: Which language to use?
Post by: Walker on April 14, 2010, 03:12:57 pm
Firstly, I'm not formally educated in programming or anything similar.

I would really recommend C++ above the rest, I found parts of it ridiculous while I was learning the basics but now I am glad C++ is what I focused on.

I'm not a real fan of programming in Python, it can be a useful tool for scripting and automation, but I do view it as a tool rather than a "proper" programming language, I've never looked into the Python SFML binding.

I'm pretty sure the .NET binding is very close if not the same as the C++ one, if you are interested in a .NET language.

If you already are learning C++, I say stick with it.

Hopefully this is of some help and not just confusing :)

Converting numbers to strings pisses me off too lol :P
Title: Which language to use?
Post by: Laurent on April 14, 2010, 03:32:27 pm
All version of the .Net bindings are up-to-date (even in SFML 2) ;)
Title: Which language to use?
Post by: Ashenwraith on April 14, 2010, 03:44:09 pm
Just use C++ and keep it simple. You don't have to use pointers or anything complex. If you are just making a simple game you can hardcode most things (and that can even make it faster).

The real answer is that you need to make your game simple until you become a better programmer.

IE, make a shmup--there are a bunch of people here making those too.
Title: Which language to use?
Post by: kolofsson on April 14, 2010, 04:14:37 pm
so, by .NET you mean C#? I know that C# has some nice functions included, which make eg. type conversion easier. But is this whole "binding" a simple thing to do for a noob? Are there no compatibility issues, do the binding work 100% and are they efficient to use? How about portability, if I write in C#, will I be able to compile it under Linux?
Title: Which language to use?
Post by: Laurent on April 14, 2010, 04:29:40 pm
Quote
so, by .NET you mean C#?

I mean all .Net languages. Once an assembly is compiled, it can be used by all the .Net languages. There's a VB.Net sample in SFML.Net to demonstrate that.

Quote
But is this whole "binding" a simple thing to do for a noob?

The .Net API is almost the same as the C++ one, there are just a few things that have been modified to better suit the language.

Quote
Are there no compatibility issues

Compatibility with what? :)

Quote
do the binding work 100%

As far as I know.

Quote
and are they efficient to use?

Absolutely, the overhead of accessing the actual functions through several DLLs is in fact pretty low.

Quote
How about portability, if I write in C#, will I be able to compile it under Linux?

I've written the binding with Linux compatibility in mind. I've never tried to compile it on Linux with Mono, but it should be ok.
Title: Re: Which language to use?
Post by: gsaurus on April 14, 2010, 04:31:23 pm
Quote from: "kolofsson"
I lack the flexibility of PHP, I can't really grasp the whole low-level programming stuff, like memory management, pointers. Converting numbers to strings is a real pain in the ass.

If you know and are used to php I definitely suggest not to use C++. I suggest you to try Phyton (http://python.org/) or Ruby (http://www.ruby-lang.org), they are more like php style.

Quote from: "kolofsson"
I have heard about Python, although I do not know how to program in this language.

There's plenty of information out there, just have a look at Phyton site (http://python.org/), it's documentation (http://docs.python.org/) and wiki beginners guide (http://wiki.python.org/moin/BeginnersGuide).

I think C++ is too much powerful and complex for what you want, give Phyton a try and see what you think about it ;)
I actually never used Phyton or Ruby, but I have an idea about it...
Title: Which language to use?
Post by: Ashenwraith on April 14, 2010, 04:43:31 pm
Asking what language to program SFML in is kinda like moving to Japan and asking what language you should speak.

Yeah, you can speak whatever you want, but depending on who you want to understand and help you is important. It depends on your background and what you want to do.
Title: Which language to use?
Post by: kolofsson on April 14, 2010, 05:18:16 pm
Quote from: "Laurent"

I mean all .Net languages. Once an assembly is compiled, it can be used by all the .Net languages. There's a VB.Net sample in SFML.Net to demonstrate that.


OK, I read a bit about the .NET. I did not know that there are more languages than C# working with the .NET framework.

So, I have found out that there is such thing as iron Python, which is Python for .NET. So the question is, which would be better: PySMFL or SFML.NET with iron Python?
Title: Which language to use?
Post by: Walker on April 15, 2010, 02:58:23 am
If you are going to be coding in Python, PySFML is most certainly the better choice.
Title: Re: Which language to use?
Post by: Mindiell on April 15, 2010, 08:26:09 am
Quote from: "kolofsson"
Converting numbers to strings is a real pain in the ass.
Why do you want to do that ? Don't you think you could do better by using strings for string stuff and numbers for number stuff ?
Title: Re: Which language to use?
Post by: pdusen on April 15, 2010, 12:52:11 pm
Quote from: "Mindiell"
Quote from: "kolofsson"
Converting numbers to strings is a real pain in the ass.
Why do you want to do that ? Don't you think you could do better by using strings for string stuff and numbers for number stuff ?


Anyway, it's not really hard at all.

Code: [Select]

int number = 5;

std::stringstream num_stream;

num_stream << number;

std::string num_string = num_stream.str();


And besides that, Boost (and C++0x, I believe) offer a lexical_cast to do pretty much the same thing in one line.
Title: Re: Which language to use?
Post by: kolofsson on April 15, 2010, 11:01:27 pm
Quote from: "Mindiell"
Why do you want to do that ? Don't you think you could do better by using strings for string stuff and numbers for number stuff ?


Wow, I almost don't know how to respond to that. I need to print some values to check how some variables behave. Anyway, I'm using the good old sprintf. For me, the c++ way of working with strings is terrible.
Title: Re: Which language to use?
Post by: Mindiell on April 16, 2010, 09:22:24 am
Quote from: "kolofsson"
Wow, I almost don't know how to respond to that. I need to print some values to check how some variables behave. Anyway, I'm using the good old sprintf. For me, the c++ way of working with strings is terrible.

Why don't you simply use std::cout ?
Code: [Select]
int main()
{
 int a = 3;
 float b = 3.4;
 std::string foo = "bar";

 std::cout<<"int : "<<a<<std::endl;
 std::cout<<"float : "<<a<<std::endl;
 std::cout<<"string : "<<a<<std::endl;
}


Be careful, I'm just asking questions, not judging you. It's always interesting to see what others do.
Title: Which language to use?
Post by: Walker on April 16, 2010, 11:08:29 am
std::cout is fine until you want to use something like sf::String and have numbers to print to it. I imagine this is what kolofsson is trying to do.

As pdusen said it's not that hard anyway, although it is a little bit more difficult than string += someInt;  :lol:
Title: Which language to use?
Post by: Mindiell on April 16, 2010, 12:18:41 pm
For an sf::string, of course, a stringstream will help :wink:
Title: Which language to use?
Post by: gsaurus on April 16, 2010, 12:22:49 pm
then, use phyton  :lol:

Code: [Select]
myAge = 23
myString = "I am " + str(myAge) + " years old"
Title: Re: Which language to use?
Post by: kolofsson on April 16, 2010, 12:38:28 pm
Quote from: "Mindiell"
Be careful, I'm just asking questions, not judging you. It's always interesting to see what others do.


Hey I didn't mean to offend you, I was only puzzled by your question.

Here is how my code looks like:

Code: [Select]
int txt = sprintf_s(string, "KPH %6.0f WHEELS %6.2f AIR %6.3f DISTANCE %6.0f POWER %6.0f", s, wheels, air, dist, pwr);
label.SetString(string);


Label is an sf::Text object. So, as you can see, displaying these numbers with all the formatting, using c++ streams would be much more complex.

Anyway, I seem to have some problem with my code. I declare the "float wheels = 0.f;" and when I run the program, SOMETIMES it is not equal to zero. it's very strange to me. the value randomly is equal to zero or something else, each time I run the program.
Title: Which language to use?
Post by: Mindiell on April 16, 2010, 02:11:33 pm
Very strange, what is the value in wheels if it's not 0 ?

Quote from: "kolofsson"
Hey I didn't mean to offend you, I was only puzzled by your question.
Ok, I was afraid I offended you. I'm french and am not always completely sure of my english comprehension ;)
Title: Which language to use?
Post by: Laurent on April 16, 2010, 02:29:18 pm
Quote from: "gsaurus"
then, use phyton  :lol:

Code: [Select]
myAge = 23
myString = "I am " + str(myAge) + " years old"

Use C++ 8)
Code: [Select]
template <typename T>
std::string str(const T& t)
{
    std::ostringstream oss;
    oss << t;
    return oss.str();
}

int myAge = 23;
std::string myString = "I am " + str(myAge) + " years old";
Title: Which language to use?
Post by: gsaurus on April 16, 2010, 04:48:24 pm
I know Laurent :P For us C++ coders, it's all ok 8) But for a hobbyist programmer phyton is much simpler to learn and use.

But it's all up to you kolofsson, learning C++ is great but will probably make things harder to you. If you have the time and interest on learning and use C++ with SFML for your game, go ahead  :). But if you just want to make a game without many worries, I'd say phyton. Phyton specially if you're used to php and/or javascript, because they all uses dynamic type checking, when C++ uses static typing instead.

I found this comparison article (http://www.dmh2000.com/cjpr/), actually I didn't read it all, but you may find it interesting.
Title: Which language to use?
Post by: Trass3r on April 20, 2010, 12:38:00 pm
D (http://www.digitalmars.com/d/) is also to be chosen over C++.
But if you are into php you better go with Python or some other high-level language.
Title: Which language to use?
Post by: Wibbs on April 30, 2010, 12:58:10 am
I'm working with SFML and c# and apart from a few minor wrinkles largely to do with my misunderstanding the SFML API, its been extremely straightforward to use.