Rubberduck: Change operator placement for smart-concat feature

Created on 3 Sep 2019  ·  5Comments  ·  Source: rubberduck-vba/Rubberduck

Justification
I was reading the python PEP 8 style guide, and noticed something that could apply equally well to VBA code. The guidelines include instruction on whether to insert line breaks before or after a binary operator - you can read some justification there, but I think ultimately the look is really nice, and I believe this is a stylistic guideline that VBA developers should adhere to as well.

The smart concat feature currently places operators at the end of a line, before the line break _ character. I would propose moving them to the beginning of the subsequent line.

Description
Here's what I get at the moment:

Err.Description = "This is a very long sentence " & _
                  "with lots of linebreaks, to " & _
                  "demonstrate the smart-concat " & _
                  "feature"

And here's what I would propose:

Err.Description = "This is a very long sentence " _
                  & "with lots of linebreaks, to " _
                  & "demonstrate the smart-concat " _
                  & "feature"

With the multiline smart-concat (ctrl+enter) I'm in split minds as to the placement of vbNewLine following this change

Err.Description = "Invalid timer function supplied; timer functions must be one of:" & vbNewLine _
                  & " - a TIMERPROC pointer" & vbNewLine _
                  & " - an ITimerProc instance" & vbNewLine _
                  & " - a class name String"

Err.Description = "Invalid timer function supplied; timer functions must be one of:" _
                  & vbNewLine & " - a TIMERPROC pointer" _
                  & vbNewLine & " - an ITimerProc instance" _
                  & vbNewLine & " - a class name String"

I'd probably slightly favour the former (possibly that's just because I'm used to it as the current way of doing things), however I think it's definitely an improvement on having the & operator before the linebreak.

Additional context
Worth noting that this plays nicely with the smart indenter provided the "Ignore operators" setting is unchecked

enhancement feature-autocomplete feature-settings feature-smart-concat user-experience

Most helpful comment

I'd make that a smart-concat setting: "trailing concatenation operator" vs "leading concatenation operator".

All 5 comments

I'd make that a smart-concat setting: "trailing concatenation operator" vs "leading concatenation operator".

It does make handling backspace harder though.

@retailcoder I can imagine, although nothing the Rubberduck team isn't capable of ;)

Also FWIW I can't find any official guidelines on placement of newlines in strings, but I did find some example code...

template = ("This is the first line.\n"
            "This is the second line.\n"
            "This is the third line.")

...which puts the newlines at the end (of course python isn't VBA but it's good inspiration)

FWIW I'd make the vbNewLine follow the & operators - if it's trailing, then the whole package is trailing:

foo = "abcdef" & vbNewLine & _
      "ghijkl|"

If it's leading, then the whole package is leading:

foo = "abcdef" _
      & vbNewLine & "ghijkl|"

FWIW, I prefer the new line at the beginning (after the “&” operator). Helps me make sure the newlines are where I do (and do not) want them. I like the idea of how its done being a user preference setting.

From: Greedquest notifications@github.com
Sent: Tuesday, September 3, 2019 11:34 AM
To: rubberduck-vba/Rubberduck Rubberduck@noreply.github.com
Cc: Subscribed subscribed@noreply.github.com
Subject: Re: [rubberduck-vba/Rubberduck] Change operator placement for smart-concat feature (#5130)

@retailcoder https://github.com/retailcoder I can imagine, although nothing the Rubberduck team isn't capable of ;)

Also FWIW I can't find any official guidelines on placement of newlines in strings, but I did find some example code...

template = ("This is the first line.\n"
"This is the second line.\n"
"This is the third line.")

...which puts the newlines at the end (of course python isn't VBA but it's good inspiration)


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub https://github.com/rubberduck-vba/Rubberduck/issues/5130?email_source=notifications&email_token=AKCD6F67DTXL3RT345AXYOTQH2GV5A5CNFSM4ITIB3BKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD5YZJGQ#issuecomment-527537306 , or mute the thread https://github.com/notifications/unsubscribe-auth/AKCD6FYSJY2B57KAKAJCECDQH2GV5ANCNFSM4ITIB3BA . https://github.com/notifications/beacon/AKCD6F73NVDXYHG6I2W4AO3QH2GV5A5CNFSM4ITIB3BKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD5YZJGQ.gif

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Gener4tor picture Gener4tor  ·  3Comments

SteGriff picture SteGriff  ·  3Comments

retailcoder picture retailcoder  ·  3Comments

ThunderFrame picture ThunderFrame  ·  3Comments

susnick picture susnick  ·  3Comments