SoftTree Technologies SoftTree Technologies
Technical Support Forums
RegisterSearchFAQMemberlistUsergroupsLog in
[11.0.35 Pro] - FR: Commenting lines

 
Reply to topic    SoftTree Technologies Forum Index » SQL Assistant View previous topic
View next topic
[11.0.35 Pro] - FR: Commenting lines
Author Message
gemisigo



Joined: 11 Mar 2010
Posts: 2108

Post [11.0.35 Pro] - FR: Commenting lines Reply with quote
When nothing is selected in the editor the Comment with /**/ will only put a single /**/ into the code wherever the caret is currently positioned. On the other hand, Comment with -- will comment out the entire contents of the editor.

Not only does that not make any sense (why would anyone want to comment out everything???), it is potentially very harmful. An accidental hitting of the hotkey for Comment with -- without having anything selected in the editor with a couple of dozen of code lines is disastrous. It happens at once but is not undone as a group (checking/unchecking Group Undo in Options > Editor has no effect on it), it has to be undone line by line.

Now, making that function heed the Group Undo setting would only be damage control. It would be better if that function put that -- where the caret is, or what would be even much better, only commenting the current line (which is many other editors do).
Wed Oct 16, 2019 4:29 am View user's profile Send private message
SysOp
Site Admin


Joined: 26 Nov 2006
Posts: 7847

Post Reply with quote
If my understand is correct the described behavior of /**/ is wrong. It's a bug. As documented it should apply to the entire editor. The behavior is supposed to be consistent for all operations including code execution, text formatting, refactoring, etc.... if nothing is selected, it applies to the entire file. If there is a selection, it applies to the selected text only.

The group undo is a different issue. I think the problem here is that each line is commented out by -- separately instead of the entire text replaced at once. Because the insertion of line comments operation is not atomic, comments are inserted separately in every line, it cannot be undone in one step.
Wed Oct 16, 2019 10:30 pm View user's profile Send private message
gemisigo



Joined: 11 Mar 2010
Posts: 2108

Post Reply with quote
As I see, there are two problems, which seem to be likely to escalate to several more.

1. Simply putting the /**/ pair into the editor at the current caret position is a bug, without anything being selected it should behave as if everything was selected. That's the intended (and most likely best) way for it to work.
2. Comment with -- being consistent with all the other operations (regarding no selection there means to operate on the entire content)

If there are lines selected when using Comment with -- then Group Undo works as if the commenting operation was atomic, so I'm not mentioning Group Undo for -- comments here as it only happens when commenting without a selection and I strongly believe that Comment with -- should not be operating on the entire contents of the editor. That's what block comment (/**/) is for. Though we could debate about personal preferences, and I could even argue against myself as SQL is rather sh!tty about handling nested block comments. Heck, you can even comment out comments. Putting -- in front of a /* makes that /* never happened. That's some weird stuff :)

My point is that while being consistent in doing something in a defined/declared way is great, and consistency generally is a very good thing, it's only good as long as it does not get in the way. -- type comments are meant to comment a line or only part of a line. Sometimes it does make sense to comment out multiple lines with -- but it is clearly planned for single/partial-line use. Now, if you want to use -- as intended you'd have to select something before using that function/hotkey. And that might require pressing more hotkey that necessary.

For example, if I'm in the middle of a line and want to comment out the rest of it, it's much easier to hit '-' twice instead of using the hotkey (which, in its current state, would need me first selecting at least one character to the right).
Now let's suppose I'd like to comment out the entire line, and that's exactly where this function/hotkey could shine. I simply hit the hotkey and move a line below, where I either repeat the sequence or edit something or simply comment out the rest of the line by adding '--' there. This is how many other editors (eg. Notepad++, Sublime Text, SQL Server Management Studio, Visual Studio Code, etc.) handle adding/removing line comments, and frankly, I think their way makes much more sense.

Instead, I have to hit Home (twice, if I want it to put that comment really at the beginning of the line), use Shift+Right/End to select at least 1 character and only then am I allowed to press the hotkey without it completely ruining my day. Hitting Home (twice) and '-' twice is a bit shorter and faster but it still leaves me at the beginning of the line instead of where I'd like that caret to be, so I have to move it back. Using markers help but that only adds to the keys pressed.

By the way, more or less the same applies to Uncomment. If there is more than one line commented using --, and I hit the hotkey for Uncomment two things can happen:
1. If the -- for a certain line is not selected, that line won't be uncommented. That might be a bit inconvenient, but no harm is done. Also, one would expect that only the selected text is allowed to change. On the other hand...
2. Not having anything selected in the editor, it removes every single darned comment in the editor, which is a minor catastrophe on its own, considering it behaves similar to adding comments, that is, removes them one by one and cannot be undone as a group.

Both Comment with -- and Uncomment are dangerous, potentially destructive, and require great care using them. In my opinion, they must not be allowed to operate on the entire editor content unless explicitly selected. Otherwise, that'll be a recipe for a disaster.
Thu Oct 17, 2019 8:30 am View user's profile Send private message
SysOp
Site Admin


Joined: 26 Nov 2006
Posts: 7847

Post Reply with quote
You have very valid points. I just want to add one more. Using /* */ isn't always appropriate. If the text in the editor already has /* */ comments that wouldn't work well, because nested comments break the script. The solution is to use -- comments for all lines, it can be applied as many times as needed, nothing breaks.

There as a common use case scenario when someone writes queries in the editor and executes them iteratively, they want to write something else and don't bother with selecting/deselecting anything, scrolling up and down, and or deleting the text. Kind of type press F5 to run, review results, type something else, press F5, and so on. One Ctrl +- hotkey solves that. After hotkey
everything is commented out, F5 is usable, and new query can be started and executed without doing extra keystrokes or mouse moves/clicks.
Thu Oct 17, 2019 11:37 am View user's profile Send private message
gemisigo



Joined: 11 Mar 2010
Posts: 2108

Post Reply with quote
Yes, I already mentioned problems with nesting comments.

As for the use case, I think that can be done better. Utilizing -- there is not the best choice for multiple reasons.
1. Using a single /* */ pair instead will keep the commented code in a "somewhat executable" form by selecting them and executing the selection. That works even if the code is inside a comment block (provided you don't select the comment boundaries, of course). The same is not true for -- comments, except for the single line statements. Very limited.
2. Putting more and more -- comments in front of already existing ones creates a real mess very quickly. That pile of increasing number of -- comments might be useful for trying to reconstruct what has happened, but it isn't easy. If retaining what has happened is a requirement, using the execution history is much more practical.
3. It might also not be a single hotkey. In case you have Auto Complete -- Comments enabled, that last -- comment (that ends up on the same line your caret) will make it require a couple of more keys to be pressed before you can type something new. Simply hitting Enter will "complete" the next line with the same -- so you cannot just start and type the query. So you either need to hit Backspace thrice or Ctrl+Backspace or Shift+Home to overwrite those dashes. You have to hit two hotkeys. On the other hand, using Ctrl+A will truly allow you to start typing the new query in a shining new and empty editor :)
4. In some cases Execute Current Statement or using the Select Current Statement (which can be used incrementally) is also a viable alternative.

In my opinion, while using the -- might not be the worst way to comment everything out, it's pretty close to it. But then again, that's personal preferences. Meanwhile, I still think it's quite disturbing that SA handles this in a different way than some (most?) other editors. And I still hold firm that the Uncomment function must not be allowed to operate at all without having a selection. It's harmful.
Fri Oct 18, 2019 10:53 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.