Redesigning Paste



  • DevStudio 2005 is chock-full of great new technology. One example is the "Paste" command. I bet you never thought there was anything wrong with the old way, right? Ctrl+C to copy, Ctrl+V to paste. It's simple and clear, it does the job, and it hasn't changed since around the time WordStar was released. No need.

    Well, the DevStudio 2005 team thought of something: Now, when you paste a line of code which ends with a semicolon, the text editor collapses every run of whitespace on the line to a single space character, except for whitespace at the beginning of the line. No, really. That's not a joke, it's true. I'm serious! And if there's no whitespace at the beginning of the line, but there is whitespace elsewhere in the line, it indents it to the level of the previous line in the file. That happens even if the whitespace in the line was left untouched (i.e., nothing but single space characters).

    Their assumption must be that in the normal case, you are adding whitespace that you don't want to add. I don't know why you'd do that, but some evil clown at Microsoft thinks he's got you figured out.

    Here's the best part: If you hit Ctrl+Z immediately after pasting, the editor restores the whitespace it just removed. If you really want to undo the paste you just did (which is what Ctrl+Z used to mean, remember?), you have to hit Ctrl+Z twice -- unless it happened that nothing in the line fit the mutilation profile. In that case, the first Ctrl+Z undoes what you just did, instead of what the editor just did to screw up your code.

    Oh, and by the way, if you paste in a line of text ending in a semicolon immediately preceding an existing line, it gratuitously mutilates the whitespace in the following line as well. This happens even if the pasted line's whitespace is not mutilated.

    So sometimes the Undo command is Ctrl+Z, and sometimes it's Ctrl+Z + Ctrl+Z. And the paste command is now two keystrokes as well -- in most cases. But not all, and the rules for deciding what to destroy are so convoluted they take a few paragraphs to explain.

    That's just brilliant: Take two of the most commonly used editor commands, and make them require two keystrokes each instead of one. But only in an arbitrary subset of cases, so you can't even just memorize the new, broken keyboard commands: You have to watch the thing every time. You have to learn to treat your text editor as a hostile entity. As if you didn't already have enough troubles already.

    It also indents pasted text to the indentation level of the previous line, even if indenting is disabled. That's not just "smart" indenting being disabled, but indenting, full stop. Naturally, it indents the following line as well, just because... well... because it's more insane that way.

    They don't have time to fix crashing bugs, but they have time to dream up surreal and byzantine modifications to commands whose behavior has been rigidly standardized throughout the entire industry (at least the parts that MS is aware of) for, what, 25 years? And they'll let you turn off a lot of moronic user-harassment misfeatures, but not this one. This time, there's no escape. It's the f*****g paperclip all over again.

    They have utterly lost it.



  • I make it a firm rule not to edit code with an editor that changes my code for me. I was annoyed enough at DreamWeaver's habit of re-doing all the line breaks in everything; this would drive me straight up the wall, instantly.

     



  • P.S. If the only non-leading whitespace in the pasted line is located immediately preceding the terminal semicolon, the line does not qualify for mutilation.

    For example, the following line will be pasted intact, with no damage done to the following line:

    foo ;

    ...but this line will be indented, in addition to further mutilation being visited
    on the line following, even though it has no internal whitespace that qualifies for mutilation:

    foo bar;

     



  • The formatting is based on the rules you define in your preferences.  I *think* you can prevent this from happening. 

     

    It does have its uses though: if you open up someone elses class which is formatted differently to your preferences, you can CTRL+A, CTRL+X, CTRL+V to reformat the entire file.

     



  • It's even worse than I thought: When you paste anything into a line, the whitespace in that line is mutilated. Virtually every case of pasting text now requires two keystrokes.

    And that would make this... the worst editor I've ever used. edit.com, vi, emacs, VB, ed, pico, Notepad... none of them can touch it.

    Unbelievable. 



  • I certainly hope I can turn this idiocy off, but I haven't found a way yet. 

    Most places I've worked, we've had better things to do than conduct guerilla warfare over code formatting. It plays hell with diffs.



  • Try Visual Basic .Net in Visual Studio 2003: It won't even allow you to custom-format stuff (with the default settings, I haven't bothered yet to look into it.).

    Nicely indent your code so all the =  are at the same column, press Enter et voila, 1 space only, automatic capitalization of your keywords, automatic indentation etc.

    Quite a relief to go back to having to do it manually once I got to do some C# and having the compiler tell you C# wants lowercase keywords etc. The ranting on VB-programmers is entirely valid: only people who want to think as little as possible while programming use it voluntarily, and that "requirement" is very visible in the code they write.

    I have an ex-colleague whose every other line was "on error resume next", his VB6 apps (and I had the pleasure of having to "convert" them to VB.Net, the boss would not allow a rewrite, no matter how bad the code was,  because "it works, and that's good enough.") were 100% procedural, not a single class to be found. No, that's not true I suppose. Every Form was a class (but them again, there no other way to do it, I think), but of course there was is a module declaring them all at startup, global variables all over the place...



  • Am I the only one, that really likes it? I just define my formatting style and don't care any more. I want to keep one style only, so if vs helps me with it, I'm really glad.

    Little things like auto-formatting, intelligent <tab> (after new, events, frequently used properties, ...), "vs style" <home> and many others make vs my favourite IDE. Even though I see it once a month maybe (I use linux / vim on daily basis), it's best one I've seen.

    I'd even add one more configuration to formatting styles: where to start new line of arguments, when you want to split the line. I prefer aligned:

    whatever(arg1, arg2, arg3,
    arg4, arg5);

     And VS forces 1 tab indent, or something like that.



  • The paste behaviour is totally customizable. You can't have looked very hard for the option to turn it off (Options > Text Editor > (Lang) > Formatting).

    The paste behaviour make perfect sense to me. Once I set the formatting options to my preferences, the paste command acts as a pretty-printer, saving me loads of trouble when pasting other people's code or code at a different level of indentation.

    The double-undo is consistent with Microsoft's Office apps that do any type of auto-formatting. Even if you've never used Word or Excel, it's a pretty intuitive way of giving the developer control in those cases where the auto-formatting is inappropriate for the pasted content.

    Of course, if one can't wrap one's head around it, I can see how it would make sense to write a short essay complaining about it rather than looking through the options for a way to disable it.



  • Visual Studio 2005 formats all the inserted code for you according to a preset standard, which you can customize in just about every single way. It cleans up code at the end of each valid line, which makes perfect sense considering that it's a code editor and not a text editor. You can always dumb it down to be one though.



  • bugmenot, 

    Reformatting other people's code is a neurotic stunt losers perform after they finish their daily quota of memory leaks.

    There's nothing intuitive about turning a single-keystroke command into two keystrokes, nor do you "give the developer control" by doing arbitrary stuff he never asked for. Control is when it does what I tell it to, not when it runs amok on its own initiative.

    You haven't quite explained all the lunatic exceptions to the rules, either: How does it serve your weird masochistic tendencies for the following line to be reformatted only if the line you paste has a certain configuration of whitespace in it? Can you explain that? And what about reformatting a line when you paste something into the middle of it? Do you only ever paste text into the middle of lines other people wrote? Is that it?

    By the way, does the word "diff" ring any bells with you?

    This foolishness makes no sense whatsoever to anybody who hasn't been behaviorally conditioned by Word to sit there obediently while the editor makes arbitrary and aggressively moronic formatting decisions.

    Thanks for the pointer on how to turn it off, though. My bad assumption there was that the feature could (as in software designed by rational adults, and as with much else in DevStudio) be disabled for all languages in the same place, so I was looking under "All Languages". But it turns out they didn't do it consistently; it seems not to be implemented for C++, for example. Which makes sense: If you're bright enough to learn C++, you've earned the right to write your code in peace. They only punish the idiots. This is what I get for wasting my time on C#.

    Lastly: "Wrap my head around it"? Why would I waste my time doing that? This is destructive, undesired, nonstandard behavior. I can see what it's doing, and what it's doing is idiotic. The designer's rationale for doing idiotic things is of no interest to me; he's the idiot, not me. But there's a remote chance that, if enough people complain about these imbecilic user-harassment decisions at Microsoft, such decisions will be made microscopically less often. Unlikely, but you take your chances in life. Same reason you vote.



  • Maybe this thread should be called "Insert senseless MS bashing here"

    Personally, I like the auto-formatting.

    Allows me to actually write code, instead of spending precious time making sure everything is aligned manually in a stupid text editor.

     


  • ♿ (Parody)

    [quote user="Edgar Plonk"]This is destructive, undesired, nonstandard behavior. I can see what it's doing, and what it's doing is idiotic. The designer's rationale for doing idiotic things is of no interest to me; he's the idiot, not me. But there's a remote chance that, if enough people complain about these imbecilic user-harassment decisions at Microsoft, such decisions will be made microscopically less often. [/quote]

    You should have downloaded Visual Studio 2005: Edgar Plonk Edition. It's a new thing Microsoft is trying; instead of doing extensive usability research, putting out beta editions for the public months before release, tweaking their software so that majority of users will like it, and allowing everyone else to customize it as needed, they've decided to just build a custom edition for each individual user.

    Personally, I love Visual Studio 2005: Alex Papadimoulis Edition. It ships with ProggyClean instead of Courier New; this way I don't have to waste a good 20 seconds or so going in the settings to change it.



  • [quote user="Quinnum"]

    Personally, I like the auto-formatting.

    Allows me to actually write code, instead of spending precious time making sure everything is aligned manually in a stupid text editor.

     [/quote]

    I may have to grudgingly agree here.  I don't use such tools, Emacs and vi do quite nicely.  But I've run across too many people that just can not absolutely to save their lives indent code.  I've seen people check out code, paste three lines ink, and check in the code, all within 5 seconds (they'd have been faster but they took their time because I was watching).  If the brainless editor of choice for these people has added auto indenting, it can only be a good thing (though I can you choose between any of the 17 most popular formatting styles?).

    Even with auto indenting, I still take the time to look code over and make sure it's correct.  I just can't understand people who are willing to put their name on poorly formatted code.  It's just unprofessional.  My home may be slovenly and unkempt, but my code is always readable.



  • > Edgar Plonk (various) 

    Now that's just language snobbery. Personally I really like that it helps to enforce a consistent coding style across the department. You can also export the format settings, place them on the network and configure all the clients to pickup the config file so any "standards" changes are grabbed automatically by the IDE ("Use team settings file:").

    The auto-format is invaluable when copy/pasting between different indentation levels etc; if anything, as long as all clients are configured to use the same standards, this makes "diff" easier, not harder. Note also that the chord [Ctrl]+E+D does an in-place reformat (instead of the "all, cut, paste" suggested earlier).

    But this post basically amounts to "C++ coders should be allowed to check in code in whatever format they like"... thy are called "standards", poeple! Pick a coding style, and then let the IDE help you enforce it without any developer effort. This is a good thing IMO.

    The code should be equally readable in any chosen format (otherwise it isn't written correctly!); all of this is just about making it consistent.



  • Auto formating is a good thing. Select some text tell the editor to apply my formatting standards to it.


    The problem is also that auto formating is a bad thing. There are times when you need to lay code out differently so that the really important features are immediatly obvious.

    eg

    SOME_CONST_VAR = 6;
    SOME_MUCH_LONGER_CONST_VAR = 12;
    TINYCONSTVAR = 18;
    REALLY_REALLY_REALLY_REALY_REALLY_LONG_CONST_VAR = 34;

    SOME_CONST_VAR                                                                      = 6;
    SOME_MUCH_LONGER_CONST_VAR                                            = 12;
    TINYCONSTVAR                                                                            = 18;
    REALLY_REALLY_REALLY_REALY_REALLY_LONG_CONST_VAR = 34;

    NOTE: the equals are meant to be at the same indentation.

    The latter isn't a formatting style i normally use, but sometimes the important bit is accross severall lines and needs to be made blantently obvious. The format on paste would destroy this, along with the semantic information i need to get accross to other developers. Granted it's still there, but you have to look for it.

    So it is smart to have a format on paste (lets say control + shift + v) and a standard verbatim copy of the clipboard paste which happens to be control + v.

    Cheers

    ps.
    it would also be nice if programming languages could provide an unobtrusive character that is simply ignored during compilation so that lines could be followed more easily.



  • You have totally misunderstood how it works. The paste command has not changed at all. What you are experiencing is auto format, which is a completely separate feature. It's only logical that the auto format step should be separate from the paste step in the undo history.

    I have used VS 2005 for a while now, and I really like the auto formatting. Usually I don't care much for stuff like that, especially not the dreaded total reformat of the design mode of previos versions, but this time it really works. Even the design mode works without messing up the code.

    If you don't like it, you can easily disable it. In much less time than it takes to rant about it. ;)

     



  • Man, I bet Edgar's face would melt if he ever accidentally hit Ctrl-K, Ctrl-D. Ha ha. (This is a keystroke I love, by the way, even if it does make horrible messes of HTML tags.)



  • [quote user="Alex Papadimoulis"]

    ... It ships with ProggyClean instead of Courier New...

    [/quote]

     I love you! I spent yesterday looking for something nicer than FrutigerLight and turned up nothing.

    Beautiful: http://www.proggyfonts.com/index.php?menu=download
     



  • By the way, does the word "diff" ring any bells with you?

    Yes.

    So does "diff (ignore whitespace)".

    In addition, I've never, ever, ever had more than one (1) consecutive space char in a line, except at the beginning, and within strings. But I'm sure VS doesn't format the spaces inside strings.

    I love you! I spent yesterday looking for something nicer than FrutigerLight and turned up nothing.

    I use Consolas, one of the new Vista default monospace fonts. Really great. I also have Cleartype ON, of course.

    FrutigerLight
     

    ... isn't the entire Frutiger family variable space?



  • [quote user="Edgar Plonk"]

    They don't have time to fix crashing bugs, but they have time to dream up surreal and byzantine modifications to commands

    [/quote]

    You know, I've found that some 90% of the time, Microsoft's automatic whitespace handling and indentation do exactly what I wanted to do anyway.

    Since that saves me a lot of time and effort, I don't bitch about the other 10% of the time.

    Of course, if that's not your experience - maybe VS isn't the best editor to use. It's not like we don't have a boatload of great editors out there.



  • Microsoft do have a bad habit of adding 'cool' new features, turning them on by default and making it difficult to find the place to turn them off. Auto-indenting when you paste whole lines is generally not too bad (though I'd prefer it if I chose to fix the indenting afterwards), but munging the internal formatting of a line is just wrong.



  • [quote user="db2"]Man, I bet Edgar's face would melt if he ever accidentally hit Ctrl-K, Ctrl-D. Ha ha. (This is a keystroke I love, by the way, even if it does make horrible messes of HTML tags.)
    [/quote]

    For those of us who are old enough to have worked with Wordstar-compatible editors, that's how you save and quit.  The real keystrokes from Wordstar are Ctrl-K, D.  But some editors also took Ctrl-K, Ctrl-D.



  • I don't see a single complaint (against VS) in this thread that can't be fixed with the simple reply "Options" - it's all there, it's all controllable.

    Are you people honestly so arrogant that you expect an editor, configurable up the wazoo and used by millions, should come installed with precisely your configuration by default?

    It took me, I think, a full 10 minutes to configure the numerous auto-formatting options of VS2005 (right down to the "insert a space after the open bracket of an 'if'" etc).  I did this once.  Surely 10 minutes is a worthy investment in an environment you'll spend so much time in?

    And anybody using a diff tool that gets confused by whitespace should get themselves a new one (I suggest any one of the many that is actually designed for free-form languages).

    Sorry for the harsh tone.  This kind of thing really annoys me.


Log in to reply