Version 3 of Square bracket indentation style

Updated 2014-07-24 11:32:34 by dbohdan

dbohdan 2014-07-24: I haven't found discussions on the matter on the wiki, so I made this page.

What do you guys think of the following style of indentation for functional-leaning Tcl code?

# style #1
return [
    join [
        ltrim [
            struct::list mapfor x $msgLines {string range $x $indent end}
        ]
    ] "\n"
]

Its main benefit over "Lispish" indentation like

# style #2
return \
  [join \
    [ltrim \
      [struct::list mapfor x $msgLines {string range $x $indent end}]] "\n"]

or

# style #3
return [join \
    [ltrim \
        [struct::list mapfor x $msgLines {string range $x $indent end}]] "\n"]

is that it doesn't break when a backslash at the end of a line goes missing. The respective downside is that when you can't tell whether a command at the beginning of the line is being quoted or substituted from just looking at it; you have to see whether the line above it ends with a [ or a {.

On a related note, have you programmed your text editor to manage the backslashes within square brackets for the second/third style of indentation? I'm considering doing that but it still seems brittle: insert one newline in another editor (e.g., vi on the command line) and it breaks.

An rather more ugly example:

# style #1
set conn [
    ::ftp::Open [
        dict get $websiteConfig deployFtpServer
    ] [
        dict get $websiteConfig deployFtpUser
    ] [
        dict get $websiteConfig deployFtpPassword
    ] -port [
        dict-default-get 21 $websiteConfig deployFtpPort
    ] -mode passive
]

vs.

# style #3
set conn [::ftp::Open \
    [dict get $websiteConfig deployFtpServer] \
    [dict get $websiteConfig deployFtpUser] \
    [dict get $websiteConfig deployFtpPassword] \
    -port [dict-default-get 21 $websiteConfig deployFtpPort] \
    -mode passive]