SA-MP Forums Archive
Choosing a programming language - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Discussion (https://sampforum.blast.hk/forumdisplay.php?fid=84)
+---- Thread: Choosing a programming language (/showthread.php?tid=465815)



Choosing a programming language - DexX39 - 24.09.2013

Hello,

I have a question.
We can develop a GM with Pawn langage.
But, on the forum, I saw that GM could be develop in Java or PHP

Links : PHP or Java

Is it interesting and optimized ? Is it not going to be too heavy for SA-MP client ?
Is that it is useful to use object-oriented programming to develop a GM ?

Thx !


Re: Choosing a programming language - Deji - 26.09.2013

I'm using C++ and it's a dream. But I'm already kina big on C++ anyway...


Re: Choosing a programming language - zgintasz - 26.09.2013

I would use C++ too, leave that stupid pawn somewhere in a corner...


Re: Choosing a programming language - playbox12 - 30.09.2013

Quote:
Originally Posted by zgintasz
View Post
I would use C++ too, leave that stupid pawn somewhere in a corner...
Last time I checked it still interfaces through PAWN.


Re: Choosing a programming language - overflow - 30.09.2013

Quote:
Originally Posted by playbox12
View Post
Last time I checked it still interfaces through PAWN.
Not necessarily.

---------------------------------------------------------------

I'd go with C++, too. (IMHO Pawn isn't even a real programming language; PHP is made for generating HTML; Java is ugly)


Re: Choosing a programming language - Deji - 01.10.2013

^ If I could yell at everyone that HTML should not be written and should not even be identifiable, what with all the ugly low-level PHP code surrounding it, I would be a very hated person. I might also improve web design globally, so perhaps I'll try it one day :0

