SA-MP Forums

Go Back   SA-MP Forums > SA-MP Server > Server Support

Reply
 
Thread Tools Display Modes
Old 13/11/2017, 01:10 PM   #1
Piooo
Little Clucker
 
Join Date: Mar 2012
Posts: 13
Reputation: 0
Default Advantages of coding your gamemode in C++ over Pawn?

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.
Piooo is offline   Reply With Quote
Old 15/11/2017, 08:03 AM   #2
Sithis
Gangsta
 
Join Date: Mar 2013
Location: the Netherlands
Posts: 833
Reputation: 52
Default Re: Advantages of coding your gamemode in C++ over Pawn?

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..
__________________

Follow the development of trinityRPG (C#): https://revctrl.com/fvandillen/trinityRPG/
Sithis is offline   Reply With Quote
Old 15/11/2017, 08:55 AM   #3
10MIN
Huge Clucker
 
10MIN's Avatar
 
Join Date: Jun 2017
Location: Clockania
Posts: 297
Reputation: 24
Default Re: Advantages of coding your gamemode in C++ over Pawn?

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.
__________________
__________________
__________________
__________________
__________________
__________________
__________________
10MIN is offline   Reply With Quote
Old 15/11/2017, 09:32 AM   #4
NaS
High-roller
 
NaS's Avatar
 
Join Date: Mar 2008
Location: Germany
Posts: 1,136
Reputation: 331
Default Re: Advantages of coding your gamemode in C++ over Pawn?

Quote:
Originally Posted by Sithis View Post
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.
NaS is offline   Reply With Quote
Old 15/11/2017, 12:27 PM   #5
Sithis
Gangsta
 
Join Date: Mar 2013
Location: the Netherlands
Posts: 833
Reputation: 52
Default Re: Advantages of coding your gamemode in C++ over Pawn?

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
__________________

Follow the development of trinityRPG (C#): https://revctrl.com/fvandillen/trinityRPG/
Sithis is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
What are the advantages of using CallLocalFunction NeXoR Scripting Help 6 01/11/2016 10:43 PM
Coding Pawn Framework Regziol Discussion 17 27/12/2012 09:01 PM
Advantages/Disadvantages of using one string. ReneG Scripting Help 11 14/06/2012 05:16 AM
need advantages and disadvantages of these working styles! [EDT]AmanSingh123 Everything and Nothing 3 14/10/2011 05:55 PM


All times are GMT. The time now is 03:45 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.