Programming style in ZDoom

Archive of the old editing forum
Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. This forum is archived - please use this set of forums to ask new questions.
Locked
User avatar
Nash
 
 
Posts: 17501
Joined: Mon Oct 27, 2003 12:07 am
Location: Kuala Lumpur, Malaysia
Contact:

Programming style in ZDoom

Post by Nash »

I'm OCD like that, I was wondering what is the "accepted standard" as far as letter casing (and stuff like that) goes in everything in ZDoom.

From what I can gather from looking at stuff in zdoom.pk3 (let's use DECORATE as an example)...

Code: Select all

// A DECORATE actor.

ACTOR ActorName
{
    PropertyName 123 
    Another.Property 456
    StringProperty "A string."
    +FLAGNAME
    States
    {
        Spawn:
            ROFL A 1 
            Loop
    }
}
 
  • Separate words in properties are always letter-cased.
    If a property expects a string, it should be enclosed in quotation marks, eventhough the parser doesn't complain without them.
    Flag names are always in uppercase.
    Sprite names are always in uppercase.
    Flow instructions are properly punctuated (GoTo instead of goto, Loop instead of loop, etc).
    Use tab for identation, with a tab size of 4 characters.
    Everytime a curly bracket is found, the next line is idented.
    For DECORATE, properties on top; flags at the bottom.
    I don't sort properties or flags by any rule... I used to want to sort them alphabetically, but I think that's just too much.
For everything that uses this format (MAPINFO, MODELDEF, TEXTURES, DECALDEF, etc), I will follow this convention.

And I'm not talking about ZDoom's source, because that is a gargantuan mess and attempting to enforce programming style on that is just wasting time. :P

Any thoughts?
Last edited by Nash on Sun Feb 19, 2012 11:21 am, edited 1 time in total.
Gez
 
 
Posts: 17946
Joined: Fri Jul 06, 2007 3:22 pm

Re: Programming style in ZDoom

Post by Gez »

Goto rather than GoTo or goto or goTo.
User avatar
Nash
 
 
Posts: 17501
Joined: Mon Oct 27, 2003 12:07 am
Location: Kuala Lumpur, Malaysia
Contact:

Re: Programming style in ZDoom

Post by Nash »

Really? I was trying to obey the "separate words being letter-cased" rule...

EDIT: Also, IMO, ACTOR shouldn't be capitalized and should just be Actor... but that's just me...

EDIT 2: Added some additional rules that I forgot to the first post.
User avatar
printz
Posts: 2649
Joined: Thu Oct 26, 2006 12:08 pm
Location: Bucharest, Romania
Contact:

Re: Programming style in ZDoom

Post by printz »

Personally, I type everything that's not case-sensitive in lower case. Some ports require the sprites and frame characters to be upper-case.
Gez
 
 
Posts: 17946
Joined: Fri Jul 06, 2007 3:22 pm

Re: Programming style in ZDoom

Post by Gez »

printz wrote:Personally, I type everything that's not case-sensitive in lower case.
Yes but it has already been established you deliberately choose the worst practices whenever you can get away with them. :P
User avatar
Ghastly
... in rememberance ...
Posts: 6109
Joined: Fri Jul 06, 2007 2:34 pm

Re: Programming style in ZDoom

Post by Ghastly »

I thought it was somewhat culturally established in ZDoom that writing style doesn't really matter in Decorate ("real" programming languages aside), as long as it's easy to read. I've never seen anyone use real-language conventions in Decorate.
User avatar
Nash
 
 
Posts: 17501
Joined: Mon Oct 27, 2003 12:07 am
Location: Kuala Lumpur, Malaysia
Contact:

Re: Programming style in ZDoom

Post by Nash »

For functions... should there be a space before a bracket?

Code: Select all

function void HUDMessageOnActor(int tid, int hudWidth, int hudHeight, str image, int hudMsgID, int offset)
{

...

    SetHUDSize(hudWidth, hudHeight, true);
... or...

Code: Select all

function void HUDMessageOnActor (int tid, int hudWidth, int hudHeight, str image, int hudMsgID, int offset)
{

...

    SetHUDSize (hudWidth, hudHeight, true);
I realize this isn't really related to ZDoom anymore but programming style in general.

EDIT: what do you think about letter casing for variables? IMO they should be all lowercase... the above piece of code was just copy/pasted from a time where I just didn't seem to have a coherent rule when it comes to letter casing... :P
User avatar
scalliano
Posts: 2867
Joined: Tue Jun 21, 2005 1:16 pm
Location: Ireland

Re: Programming style in ZDoom

Post by scalliano »

I format everything pretty much as Nash demonstrated. It just makes stuff easier to pick out.
User avatar
Nash
 
 
Posts: 17501
Joined: Mon Oct 27, 2003 12:07 am
Location: Kuala Lumpur, Malaysia
Contact:

Re: Programming style in ZDoom

Post by Nash »

A nicely formatted code gives it that "polished" vibe, when I read code like this, it makes me think... "the person who wrote it is an organized person who does things the right way". XD

Also: OCD
User avatar
NeuralStunner
 
 
Posts: 12328
Joined: Tue Jul 21, 2009 12:04 pm
Preferred Pronouns: No Preference
Operating System Version (Optional): Windows 11
Graphics Processor: nVidia with Vulkan support
Location: capital N, capital S, no space
Contact:

Re: Programming style in ZDoom

Post by NeuralStunner »

Code: Select all

a_bUGnASH
:P
User avatar
Phobus
Posts: 5984
Joined: Thu May 05, 2005 10:56 am
Location: London
Contact:

Re: Programming style in ZDoom

Post by Phobus »

I'm quite inconsistent with my ACS, as I've been getting more experience with programming in the background between Doom projects. DECORATE and other text lumps are things I tend to write in step with the wiki example I'm working from.
User avatar
Isle
Posts: 687
Joined: Fri Nov 21, 2003 1:30 am
Location: Arizona, USA

Re: Programming style in ZDoom

Post by Isle »

Nash wrote:For functions... should there be a space before a bracket?
no

i never capitalize anything except for putting constants in all caps.
the only real style i stick with is getting nesting straight.
User avatar
Apothem
Posts: 2070
Joined: Sat Nov 29, 2003 7:13 pm
Location: Performing open heart surgery on an ACS compiler.

Re: Programming style in ZDoom

Post by Apothem »

Biggest piece of advice I can give you about coding in ACS as far as form goes is:
Indent, comment, and use LOTS OF DEFINES.

Up until named scripts showed up, the only way you COULD name scripts was with #defines. However, the idea would be to remove as many 'magic numbers' as you can. Magic numbers being just plain old numbers put somewhere to define a limit or base number of some kind.

Also, because of the nature of ACS and how messy it CAN get, commenting your code can make the difference between finding that bug, and getting lost for hours.

Beyond that, legibility is incredibly important. If you're really worried about your coding style, I'd suggest looking at a lot of properly formatted C/C++ code. ACS's mechanics fall about into the same style (plus or minus some details).

I wish I could think of more, but just off the top of my head that's what I can come up with. This was something of which I had to take some serious time to learn because I had HORRIBLE habits before hand. Think of it this way, I used to basically write everything like it was on one line, and I never used defines or indentation. My code looked and ran awful. So if anything, the better you can keep your code clean and comment the shit out of it, the faster and more easily you can get it done :)
User avatar
Wills
Posts: 1446
Joined: Mon Jan 10, 2005 7:01 pm
Location: The Well of Wishes

Re: Programming style in ZDoom

Post by Wills »

I think I made a map once where the entire ACS script was on one line
Anyway I wish I had the mental fortitude to do this for all my levels
User avatar
printz
Posts: 2649
Joined: Thu Oct 26, 2006 12:08 pm
Location: Bucharest, Romania
Contact:

Re: Programming style in ZDoom

Post by printz »

I Dislike Title Caps. They look silly and make reading difficult. It causes one to mentally emphasize every word. So I choose to make things lower case, which is both easier to type and to read (it flows quickly in one's mind).
Locked

Return to “Editing (Archive)”