Advantages of coding your gamemode in C++ over Pawn? -
Piooo - 13.11.2017
Recently I've noticed some servers turning to other scripting languages such as C++.
I was wondering why these servers would turn away from pawn, and what the (dis)advantages are.
Thank you.
Re: Advantages of coding your gamemode in C++ over Pawn? -
Sithis - 15.11.2017
C++ is supposed to be faster. However, I don't see why you would use C++ when you can use C# as well (SampSharp).
C# is much more suitable for SA:MP because it's a business language that you can use to interact with your database on a high level.
Pawn isn't a very well made language at all. No object oriented programming, no multi threading, etc..
Re: Advantages of coding your gamemode in C++ over Pawn? -
10MIN - 15.11.2017
C++ is faster because it is compiled directly to machine-code, and Pawn compiled to byte-code for a virtual machine (integrated in the samp-server).
Also don't think it should which language is better is important (you can use Pawn, C/++, Java, C# even Lua). You are the artist, and they brushes, use the best one that suites your needs to make art.
Re: Advantages of coding your gamemode in C++ over Pawn? -
NaS - 15.11.2017
Quote:
Originally Posted by Sithis
C++ is supposed to be faster. However, I don't see why you would use C++ when you can use C# as well (SampSharp).
C# is much more suitable for SA:MP because it's a business language that you can use to interact with your database on a high level.
Pawn isn't a very well made language at all. No object oriented programming, no multi threading, etc..
|
I don't think anyone would use C++ over PAWN just for plain speed improvement. Pawn isn't so slow that you could do way more in C++. It's most likely the style and features that get you to use C++.
Some more advantages of C++ (many of them would also apply to C#, Java, Lua etc) are:
- A language that is used not only for SAMP, Pawn isn't really used in many projects. Search for Pawn in a Search Engine and most of the results will be SAMP related (except results related to the language itself). So getting help on certain issues may not require you to ask in this forum, or someone who knows Pawn.
- Non-SAMP specific libraries that you could directly include and use without writing a wrapper-Plugin. Some of them aren't really possible to port to PAWN even (although that is only the case rarely, I guess).
- Language features. C++ is way more dynamic and you can do a lot more without any additional library. Besides dynamic memory allocation, there are real data types (which means more efficient data storage), data structures (structs, real Vectors & Maps, etc - without relying on 3rd party addons) and much more. Using these in Pawn will still require you to buffer certain data in the VM's memory, in C++ however you won't need to.
- If you learn Pawn, you will probably only learn it for SAMP and never use it anywhere else. If you learn C++, you will be able to use that knowledge for projects outside of SAMP later, even in case you quit SAMP (this is obviously not a reason to use C++, but a nice side-effect if you do so anyway)
Many of these things can also be achieved by writing a Plugin, but that's not really the same.
Disadvantages:
- You should have some knowledge already, otherwise you won't know what you are doing. Pawn is much easier, modifying a Script is easy even if you're not into programming or scripting at all (to a certain degree, of course).
- Doing a small mistake in Pawn will crash the server at most (if you are really unlucky you mess up player accounts or something). Doing a small mistake in C++ may get unnoticed for weeks, but actually screw up many parts of the server (not only your gamemode), causing weird issues you may not be able to link to that mistake. Unlikely, but possible.
Related to that, pure Pawn is free of Memory Leaks and similar issues.
These two disadvantages however aren't really disadvantages, it's just obvious that a way more powerful language is also more complicated and prone to critical mistakes.
Probably the most annoying one is Windows/Linux. Every Pawn Script will run on both OS, a C++ gamemode/plugin must be compiled for the specific OS. But if you manage to do that, I don't really see a disadvantage in using C++ if you know what you are doing.
Re: Advantages of coding your gamemode in C++ over Pawn? -
Sithis - 15.11.2017
Yes NaS, that's one of the main reasons i'm currently coding in C#.
It offers the NuGet package source which allows you to use any database backend you like without having to wait for someone in the SA-MP community to update all the plugins. It also allows you to use ORM such as nHibernate and Entity Framework, amongst other plugins.
My main reason for C# over C++ is its easy syntax for manipulating lists and working with the database behind it (in my case, MS SQL Server). The performance benefits of using C++ are IMHO not outweighed by the syntax sugar that C# offers. It dramatically reduces the complexity and amount of code needed in my gamemode.
See screenshot how easy it is to handle dialogs and events:
https://imgur.com/a/9olyd
Re: Advantages of coding your gamemode in C++ over Pawn? -
Dayrion - 25.11.2017
Quote:
Originally Posted by Sithis
Yes NaS, that's one of the main reasons i'm currently coding in C#.
It offers the NuGet package source which allows you to use any database backend you like without having to wait for someone in the SA-MP community to update all the plugins. It also allows you to use ORM such as nHibernate and Entity Framework, amongst other plugins.
My main reason for C# over C++ is its easy syntax for manipulating lists and working with the database behind it (in my case, MS SQL Server). The performance benefits of using C++ are IMHO not outweighed by the syntax sugar that C# offers. It dramatically reduces the complexity and amount of code needed in my gamemode.
See screenshot how easy it is to handle dialogs and events:
https://imgur.com/a/9olyd
|
I'm very interesting by that. Have any useful links for me (tutorial in C#, conversion for pawn, ...) ? :x
Re: Advantages of coding your gamemode in C++ over Pawn? -
Sithis - 25.11.2017
Sure thing, check out sampsharp.timpotze.nl
Re: Advantages of coding your gamemode in C++ over Pawn? -
hawk2012 - 25.11.2017
IMHO programming style is chosen by the person himself, not so important on what you write, the main thing is that there were no bugs