Languages & Coding > AGK

Tips (maybe a website or book) for maintaining manageable code

(1/2) > >>

My code is a mess. Are there any websites, books or tips (In that order) for writing manageable code in a non OO environment? Specifically AGK

You're using AGK so there's no need to recommend some kind of format that most people would be using if you were looking for employment for that. Coding style is different for everyone but I've always tried to ensure that everything always looks tidy and lines are written in a consistent way, even if the what the code does could be done in a much smaller block.

Having a bit of OCD helps with that.

When I first moved from tinkering with Blitz I worked with a friend coding a couple of games and a few prototypes using Swift and, because he'd come from an occupation coding for application software for a company, I switched to layout code like he did so it was easier for both of us to understand what each of us was doing.

Have a look at some other source code written by people who have used AGK for a while and have a style format that's readable and you feel you could stick to and follow their example.

And stick to it. The benefits will pay for themselves when you read the code again a few months later and it still makes sense to you. I always feel it's better to have a few more lines and comments in a bit of code if it makes it understandable as a compiled version doesn't throw all that extra stuff into it anyway. A few extra seconds being neat at the start can save you hours of head scratching at a later date.

This your code often enough and someone like Derron or another will tell you things like (which are all good to be told) -

Indent your code
Keep tab spaces consistent
Use a defined convention for variable names, function names, and so on.
Be consistent with lower case and uppercase however you choose to use them.
Pick a convention that is in line with what you use in your employment, or if not working as a coder then at least that is somewhat close to a defined known convention.
If you use includes then prefix all functions, methods, variables specific to the include with the name of the include - or similar.

If you repeat a few lines of code with minor variations a number of times then consider replacing with a method/function/procedure.
If you open a file - always remember to close it.
If you load a resource, always remember to free it - unless the system does so for you.
When it comes to game programming:
If performance matters (sometimes it doesn't) then don't create/destroy object inside the main loop - keep them in a pool and recycle.

That's my two cents.


--- Quote from: Matty on May 16, 2019, 09:40:54 AM ---That's my two cents.

--- End quote ---

I agree with everything Matty has stated, barring:

--- Quote ---If you use includes then prefix all functions, methods, variables specific to the include with the name of the include - or similar.
--- End quote ---

I've never liked that as I think it adds too much and with a decent IDE it is unneeded, but I can see why some coders do it.

Steve Elliott:
I agree with everything that therevills said.   ;D

Some great advice from Matty.

Just one to thing to add, are you using Types?  Using Types and putting code in neat little functions really helps organize code.


[0] Message Index

[#] Next page

Go to full version