07-25-2012, 09:18 AM
The PreCompiler is under more active development again... and now that im rewriting parts of the gamemode it would be a good time for each of you devs to learn how to write code with them.
Pick an isolated feature (such as the pirate ship or the tax system) and re-write it. Revision 2274 shows you roughly how to start.
The steps for writing a feature are:
1. Write up a short document about what it is, should do, and some rough ideas you have (example).
2. Write up a diagram about the code structure on LucidChart. Ask in #LVP.dev for our account.
3. Write the code.
After you've done this once or twice, you can probably skip steps 1 and 2. Initially, however, it's important that you understand the principles.
Some important things to keep in mind:
1. Long names are good. The LVP PreCompiler adjusts the Pawn compiler to allow function names of more than 32 characters. Utilize it. "CashPointController::sendMessageToPlayersWithinRangeToCashPoint" is much clearer than "checkRange". Why? Because you don't need to read the code in order to know what it does.
2. Thinking about your feature is good. Everyone can just start typing some code, but the interesting thing about programming is writing your code as efficient as possible. What are possible future additions, and what would they mean on architecture?
3. Encapsulation and isolation are good. Pretty much every feature should be able to be written in one source-file, and require little to no modifications to other files. Strongly utilize invocation lists (@list) and switches (@switch) to achieve this. The file "Features/Account/EnterPasswordDialog.pwn" shows a completely self-contained dialog, with no external code at all.
4. Ask. There's plenty of smart people around. Ask.
Start trying... Let me know when you committed something and I will review it. The idea there is that I'll add a lot of @review annotations in the code, which you then can pick up.
Once you learn to write code using classes you'll never want to go back again
Pick an isolated feature (such as the pirate ship or the tax system) and re-write it. Revision 2274 shows you roughly how to start.
The steps for writing a feature are:
1. Write up a short document about what it is, should do, and some rough ideas you have (example).
2. Write up a diagram about the code structure on LucidChart. Ask in #LVP.dev for our account.
3. Write the code.
After you've done this once or twice, you can probably skip steps 1 and 2. Initially, however, it's important that you understand the principles.
Some important things to keep in mind:
1. Long names are good. The LVP PreCompiler adjusts the Pawn compiler to allow function names of more than 32 characters. Utilize it. "CashPointController::sendMessageToPlayersWithinRangeToCashPoint" is much clearer than "checkRange". Why? Because you don't need to read the code in order to know what it does.
2. Thinking about your feature is good. Everyone can just start typing some code, but the interesting thing about programming is writing your code as efficient as possible. What are possible future additions, and what would they mean on architecture?
3. Encapsulation and isolation are good. Pretty much every feature should be able to be written in one source-file, and require little to no modifications to other files. Strongly utilize invocation lists (@list) and switches (@switch) to achieve this. The file "Features/Account/EnterPasswordDialog.pwn" shows a completely self-contained dialog, with no external code at all.
4. Ask. There's plenty of smart people around. Ask.
Start trying... Let me know when you committed something and I will review it. The idea there is that I'll add a lot of @review annotations in the code, which you then can pick up.
Once you learn to write code using classes you'll never want to go back again