Using C++ does not 'interface' through PAWN (not what I'm using, anyway), it runs as a plugin which can be called in exactly the same way, especially since the callee, the SA-MP server, is written in C++ itself (why would it go C++>PAWN>C++?) - the things that speak are all in machine language. PAWN is a coding language. That said, there is nothing wrong with PAWN ('cept for lack of all the things that make C++ amazing, ehem). The reason I chose not to even bother to learn it is because no IDE will ever be available which would have anywhere near the features that most C++ IDE's do. C++ IDE's provide better code management (partly due to C++'s design itself) and many other amazing things thanks to their preprocessors. That said, the only reason PAWN can't do those things, isn't because of PAWN, but the compilers used to build it. That said, PAWN isn't a real thing without the compilers to build it... I will post the moral of this parable at the end, since that's just where morals go, I guess...

C++ itself is just amazing as you can write so much and there be so little code. What I mean is, if you're like me, you barely ever even write code. Most of the type you are trying to figure out what to add to your object classes and custom types... Once you've done that, a little bit of code and you've implemented a fully stable and efficient feature. It's easy, when you know how...

If C++ was easy for anyone to learn, then it would probably be the only language in existance then it would probably somehow replace PAWN as the chosen language for SA-MP game mode scripting.


p.s. The moral of the story is that saying a programming language is good or bad is just like saying a spoken language is good or bad. Perhaps they don't have all the same words, but they can still string a meaningful sentence, in one way or another. Words may be flawed in theory, but can still be used practically. And which language fits best depends on the speaker, speakee or even the translator.

p.p.s. C++ needs a codename, because it stands out like a pimp on a beach...


Re: Choosing a programming language - Slice - 01.10.2013

I'm not sure why you're bashing every language except C++. They all serve different purposes.

Quote:

If I could yell at everyone that HTML should not be written and should not even be identifiable

What's wrong with HTML? What do you think websites should be written with? Some C++ JIT compiler in the web browser that uses 20 frameworks to write "hello world"?

Quote:

what with all the ugly low-level PHP code surrounding it

Not sure what you mean with low-level PHP code - PHP is anything but low-level!
It's also a much better fit for serving web pages than C++. Think about continuous integration, ease of maintenance, cross-compatibility, and - yes - the learning curve. Anyone can learn to start modifying bits of PHP scripts to fit their needs very quickly, the same can't be said for C++.

Quote:

PAWN isn't a real thing without the compilers to build it...

The same goes for every other language out there. If you don't want a compiler, make your programs on circuit boards.

Quote:

if you're like me, you barely ever even write code. Most of the type you are trying to figure out what to add to your object classes and custom types... Once you've done that, a little bit of code and you've implemented a fully stable and efficient feature. It's easy, when you know how...

Yes, and it all works silky smooth!
Then, in production, you have tons of memory leaks, way too high CPU usage, and other fun stuff. Why is that? Because you only learned C++ to script SA-MP servers, you didn't learn every aspect of C++. You just wanted to write some code!
What now? No clue! Where could the errors be? No clue! You didn't write the functions you used.

(I don't mean "you" being "Deji")


C++ is great for SA-MP servers if you're very familiar with it, yes, but Pawn is a much better choice for most people.


Re: Choosing a programming language - RajatPawar - 01.10.2013

There must have been a reason the developers picked PAWN for SA-MP. C++/Java/PHP and all have too much other stuff EXCEPT the stuff required for SA-MP, while PAWN - well basically if one learns PAWN for SA-MP, he is much likely to be better at it than trying to learn a huge language like C++ for just coding some game modes for SA-MP!
Basically, PAWN is easier!
Easier = less features than some other languages, but it atleast allows for 5000 scripters with unique ideas scripting unimaginable stuff than 200 who know the language.


Re: Choosing a programming language - Deji - 01.10.2013

Quote:
Originally Posted by Slice
View Post
I'm not sure why you're bashing every language except C++. They all serve different purposes.
I'm not, personally. This is a post about being positive about a particular programming language (which I must note means that PAWN isn't even relevant lol) however, I don't have to be positive about every language.

Quote:

What's wrong with HTML? What do you think websites should be written with? Some C++ JIT compiler in the web browser that uses 20 frameworks to write "hello world"?

Actually, the entire state of web design is a bit laughable. We got languages coming out of our asses because the tools to write web pages have been terribly outdated for years. Half the useful stuff is deprecated, with no alternatives. Of course, we finally have had HTML5 recently come out which is a step up, but to me, HTML is no more impressive than BB code. It provides little functionality in web pages and can only be used to make static content. Like PAWN, it suffers from needing to be easy to use for it's purpose. It suffers in optimisation (heavily), design, reliability and complete-ness. I've been web designing for ages. I use my own template system in PHP nowadays, of course.

Quote:

Not sure what you mean with low-level PHP code - PHP is anything but low-level!
It's also a much better fit for serving web pages than C++. Think about continuous integration, ease of maintenance, cross-compatibility, and - yes - the learning curve. Anyone can learn to start modifying bits of PHP scripts to fit their needs very quickly, the same can't be said for C++.

Exactly. Ease of maintenance, ease of accessibility.. these are all things that benefit the person who probably wants to make money off the suckers who visit the page he took 10 minutes to write. The page that is vulnerable to MySQL injections (many times I've got past logins by a simple MySQL injection - naughty me - but why should I enter my password where it won't be encrypted?), XSS, doesn't work on multiple browsers (cause HTML isn't even cross-compatible, in fact) and 70% of what the user waits for to load is useless text data about elements, images not optimised for web use, countless lines of inflated CSS (I don't minify my scripts because I'm certain the regex will screw somthing up lol - instead I write it minified) and JavaScript, which has to be the most nasty thing that has been invented for use in websites.

Mostly, I'm just ranting. There are ways to do it right, but it's hard to find someone who knows them, because the so called ease of the language makes them believe they know more than they do and proceed with using bad methods to do everything.

[quote]The same goes for every other language out there. If you don't want a compiler, make your programs on circuit boards.


Quote:

Yes, and it all works silky smooth!
Then, in production, you have tons of memory leaks, way too high CPU usage, and other fun stuff. Why is that? Because you only learned C++ to script SA-MP servers, you didn't learn every aspect of C++. You just wanted to write some code!
What now? No clue! Where could the errors be? No clue! You didn't write the functions you used.

