Coding Conventions
Moderator: Forum Moderators
Forum rules
- Please use [code] BBCode tags in your posts for embedding WML snippets.
- To keep your code readable so that others can easily help you, make sure to indent it following our conventions.
Coding Conventions
I like to know every irregularity in the WML api,
namely violations to the Coding Conventions.
Things like canrecruit= which should be can_recruit= or [advancefrom] which should be [advance_from]
A second category are attributes which don't match the content or type of the value.
attack.name is not a translatable name but the id used for filtering animations.
While attack.description is not a description but a single translatable name.
So I think it should be:
So far I know about:
movetype.name should be 'id'
canrecruit
[advancefrom]
team_name -> not translatable, should be 'team_id' ?
user_team_name
'name' in the event tag -> not translatable should it be event 'type' or 'id'?
moveto -> move_to
prestart -> pre_start
prerecall -> pre_recall (and similar) ..
Please help with "and similar", I am not a native English speaker and thus not sure which words are valid.
[allow_extra_recruit] extra_recruit= -> allow_extra_recruit.type
the attack id/name/description issue
Please tell me when you discover more of those and help me make the list complete.
Thank you
namely violations to the Coding Conventions.
Things like canrecruit= which should be can_recruit= or [advancefrom] which should be [advance_from]
A second category are attributes which don't match the content or type of the value.
Code: Select all
[attack]
name="bow"
description= _ "bow"
...
[/attack]
While attack.description is not a description but a single translatable name.
So I think it should be:
Code: Select all
[attack]
id="bow"
name= _ "Fine Bow"
description= _ "Bows are far better than axes."
[/attack]
movetype.name should be 'id'
canrecruit
[advancefrom]
team_name -> not translatable, should be 'team_id' ?
user_team_name
'name' in the event tag -> not translatable should it be event 'type' or 'id'?
moveto -> move_to
prestart -> pre_start
prerecall -> pre_recall (and similar) ..
Please help with "and similar", I am not a native English speaker and thus not sure which words are valid.
[allow_extra_recruit] extra_recruit= -> allow_extra_recruit.type
the attack id/name/description issue
Please tell me when you discover more of those and help me make the list complete.
Thank you
"Wesnoth has many strong points but team and users management are certainly not in them." -- pyrophorus
- skeptical_troll
- Posts: 500
- Joined: August 31st, 2015, 11:06 pm
Re: Coding Conventions
A few I can think of (if I understand what you mean):
team_name -> not translatable, should be 'team_id' ?
'name' in the event tag -> not translatable should it be event 'type' or 'id'?
moveto -> move_to ?
prestart -> pre_start ?
prerecall -> pre_recall (and similar) ..
Something I also find confusing is that [allow_recruit] uses 'type' to specify the new units and [allow_extra_recruit] has 'extra_recruit'
team_name -> not translatable, should be 'team_id' ?
'name' in the event tag -> not translatable should it be event 'type' or 'id'?
moveto -> move_to ?
prestart -> pre_start ?
prerecall -> pre_recall (and similar) ..
Something I also find confusing is that [allow_recruit] uses 'type' to specify the new units and [allow_extra_recruit] has 'extra_recruit'
Re: Coding Conventions
Yeah, all good catches.skeptical_troll wrote:A few I can think of (if I understand what you mean):
team_name -> not translatable, should be 'team_id' ?
'name' in the event tag -> not translatable should it be event 'type' or 'id'?
moveto -> move_to ?
prestart -> pre_start ?
prerecall -> pre_recall (and similar) ..
Something I also find confusing is that [allow_recruit] uses 'type' to specify the new units and [allow_extra_recruit] has 'extra_recruit'
Thank you very much.
"Wesnoth has many strong points but team and users management are certainly not in them." -- pyrophorus
Re: Coding Conventions
I find it quite irregular how some tags want [filter] and some only want its content.
Re: Coding Conventions
Okay, let's fix that by just allowing filter everywhere (edit: everywhere a SUF is expected).Ravana wrote:I find it quite irregular how some tags want [filter] and some only want its content.
This is also backwards compatible.
(And I need to do that anyway for different reasons)
"Wesnoth has many strong points but team and users management are certainly not in them." -- pyrophorus
- beetlenaut
- Developer
- Posts: 2825
- Joined: December 8th, 2007, 3:21 am
- Location: Washington State
- Contact:
Re: Coding Conventions
Actually, this is wrong. "Pre" is not a word, so it would never be used with a space before the word it modifies. That makes an underscore inappropriate too. Out of prestart, prerecall, and prerecrut, only prestart appears in the dictionary. When we invent our own words by attaching "pre" to other words, we usually use a hyphen, but it's not strictly necessary. It wouldn't help make WML more consistent either, so we should just keep "prerecall" and "prerecruit" as they are, along with anything else that starts with "pre".skeptical_troll wrote:prestart -> pre_start ?
prerecall -> pre_recall (and similar) ..
I vote for "type" in event. It makes the most sense. Ravana's suggestion is good too. That inconsistency has bothered me for a long time.
Campaigns: Dead Water,
The Founding of Borstep,
Secrets of the Ancients,
and WML Guide
The Founding of Borstep,
Secrets of the Ancients,
and WML Guide
- skeptical_troll
- Posts: 500
- Joined: August 31st, 2015, 11:06 pm
Re: Coding Conventions
Ops, my fault. I wasn't actually totally sure, because prestart and 'pre advance' (as well as 'post advance') are treated in different ways, and both should be written with an hyphen. I guess then the latter should change?beetlenaut wrote:Actually, this is wrong. "Pre" is not a word
Another thing I find confusing is the [terrain] tag, when you want to filter for the old terrain. Wouldn't be easier to use the keyword 'new_terrain' instead of 'terrain' to specify the new type and 'terrain' for the one to be filtered as in the SLF? At the moment it is a bit counter-intuitive how it works. Just a suggestion..
another one: [endlevel] -> [end_level] ?
Re: Coding Conventions
We also have the "pre_advance" event, the reason why the underscroe was added is becasue the "post_advance" event had that too.Actually, this is wrong. "Pre" is not a word, so it would never be used with a space before the word it modifies. That makes an underscore inappropriate too. Out of prestart, prerecall, and prerecrut, only prestart appears in the dictionary. When we invent our own words by attaching "pre" to other words, we usually use a hyphen, but it's not strictly necessary. It wouldn't help make WML more consistent either, so we should just keep "prerecall" and "prerecruit" as they are, along with anything else that starts with "pre".
I vote for "type" in event. It makes the most sense. Ravana's suggestion is good too. That inconsistency has bothered me for a long time.
Scenario with Robots SP scenario (1.11/1.12), allows you to build your units with components, PYR No preperation turn 1.12 mp-mod that allows you to select your units immideately after the game begins.
- beetlenaut
- Developer
- Posts: 2825
- Joined: December 8th, 2007, 3:21 am
- Location: Washington State
- Contact:
Re: Coding Conventions
The "post" prefix doesn't use a space either. I'm sure the reason someone added an underscore is that they felt that something should go there since they were inventing a word, but it should be a hyphen if anything.
Campaigns: Dead Water,
The Founding of Borstep,
Secrets of the Ancients,
and WML Guide
The Founding of Borstep,
Secrets of the Ancients,
and WML Guide
Re: Coding Conventions
Okay, so event names or better types are a special case.
I have reasons to capitalize them.
Start
TimeOver
Turn1
Side2Turn3
And so on.
I am also going to call them
PreStart
PreRecruit
PostAdvance
and so on. Using CamelCase and capitalizing the part after "Pre" or "Post" feels fine.
I have reasons to capitalize them.
Start
TimeOver
Turn1
Side2Turn3
And so on.
I am also going to call them
PreStart
PreRecruit
PostAdvance
and so on. Using CamelCase and capitalizing the part after "Pre" or "Post" feels fine.
"Wesnoth has many strong points but team and users management are certainly not in them." -- pyrophorus
Re: Coding Conventions
What about "movetype"?
movetype.name is also used as id.
movetype.name is also used as id.
"Wesnoth has many strong points but team and users management are certainly not in them." -- pyrophorus
- Celtic_Minstrel
- Developer
- Posts: 2207
- Joined: August 3rd, 2012, 11:26 pm
- Location: Canada
- Contact:
Re: Coding Conventions
I feel it necessary to point out here that 'id' already has a meaning in [event], so changing 'name' to 'id' is absolutely out of the question.skeptical_troll wrote: 'name' in the event tag -> not translatable should it be event 'type' or 'id'?
There are some inconsistencies in format as well as naming - for example, colours are specified in several slightly different ways depending on which tag they appear in.
Re: Coding Conventions
How do you determine what feels fine?fabi wrote:Using CamelCase and capitalizing the part after "Pre" or "Post" feels fine.
BfW 1.12 supported, but active development only for BfW 1.13/1.14: Bad Moon Rising | Trinity | Archaic Era |
| Abandoned: Tales of the Setting Sun
GitHub link for these projects
| Abandoned: Tales of the Setting Sun
GitHub link for these projects
Re: Coding Conventions
That is not exactly a precise question, so let me elaborate a little bit more.doofus-01 wrote:How do you determine what feels fine?fabi wrote:Using CamelCase and capitalizing the part after "Pre" or "Post" feels fine.
I guess most people would answer that determining what feels fine means hearing about some noise in your guts.
In the case of the event "name" (or maybe "type") I have to share some more thoughts.
All of scenario coding is now done below some [event] tags.
I introduce additional syntactic sugar by just taking every capitalized table key as the "name" of an event handler.
All code snippets are equivalent:
Code: Select all
[scenario]
[event]
name="prestart"
[unit]
type="Elvish Fighter"
id="Kalenz"
[/unit]
[/event]
[/scenario]
-----------------------------------------------------
scenario
event:
type: "PreStart"
command: ->
unit
type: "Elvish Fighter"
id: "Kalenz"
------------------------------------------
scenario
PreStart: ->
unit
type: "Elvish Fighter"
id: "Kalenz"
Also, whitespace needs to be escaped in Lua table key identifiers.
So all whitespace and underline go in favor of CamelCase.
The last gut thing is that having one "PreSomething" means "PreAnother" is also a good idea.
"Wesnoth has many strong points but team and users management are certainly not in them." -- pyrophorus
- Celtic_Minstrel
- Developer
- Posts: 2207
- Joined: August 3rd, 2012, 11:26 pm
- Location: Canada
- Contact:
Re: Coding Conventions
Underscores are perfectly valid in Lua table key identifiers.