Author Topic: space before (  (Read 7312 times)

Ivan N. Zlatev

  • Community Member
  • Posts: 87
  • Hero Points: 5
space before (
« on: December 25, 2007, 12:31:58 PM »
I just want to have a space before all my (. E.g:

if (...)
someMethod ();

but the "No space before paren" unticked doesn't work at all both in C and C#. It still produces no space on completion or code generation (e.g when overriding methods in C#)  :-[

ScottW, VP of Dev

  • Senior Community Member
  • Posts: 1471
  • Hero Points: 64
Re: space before (
« Reply #1 on: December 26, 2007, 04:23:11 PM »
Can you be more specific about the key strokes you are typing? That will help us to pin this down to a specific mechanism in SlickEdit.

If I understand what you've written, completions are behaving correctly and will only complete the symbol name, not insert the open or close parens. So, if Foo() is already defined, typing "Fo" and selecting "Foo()" from the list will insert "Foo" and not "Foo()". Are you looking for it to insert "Foo " instead?

Also, I need more information on what you mean by "code generation". Something along the lines of "I type xxx and SlickEdit does yyy..."

--Scott

Ryan

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 986
  • Hero Points: 77
Re: space before (
« Reply #2 on: December 26, 2007, 07:33:35 PM »
Quote
"No space before paren" unticked doesn't work at all both in C and C#. It still produces no space on completion or code generation

To follow up on Scott's response, if by not working "at all", you mean not even for when you type "if <SPACE>"...then that would be a bug (or at least something behaving incorrectly).  That option in the "C/C++ Options" dialog should definitely be working for syntax expansions.

- Ryan

Ivan N. Zlatev

  • Community Member
  • Posts: 87
  • Hero Points: 5
Re: space before (
« Reply #3 on: December 30, 2007, 07:44:38 PM »
When I have Tools -> Options -> File Extension Setup -> Context Tagging tab -> Insert open parenthesis enabled
and
Tools -> Options -> File Extension Setup -> C# Options -> No space before paren disbled

1) When I use Override Method for a class I get something like:
Code: [Select]
internal class UndoRedoEngine : UndoEngine
{
protected void AddUndoUnit(UndoEngine.UndoUnit unit) {

}
protected override void DiscardUndoUnit(UndoEngine.UndoUnit unit) {
}

}

I would expect it to be
Code: [Select]
AddUndoUnit ( and
Code: [Select]
DiscardUndoUnit (
2) When the completion list shows and I hit RETURN I do not get a space before the ( e.g:
Code: [Select]
String.<list shown -> hit return on the first entry ("Compare")>
String.Compare(
instead of
Code: [Select]
String.Compare (

hs2

  • Senior Community Member
  • Posts: 2761
  • Hero Points: 292
Re: space before (
« Reply #4 on: December 31, 2007, 03:13:21 PM »
Sounds like a good idea to 'use' this flag also for the code completions and not only for keywords. (+1)
HS2

Dennis

  • Senior Community Member
  • Posts: 3961
  • Hero Points: 517
Re: space before (
« Reply #5 on: December 31, 2007, 05:44:49 PM »
Do you have an alias which is overriding the default expansion behavior for "if"?  Does that alias have a space before the paren?

With respect to function calls:  No, the symbol expansion stuff does not support the no space before paren option.  I do not think many people would like the same option causing function calls to get a space before the paren.  I know I would not like that in my code. 

It would have to be a separate option.  To justify adding this option, could one or both of you explain why you prefer it in the first place?  How is "Func (arglist)" better than "Func(arglist)".  Personally, I find that style disconnected and unfamiliar, probably because I come from a mathematical background.

I am not trying to criticize your programming style -- it's just important to have good reasons before investing time in adding, testing, and documenting another coding option.

Ivan N. Zlatev

  • Community Member
  • Posts: 87
  • Hero Points: 5
Re: space before (
« Reply #6 on: December 31, 2007, 06:18:30 PM »
Do you have an alias which is overriding the default expansion behavior for "if"?  Does that alias have a space before the paren?

"if" works fine. If I type "if" and then hit space I get "if ()".

With respect to function calls:  No, the symbol expansion stuff does not support the no space before paren option.  I do not think many people would like the same option causing function calls to get a space before the paren.  I know I would not like that in my code. 

Apparently If I hit BACKSPACE instead of Return I do get a space before the ( on completion.

It would have to be a separate option.  To justify adding this option, could one or both of you explain why you prefer it in the first place?  How is "Func (arglist)" better than "Func(arglist)".  Personally, I find that style disconnected and unfamiliar, probably because I come from a mathematical background.

I am not trying to criticize your programming style -- it's just important to have good reasons before investing time in adding, testing, and documenting another coding option.

It's not a question of personal preference, but a question of the coding style of a project I am working on. The same project uses { on a new line for methods and { on the same line for loops and conditionals with no { for single line loops/statements. SlickEdit doesn't support those as well (mixed style { ).

Dennis

  • Senior Community Member
  • Posts: 3961
  • Hero Points: 517
Re: space before (
« Reply #7 on: December 31, 2007, 07:46:56 PM »
Quote
The same project uses { on a new line for methods and { on the same line for loops and conditionals with no { for single line loops/statements. SlickEdit doesn't support those as well (mixed style { ).

I'll let you in on a secret feature, but you can't tell anyone else, otherwise everyone will start using it and it won't be much of a secret anymore.   ;)

Try typing:  "if;" or "while;"

When you hit the semicolon, the statement will get expanded out as a single line statement.  This is very helpful so that you can get some useful completion for single line statements, in addition to the normal brace expansion for multi-line statements.  It doesn't have an option to force the statement to a new line, but a quick whack on the Enter key will solve that every time.

Also, you should be able to get the behavior for function braces that you want (at least, from the beautifier) if you turn off "Apply to function braces" in your C/C++ formatting options.

Quote
Apparently If I hit BACKSPACE instead of Return I do get a space before the ( on completion.

What emulation and what do you have backspace assigned to?  (Help >  What is Key)  You shouldn't even get a completion on backspace, unless you have it re-assigned to something.  Even then, wow, that shouldn't happen.


Ivan N. Zlatev

  • Community Member
  • Posts: 87
  • Hero Points: 5
Re: space before (
« Reply #8 on: December 31, 2007, 09:39:01 PM »
Quote
Apparently If I hit BACKSPACE instead of Return I do get a space before the ( on completion.
Quote
What emulation and what do you have backspace assigned to?  (Help >  What is Key)  You shouldn't even get a completion on backspace, unless you have it re-assigned to something.  Even then, wow, that shouldn't happen.

Backspace is c-space
Enter is c-enter
Emulation is CUA
« Last Edit: January 01, 2008, 06:26:05 PM by i-nZ »

hs2

  • Senior Community Member
  • Posts: 2761
  • Hero Points: 292
Re: space before (
« Reply #9 on: January 01, 2008, 03:19:21 PM »
@Dennis: Thanks a lot for the 'single line statement completion' hint - very useful indeed !
Sorry - I was a bit confused conc. the code completions :-[
The curr. impl. of list-symbols is just fine since I can already complete a function with <SPACE> and together with 'Space always insert space' being checked it follows my (disconnected) style.
BTW: What's the reason why 'autocomplete' doesn't auto-insert any fct. braces (except word-completions of course) as list-symbols does ? But I could imagine that this will be solved if the completion paths are unified one day (if it's planned).

I thought about my disconnected style habit and now I know why and when I started using that way of formatting (in dark pre-SlickEdit ages)...
Although a bit unusal I like the visual seperation of fct. identifier and parameter part. I found that I can recognize the course program flow more quickly when I don't need to seperate the identifier / parameter part myself. Only when going into detail I take care about the parameter lists. I think that nowadays with color coding support I don't really need the additional SPACE any longer and I'll start moving to the more common connected style. (Never stop changing !)
Besides that it's conform to recommended coding style in the companies I'm working for. So I better change my habit anyway ;)

BTW: I'd also prefer a 'space before paren' for the 'return' keyword. In fact I'm using a tiny beautify-(selection) wrapper which solves that at least for beautifications. Is there a reason why the return keyword is not covered by this option ?
I assume this is caused by parens being optional for the return statements. But if I explicitely enter a '(' when completing it should follow the same rules as applied to e.g. 'if' and shouldn't be omitted.

Happy new year !
HS2

StephenW

  • Senior Community Member
  • Posts: 197
  • Hero Points: 21
Re: space before (
« Reply #10 on: January 06, 2008, 10:12:40 PM »
Quote
BTW: I'd also prefer a 'space before paren' for the 'return' keyword. In fact I'm using a tiny beautify-(selection) wrapper which solves that at least for beautifications. Is there a reason why the return keyword is not covered by this option ?
I assume this is caused by parens being optional for the return statements. But if I explicitely enter a '(' when completing it should follow the same rules as applied to e.g. 'if' and shouldn't be omitted.

Like many, many C/C++/C# users, you seem to be a little mixed up about parentheses in return statements.  In the if () statement, the () is part of the language syntax for the if.  In a return statement, the () are not optional, they are simply not part of the syntax of a return statement.  You can use () in a return statement because they are part of the syntax of the expression that a return statement uses, but they are always unnecessary and have no use whatsoever from the compiler's point of view.  If you use them to clarify a complex expression, as you would for any complex expression, fine.  But in my opinion that should be the only reason to ever have () around a return expression.  They should not be used by default, as they only clutter up the otherwise very simple and straightforward return statement.

Unfortunately, there are a number of coding styles where () around return expressions are always used, and some companies require such coding styles.  I presume that this came about due to ignorant people copying how the if () and while () syntax works, without checking to see if it was necessary for return.  Whenever I am given the chance, I use a global search and replace to rip out such coding monstrosities.  Why require two extra keystrokes (or automated editor support) to add unnecessary and utterly useless clutter to your code?

hs2

  • Senior Community Member
  • Posts: 2761
  • Hero Points: 292
Re: space before (
« Reply #11 on: January 06, 2008, 11:27:05 PM »
Yeah, you're completely right about the fact that the parens are NOT part of the 'return' syntax. Thanks for the detailed clarification !
But as you said this is not known to everybody which was obviously the reson why the parens where the required coding style in a company I was working quite a long time. So I got used to it somehow...
Seems to be the next habit to throw overboard ;)

HS2