(I don't mean "you" being "Deji")

You couldn't have , because C++ makes it easy to write code that is flawless, actually. If you plan your storage right (OOP is brilliant for SA-MP) you will never have a memory leak. Plus, the debuggers available makes it easy to fix any problem.. they basically tell you what to do. But I guess I find something easy now, that many others including myself in the past have found insanely difficult. But it's mind-blowing how little I have to do to make a feature as big as any filterscript posted in the forums that the author is really proud of, by instead of letting SA-MP give me a easy platform to code with, making my own better platform to code with.

The same can be said for PAWN, though... as you said for C++ and I said for PHP. People see that it's easy and don't bother to learn every aspect. And really, the amount of random things I've seen from PAWN makes me believe that it's really got a lot going on which most people aren't aware of. They don't know how it works, they don't know how SA-MP works, they don't even know how GTA works, which is upsetting. But hey, at least they know how to write a class system.

Quote:

C++ is great for SA-MP servers if you're very familiar with it, yes, but Pawn is a much better choice for most people.

But then again... it's only a choice if you've considered the alternatives. It may not be a better choice, it might just be an easier choice in the short-term. Depending on what you want to get done... But I find it very hard to argue with using C++ for large projects.


Just for fun, I brought some Playin' Awesome code as a demonstration of how easy C++ is, especially under the SAMPGDK environment which makes it have everything AMX does:
Code:
	// SAMP is a namespace which I used to define SAMP-specific stuff, such as the player base structure
	// Here, if nBestMatch isn't -1, we set the 'type' to an eVehicleType, else we can set it to the invalid vehicle type ID
	SAMP::eVehicleType type = nBestMatch != -1 ? (SAMP::eVehicleType)(nBestMatch + 400) : SAMP::MAX_VEHICLE_TYPE;
	
	// 'type' should now contain the vehicle model found to match the search string
	if(type >= SAMP::VT_FIRST_TYPE && type < SAMP::MAX_VEHICLE_TYPE)
	{
		int i = nBestMatch;

		// Get the player coordinates
		float x, y, z;
		pPlayer->GetPos(x, y, z);

		// Create the vehicle there and at the players current angle
		auto pVehicle = new CVehicle(type, x, y, z, pPlayer->GetHeading());

		// IMPORTANT: Always confirm vehicles exist after creating them by checking if they're not "wrecked" (dead)
		if(pVehicle->IsAlive())
		{
			// Plop that player in the driverseat
			pVehicle->AddDriver(pPlayer);

			// E.G. "Spawned NRG-500"
			std::string msg = "Spawned " + std::string(g_szVehicleNames[nBestMatch]);
			pPlayer->SendMessage(msg.c_str(), GetColour(COLOUR_SUCCESS));

			// Add to the debug vehicles list so we can save memory by deleting them when we're not debugging
			g_DebugVehicles.push_back(pVehicle);
		}
		else
		{
			// Send the player a client message and delete the vehicle
			pPlayer->SendMessage("Vehicle limit reached", GetColour(COLOUR_ERROR));
			delete pVehicle;
		}
	}
I can have more code inline, more automatic things going on (for example, when I delete pVehicle, some other action can be happening in the destructor to ensure that all deleted vehicles go through a certain process) and besides from the STL, everything's childishly simple. Again, there's a case of there being an easier option (C-style strings) and it not necessarily being the best way to do things. Still, I wrote a system which spawns cars depending on text searches and it only took ~63 lines. Once I move the amazing search score analyser code to it's separate function, it will be only ~46 lines of code.

It's stuff that could probably be done in PAWN (using really hacky methods) but wouldn't be most of the time, because in order to do something that efficient even in PAWN, you'd have to know the C++ that it's based off.


Re: Choosing a programming language - Deji - 01.10.2013

Quote:
Originally Posted by Rajat_Pawar
View Post
There must have been a reason the developers picked PAWN for SA-MP. C++/Java/PHP and all have too much other stuff EXCEPT the stuff required for SA-MP, while PAWN - well basically if one learns PAWN for SA-MP, he is much likely to be better at it than trying to learn a huge language like C++ for just coding some game modes for SA-MP!
Basically, PAWN is easier!
Easier = less features than some other languages, but it atleast allows for 5000 scripters with unique ideas scripting unimaginable stuff than 200 who know the language.
*sigh* I am sad to say that there is nothing in the 'filterscript' department I've seen that I would deem as 'unimaginable' in any good sense of the word. It's all actually very predictable, if you ask me. This is coming from someone who mods GTA directly, unrestricted by SA-MP. I still even think SA-MP is lacking in some proper attention. I could replace the moon with a working television, if it so pleases me. I honestly am that ambitious. In fact, I have already managed to move the TV screens in 8-track to Grove Street (or anywhere I choose), which was a pretty big deal at the time...