Indention Consistency
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.
I use four spaces for indentation, mainly because that's what I'd use when programming with other languages, and I indent both keys and tags. Tabs could be more elegant, but with them it would be more difficult to solve some situations where I like to indent oddly for sake of readability or editability.
If I, for example, have a macro that moves a unit along a path given with a list of x and y coordinates (like [move_unit_fake]), I'd probably write it like this:
Perhaps a bad example, but the point might still be visible. But then again, I have developed some other odd habits as well, especially with macros, one being my dear IF macro (tests for a value of a variable) which I write like this:
I also use a lot of empty lines, which I think are very important for readability, but which are used rather sparingly at least in the mainline campaigns.
When writing my own campaign, which no-one else will be writing, I'll use whatever pleases my eye the most or is the most convenient or clear way for me. I like my WML pretty.
If I, for example, have a macro that moves a unit along a path given with a list of x and y coordinates (like [move_unit_fake]), I'd probably write it like this:
Code: Select all
{MOVE_UNIT description=XYZ ( 5, 6, 6, 7)
(22,22,21,20)}
Code: Select all
{IF variable equals value (
[then]
...
[/then]
[else]
...
[/else]
)}
When writing my own campaign, which no-one else will be writing, I'll use whatever pleases my eye the most or is the most convenient or clear way for me. I like my WML pretty.
I write long function calls in C++ similiar to how you do it, but I use tabs only for the indentation part, and spaces to justify the positions of the arguments. An example with '=' being a tab, and '-' being a space:zookeeper wrote:I use four spaces for indentation, mainly because that's what I'd use when programming with other languages, and I indent both keys and tags. Tabs could be more elegant, but with them it would be more difficult to solve some situations where I like to indent oddly for sake of readability or editability.
If I, for example, have a macro that moves a unit along a path given with a list of x and y coordinates (like [move_unit_fake]), I'd probably write it like this:
Code: Select all
{MOVE_UNIT description=XYZ ( 5, 6, 6, 7) (22,22,21,20)}
Code: Select all
void somefunction()
{
=
=if(condition) {
==some_very_long_function_call(arg1,arg2,arg3,
==-----------------------------arg4,arg5,arg6);
=}
}
David
“At Gambling, the deadly sin is to mistake bad play for bad luck.” -- Ian Fleming
Agreed. Guess I didn't really come to think of indentation and lining things up being a different thing.I think this makes the most logical sense -- tabs are entirely for showing how deeply nested something is; spaces can be used to line things up right.
EDIT: There would still be a (minor) problem if someone has his editor set to display tabs X spaces wide while the WML was originally written according to a tab width of Y spaces. A minor inconvenience, but still.
I prefer spaces for indentation - tabs often cause more trouble than they are worth.Dave wrote:- uses tabs for indentation
E.G. they often cause extra work, e.g. when moving a block of code to somewhere else...
This means, indent after every starting tag ?- indents attributes one tab from the containing element
- indents child elements one tab from the containing element
Why quote numeric values ?- always puts double-quotes around attribute values
-HaJo
I made an awk-script that can indent selected tags in a WML-file,turin wrote:Dacyn has written a basic program (C++) to indent it according to a standard
leave some special cases untouched (#ifdef, multiline-strings...),
and can be customized easily (i.e. tags to indent, string for indentation).
It works, but is not fully tested yet (i.e. with cfg-files from other campaigns).
If there is interest, I can post it here.
-HaJo
Spaces cause more trouble than tabs do, in my experience.HaJo wrote:I prefer spaces for indentation - tabs often cause more trouble than they are worth.Dave wrote:- uses tabs for indentation
E.G. they often cause extra work, e.g. when moving a block of code to somewhere else...
Yes.HaJo wrote:This means, indent after every starting tag ?- indents attributes one tab from the containing element
- indents child elements one tab from the containing element
Well, one reason is the engine may start requiring this in the future.HaJo wrote:Why quote numeric values ?- always puts double-quotes around attribute values
For I am Turin Turambar - Master of Doom, by doom mastered. On permanent Wesbreak. Will not respond to private messages. Sorry!
And I hate stupid people.
The World of Orbivm
And I hate stupid people.
The World of Orbivm
No there wouldn't be a problem. That's one of the most important reasons for using my prescribed scheme: there is no problem in such situations.zookeeper wrote:Agreed. Guess I didn't really come to think of indentation and lining things up being a different thing.I think this makes the most logical sense -- tabs are entirely for showing how deeply nested something is; spaces can be used to line things up right.
EDIT: There would still be a (minor) problem if someone has his editor set to display tabs X spaces wide while the WML was originally written according to a tab width of Y spaces. A minor inconvenience, but still.
“At Gambling, the deadly sin is to mistake bad play for bad luck.” -- Ian Fleming
Spaces cause just as much trouble in such a situation.HaJo wrote:I prefer spaces for indentation - tabs often cause more trouble than they are worth.Dave wrote:- uses tabs for indentation
E.G. they often cause extra work, e.g. when moving a block of code to somewhere else...
Yes.HaJo wrote:This means, indent after every starting tag ?- indents attributes one tab from the containing element
- indents child elements one tab from the containing element
There is no reason to quote numeric values if you're writing WML. I was just describing what the Wesnoth engine does.HaJo wrote:Why quote numeric values ?- always puts double-quotes around attribute values
David
“At Gambling, the deadly sin is to mistake bad play for bad luck.” -- Ian Fleming
Oops. This is perfectly true, I don't know what I was thinking (not much, it seems).Dave wrote:No there wouldn't be a problem. That's one of the most important reasons for using my prescribed scheme: there is no problem in such situations.zookeeper wrote: Agreed. Guess I didn't really come to think of indentation and lining things up being a different thing.
EDIT: There would still be a (minor) problem if someone has his editor set to display tabs X spaces wide while the WML was originally written according to a tab width of Y spaces. A minor inconvenience, but still.