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

Started by blinkok, May 16, 2019, 01:29:40

Previous topic - Next topic

blinkok

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

Xerra

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.
M2 Pro Mac mini - 16GB 512 SSD
ACER Nitro 5 15.6" Gaming Laptop - Intel® Core™ i7, RTX 3050, 1 TB SSD
Vic 20 - 3.5k 1mhz 6502

Latest game - https://xerra.itch.io/Gridrunner
Blog: http://xerra.co.uk
Itch.IO: https://xerra.itch.io/

Matty

This website...post 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.

therevills

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

I agree with everything Matty has stated, barring:

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

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.
Win11 64Gb 12th Gen Intel i9 12900K 3.2Ghz Nvidia RTX 3070Ti 8Gb
Win11 16Gb 12th Gen Intel i5 12450H 2Ghz Nvidia RTX 2050 8Gb
Win11  Pro 8Gb Celeron Intel UHD Graphics 600
Win10/Linux Mint 16Gb 4th Gen Intel i5 4570 3.2GHz, Nvidia GeForce GTX 1050 2Gb
macOS 32Gb Apple M2Max
pi5 8Gb
Spectrum Next 2Mb

iWasAdam

Everything Matty and others have said - nice and concise :)

Types are your friend they will teach you to think in 'clumps' of data.

Not been said but NEVER use goto, think about using gosub or proc/functions