SoftTree Technologies SoftTree Technologies
Technical Support Forums
RegisterSearchFAQMemberlistUsergroupsLog in
[11.5.362 Pro] - BUG: SE Tab mode: Insert spaces

 
Reply to topic    SoftTree Technologies Forum Index » SQL Assistant View previous topic
View next topic
[11.5.362 Pro] - BUG: SE Tab mode: Insert spaces
Author Message
gemisigo



Joined: 11 Mar 2010
Posts: 1919

Post [11.5.362 Pro] - BUG: SE Tab mode: Insert spaces Reply with quote
I'm using SQL Editor almost exclusively and have the Editor Options / Indents and Tabulation / Tab mode set to Insert spaces. That works most of the time but I have observed some rather strange behavior.
Check this short video here.

It shows that when I press Enter after the keyword DECLARE it breaks the line but instead of adding spaces for indentation it inserts tabs. The same applies when picking a table from the popup after the SELECT keyword. It promotes that low-ranking single SELECT to a full bird columnel statement but again, instead of using spaces, it indents with tabs.
Sun Sep 19, 2021 1:49 pm View user's profile Send private message
SysOp
Site Admin


Joined: 26 Nov 2006
Posts: 7419

Post Reply with quote
Thank you. Here is defect id for the described issue?
#SA0041996


Out of curiosity, why do you choose spaces over tabs?
Mon Sep 20, 2021 7:20 pm View user's profile Send private message
gemisigo



Joined: 11 Mar 2010
Posts: 1919

Post Reply with quote
When you use tabs the code can look radically different based on how many spaces those tabs are set in a particular editor/comparison tool/git client/etc. Combine that with a code that uses a mix of them (spaces AND tabs) and depending on the editor the code is opened the resulting image might look like complete garbage... er, I mean as if it wasn't formatted at all.

In contrast, if you use spaces the code always looks the same, no matter where you open it (well, except for non-fixed width fonts, but that's another story).
Tue Sep 21, 2021 4:14 am View user's profile Send private message
SysOp
Site Admin


Joined: 26 Nov 2006
Posts: 7419

Post Reply with quote
Quote:
When you use tabs the code can look radically different

In my 20+ years of working with the code my experience turned out to be totally the opposite, every editor and IDE takes too much liberty, often ruining all code formatting and alignment unless tabs are used consistently. Spaces also significantly inflate code size, and make block indenting/re-indenting much less productive. Well that's my experience, which isn't relevant here. The subject issue is in the queue.

I would like to clarify that replace tabs with spaces option is targeting tabs when they are manually typed. In other words, when you press Tab key, instead of inserting tab character it inserts spaces, as many as specified in the options. That feature doesn't replace tabs inserted by code snippets and other functions. When Enter key is pressed to move edit caret to the next line, the amount of white space and its tabs and spaces composition is copied to the new line without changes. If there are tabs present, they are copied as is.
There is an additional function in the Edit menu Edit -> Replace TABs, which formats the entire script replacing all tabs with spaces. A hot key can be assigned to it if that function is used often. It's not exactly what you need, but it may help with quickly rectifying tabs/spaces.


Last edited by SysOp on Tue Sep 21, 2021 10:57 am; edited 1 time in total
Tue Sep 21, 2021 8:36 am View user's profile Send private message
Mindflux



Joined: 25 May 2013
Posts: 709
Country: United States

Post Reply with quote
In all my years coding I cannot recall (either) a case where tab isn't the space equivalent of 4 spaces by default.
Tue Sep 21, 2021 8:53 am View user's profile Send private message
SysOp
Site Admin


Joined: 26 Nov 2006
Posts: 7419

Post Reply with quote
Please try v12 beta, it should be able to handle the two cases described here
Wed Sep 29, 2021 3:29 pm View user's profile Send private message
gemisigo



Joined: 11 Mar 2010
Posts: 1919

Post Reply with quote
I might as well put a quote here from Oscar to both of you :)

Angelo 'Snaps' Provolone wrote:

Wait. You're young yet


All jokes aside, I didn't want to rant again, but I do want you to understand my reasons. Your experience is not irrelevant but it seems that our experiences, yours and mine, differ. It's exactly that, editors and IDE-s taking the liberty and displaying tabs at arbitrary/default/user-set widths is making the visual mess. The contrast between the tabs and the spaces is that tabs can be used inconsistently while spaces can not. You put that tab there, one editor will show it as 4 spaces, another will display it as 2 and another one will say it's 8. And then comes a developer that likes to set it 3 spaces and formats their code accordingly. Whereas if you put 4 spaces there that will always be 4 spaces and displayed as such in every editor, no exception. Unless, of course, they convert them to tabs and that's when all hell breaks loose.

