openvpn3
openvpn3 copied to clipboard
Fix inconsistent use of hard and soft tabs
The OpenVPN 3 codebase seems to use the GNU coding style as far as I can best see from the list of common indentation styles on wikipedia. I don't want to start a debate on which style is best, the best thing is consistency.
However there is a key issue throughout the code base with regards to spaces and hard tab characters, where four groups of 2-space tabs get grouped into a single hard tab. Admittedly this is done consitently from what I have seen, but I was wondering why this is the case.
To illustrate how this can be inconvenient, below I have quoted some code from OpenVPN 3 with >>------
to denote a hard tab and >~
to denote a soft tab:
openvpn/tun/builder/client.hpp:123
:
>~>~public:
>~>~>~virtual void tun_start(const OptionList& opt, TransportClient& transcli, CryptoDCSettings&) override
>~>~>~{
>--------if (!impl)
>-------->~{
>-------->~>~halt = false;
>-------->~>~if (config->tun_persist)
>-------->~>~>~tun_persist = config->tun_persist; // long-term persistent
>-------->~>~else
>-------->~>~>~tun_persist.reset(new TunPersist(false, config->retain_sd, config->builder)); // short-term
>-------->~>~try {
>-------->~>~>~int sd = -1;
>-------->~>~>~const IP::Addr server_addr = transcli.server_endpoint_addr();
>-------->~>~>~// Check if persisted tun session matches properties of to-be-created session
>-------->~>~>~if (tun_persist->use_persisted_tun(server_addr, config->tun_prop, opt))
>-------->--------{
>-------->-------->~sd = tun_persist->obj();
// .... and so on
Now when your editor is set to use 8 space hard tabs, this looks fine (as indeed it does on the github code viewer):
However some editors may not have this set as their default hard tab width, or indeed may auto-detect the tab width based on the spaces. For example, VS Code which I have been developing in lately seems to generally pick up OpenVPN 3 source files as 4 space tabs, and thus renders the code as such:
As you can see, this makes the code much more difficult to read, as heavily indented code gets brought in by virtue of the hard tabs not being spaced out enough. Obviously this very small example might not look too bad given that you have just seen the code how it is supposed to look, but when going through the entire code base on different occasions on editors on different machines, this becomes very fatiguing.
This has been a problem for me when working with OpenVPN in different editors, and I cannot see any documentation or style guide as to why OpenVPN 3 chooses to convert 8 spaces into tabs, so if anyone could elaborate on this that would be great.
The only reason I could fathom for this is perhaps very minor file size space savings, but this is an extremely moot point on modern hardware, and if we're supporting old hardware then I should imagine the code base should be compliant to 80 character lines which it is now. In any case unless I am missing something, in my opinion this is more of a nuiscance than it is good.
I'm happy to provide a pull request that expands hard tabs into soft tabs to fix this issue, but as this is usually quite a devisive topic, I am opening this issue for discussion here first.
In general, the coding style in OpenVPN 3 is in a sad state. There are a lot of inconsistencies all over the code. This is a known issue, and we have already had several internal discussions about this trying to agree on a unified style to apply across the whole project and the proper tooling to handle this well.
If you can bare with us a bit longer, this will be handled by OpenVPN Inc, where we will update the style and add instructions how to configure various IDEs.
Sure thing, glad to know it's not just driving me mad!
Let me know if I can offer any assistance, but I will eagerly await some updates!