Indention Consistency

The place to post your WML questions and answers.

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.
User avatar
zookeeper
WML Wizard
Posts: 9742
Joined: September 11th, 2004, 10:40 pm
Location: Finland

Post by zookeeper »

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)}
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:

Code: Select all

{IF variable equals value (
    [then]
        ...
    [/then]

    [else]
        ...
    [/else]
)}
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.
Dave
Founding Developer
Posts: 7071
Joined: August 17th, 2003, 5:07 am
Location: Seattle
Contact:

Post by Dave »

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)}
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:

Code: Select all

void somefunction()
{
=
=if(condition) {
==some_very_long_function_call(arg1,arg2,arg3,
==-----------------------------arg4,arg5,arg6);
=}
}
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.

David
“At Gambling, the deadly sin is to mistake bad play for bad luck.” -- Ian Fleming
User avatar
zookeeper
WML Wizard
Posts: 9742
Joined: September 11th, 2004, 10:40 pm
Location: Finland

Post by zookeeper »

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.
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.
HaJo
Inactive Developer
Posts: 174
Joined: August 7th, 2005, 11:52 pm
Location: DE

Post by HaJo »

Dave wrote:- uses tabs for indentation
I prefer spaces for indentation - tabs often cause more trouble than they are worth.
E.G. they often cause extra work, e.g. when moving a block of code to somewhere else...
- indents attributes one tab from the containing element
- indents child elements one tab from the containing element
This means, indent after every starting tag ?
- always puts double-quotes around attribute values
Why quote numeric values ?
-HaJo
HaJo
Inactive Developer
Posts: 174
Joined: August 7th, 2005, 11:52 pm
Location: DE

Post by HaJo »

turin wrote:Dacyn has written a basic program (C++) to indent it according to a standard
I made an awk-script that can indent selected tags in a WML-file,
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
User avatar
turin
Lord of the East
Posts: 11662
Joined: January 11th, 2004, 7:17 pm
Location: Texas
Contact:

Post by turin »

HaJo wrote:
Dave wrote:- uses tabs for indentation
I prefer spaces for indentation - tabs often cause more trouble than they are worth.
E.G. they often cause extra work, e.g. when moving a block of code to somewhere else...
Spaces cause more trouble than tabs do, in my experience.
HaJo wrote:
- indents attributes one tab from the containing element
- indents child elements one tab from the containing element
This means, indent after every starting tag ?
Yes.
HaJo wrote:
- always puts double-quotes around attribute values
Why quote numeric values ?
Well, one reason is the engine may start requiring this in the future.
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
Dave
Founding Developer
Posts: 7071
Joined: August 17th, 2003, 5:07 am
Location: Seattle
Contact:

Post by Dave »

zookeeper wrote:
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.
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.
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.
“At Gambling, the deadly sin is to mistake bad play for bad luck.” -- Ian Fleming
Dave
Founding Developer
Posts: 7071
Joined: August 17th, 2003, 5:07 am
Location: Seattle
Contact:

Post by Dave »

HaJo wrote:
Dave wrote:- uses tabs for indentation
I prefer spaces for indentation - tabs often cause more trouble than they are worth.
E.G. they often cause extra work, e.g. when moving a block of code to somewhere else...
Spaces cause just as much trouble in such a situation.
HaJo wrote:
- indents attributes one tab from the containing element
- indents child elements one tab from the containing element
This means, indent after every starting tag ?
Yes.
HaJo wrote:
- always puts double-quotes around attribute values
Why quote numeric values ?
There is no reason to quote numeric values if you're writing WML. I was just describing what the Wesnoth engine does.

David
“At Gambling, the deadly sin is to mistake bad play for bad luck.” -- Ian Fleming
User avatar
zookeeper
WML Wizard
Posts: 9742
Joined: September 11th, 2004, 10:40 pm
Location: Finland

Post by zookeeper »

Dave wrote:
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.
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.
Oops. This is perfectly true, I don't know what I was thinking (not much, it seems).
Post Reply