While in data (eg. in XMLs) it can be significant, in my opinion, code size is irrelevant. It won't affect execution speed, and indenting/reindenting works just as well, regardless of the number of blocks used. 1 tab or 4 spaces should make no difference from the perspective of the (re)indenter.

But all these so far, yours and mine, were only experiences and personal preferences, and they are subjective. You prefer tabs, I prefer spaces, no problem. I preferred tabs in the past as well. But then two things happened. The first is that I kept meeting different editors, viewers, git clients, etc. handling things differently and that made me go home and rethink my life.

And then I ran into a rather objective reason. It materialized as a funny little side-effect of having a tab in the code. Suddenly I got a large number of error reports from our support department when they deployed patch scripts. It turned out that some instances of that nasty bugger command-line interface of MySQL/MariaDB really, really want to interpret tabs in the code as the user's desire for code completion and mixing that with the existing code quickly results in syntactically incorrect garbage.

Now, if your patch codes for stored procedures look like this:
Code:

DROP PROCEDURE `usp_whatever`;

DELIMITER $$$
CREATE PROCEDURE `usp_whatever` (
{tab here} `a_whatever_argument` int...


it does not take long to recognize that adding even a small pinch of diligent, hard-working support personnel is a recipe for a disaster. Because diligent, hard-working people tend to be diligent, and hard-working, they test every patch script before reporting there's was a problem with "most" of them. On that dark and gloomy day, after the database side business logic was burnt and razed to the ground and I finished sobbing, I vowed to never again use tabs in MySQL/MariaDB scripts, regardless of the death threats I receive. And because I like consistency I applied that to other RDBMSs as well, it was easier, than keeping tabs on (yep, a pun ;) which one I was developing for currently. It also solved some of the formatting issues I had with SA (and were caused by using a mixed set of tabs and space instead of a pure space solution), so it was a double-win. From that day on I also refuse to work with an editor that cannot explicitly display control characters (though I do not always turn that on).

I re-checked what I did in the editor, re-created the problem with the DECLARE, and made a short video you can watch here. It mostly works as you described. When you hit Enter, the caret is moved to the indented position on the next line and it makes the indentation by copying the whitespace that made the previous line indented. This happens when you do that, for example, after the keyword SELECT. If you do so after the keyword DECLARE, the indenting whitespaces are copied as expected but you also get a gratis tab attached. For some reason, it tries to indent the following lines before even knowing if that would be required or not. I haven't observed that behavior with other keywords, I tried a few and the indentation consistently stays the same for the next line as it was for the previous one.

This isn't usually a problem as I always check my codes in the post-production/pre-versioning phase but I dread the day when I forget to do that. History usually repeats itself when it certainly should not.
Thu Sep 30, 2021 3:11 am View user's profile Send private message
gemisigo



Joined: 11 Mar 2010
Posts: 1919

Post Reply with quote
SysOp wrote:
Please try v12 beta, it should be able to handle the two cases described here


I didn't notice the beta was already out. Is there a way to have the best of both worlds? I mean, can I install the beta next to the non-beta of v11 without the two interfering with each other?
Thu Sep 30, 2021 3:20 am View user's profile Send private message
SysOp
Site Admin


Joined: 26 Nov 2006
Posts: 7419

Post Reply with quote
Unfortunately side-by-side isn't technically possible in a clean way because of the plugins with their common registry entries, and add-on with their fixed file locations, they all require single home. But not everything is bad. Every major version stores all version specific configuration settings in an isolated version specific location %APPDATA%\SQL Assistant\[version]. These files are preserved between installations and upgrades. If for whatever reason you choose to go back to previous version, or just switch back for a day or two, run the installer for that version, keep it close somewhere, and in a minute you can get where you were before. Keep a copy of version specific installers, don't delete them. It may not be the most intuitive way, but it does work, and allows fairly quick switching between versions.
Thu Sep 30, 2021 8:31 am View user's profile Send private message
Display posts from previous:    
Reply to topic    SoftTree Technologies Forum Index » SQL Assistant All times are GMT - 4 Hours
Page 1 of 1

 
Jump to: 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


 

 

Powered by phpBB © 2001, 2005 phpBB Group
Design by Freestyle XL / Flowers Online.