Why is Xamarin now inserting line breaks in my one-line if statements?

JoeStroutJoeStrout USMember

Since upgrading recently (I'm now on 4.0.8, though this bug may go back to 4.0.7), the Xamarin editor insists on breaking my single-line if statements. For example, if I type:

if (frac > 1.0f) frac = 1.0f;

...as soon as I press Return at the end of the Line, Xamarin changes this to:

if (frac > 1.0f)
    frac = 1.0f;

This breaks one of the most sacred rules in our company coding standards, which states that you never, EVER put the single-line body of an if/while/for statement on the next line without curly braces, because that makes it far too easy to utterly break the code in a silent way later by inserting something else in between. Yet we're encouraged to use single-line if's (without curlies) for trivial adjustments like this, because it makes the overall method shorter and easier to read.

I've searched through all the Code Formatting preferences, and can't find one that controls this awful new behavior.

Can anyone point out the preference setting I'm missing, or explain how to file a bug? This is driving us nuts.

Posts

  • MikeKrgerMikeKrger DEXamarin Team, Beta Xamurai

    There is a formatting option missing for that.

    Until we have it turn off the on the fly coding formatting in the options (editor->behavior->on the fly formatting).

  • JoeStroutJoeStrout USMember

    It's a year later, and this is still driving me nuts. This is the one thing I hate most about the Xamarin IDE... my procedure for typing a single-line if statement is:

    1. Type the statement and press Return.
    2. Curse at Xamarin for breaking it and giving me dangerous code.
    3. Take my hands of the keyboard and reach for the mouse.
    4. Click at the start of the broken line.
    5. Drag to the end of the previous line.
    6. Press space (replacing the line break I didn't want with the space I had typed originally).
    7. Again reach for the mouse.
    8. Click at the end of the line.
    9. Press return again.

    Then I continue with my work. This is ridiculous. I know, I could just stop using single-line if statements, but in many cases they make the code shorter and more readable. I'm not going to let Xamarin force me to write worse code.

    We really, really need a formatting option for this, or for Xamarin to decide that the current formatter is Just Plain Wrong (for the reasons described in the first post in this thread), and to fix it.

    I want to love Xamarin, and this is now the only thing standing in the way.

  • JoeStroutJoeStrout USMember

    WOO-HOO! I am delighted to report that with today's update of Xamarin Studio (version 5.0 build 878), this problem is finally fixed!

    The magic setting is in Preferences->Source Code->Code Formatting->C# source code, Edit, Indentation, New Lines, "Place embedded statements on new line." Change this to "Always same line" and Xamarin no longer breaks your code in a most dangerous way!

    I literally leapt out of my chair and did a happy dance around my office. The #1 most annoying thing about the IDE has just been fixed. Huzzah!

  • JoeStroutJoeStrout USMember

    WOO-HOO! I am delighted to report that with today's update of Xamarin Studio (version 5.0 build 878), this problem is finally fixed!

    The magic setting is in Preferences->Source Code->Code Formatting->C# source code, Edit, Indentation, New Lines, "Place embedded statements on new line." Change this to "Always same line" and Xamarin no longer breaks your code in a most dangerous way!

    I literally leapt out of my chair and did a happy dance around my office. The #1 most annoying thing about the IDE has just been fixed. Huzzah!

  • rezanaimarezanaima USMember

    This problem is still happening for me (5.1 build 479). Driving me nuts!

  • WilliamJockuschWilliamJockusch USMember ✭✭

    I am having a similar problem with the cases of "switch" statements. I want to write simple ones like the following. XS is not making it easy for me as it always wants to put the "return" part on a new line. I don't know if the setting exists somewhere or not.

    public string Name(int number) {
      switch (number) {
         case 0: return "zero";
         case 1: return "one";
      }
    
Sign In or Register to comment.