Author |
Topic |
|
mod42
New Member
3 Posts |
Posted - Sep 26 2007 : 04:12:09 AM
|
Hi
I always format my switch case statements like this:
switch(curChar)
{
case '\\n':
{
foo();
break;
}
case '\\r':
{
bar();
break;
}
case '\\a':
{
foobar();
break;
}
}
But this style is not very well supported by VAX. If I type the first case statement (indented by four spaces) and end it with a ':' it is always put at the same indention as the '{' of the switch statement. If I hit Enter then the curser is indented. Is it possible to change this behavior or make it an option to match my style of switch/case?
mod42 |
|
rhummer
Tomato Guru
USA
527 Posts |
Posted - Sep 26 2007 : 09:49:58 AM
|
Turn off VA X and you will notice the same behavior. Thats the IDE that does the reformatting. |
Tools Engineer - Raven Software VS2005 SP2/VS2008 SP1 - VAX <LATEST> - Win 7 x64
|
|
|
feline
Whole Tomato Software
United Kingdom
19020 Posts |
|
accord
Whole Tomato Software
United Kingdom
3287 Posts |
Posted - Sep 26 2007 : 6:25:19 PM
|
I think the IDE's formatting in switch statements is horrible, and programmers usually agree with me... |
|
|
feline
Whole Tomato Software
United Kingdom
19020 Posts |
Posted - Sep 27 2007 : 09:30:17 AM
|
Personally I am not a great fan of the IDE's C++ code formatting, but at the same time I don't really feel like arguing with it every time I edit a line of code, so in the end I decided to just get used to it *sigh* *shrug*
I am one of many people who like the idea of VA doing code formatting. But I also have some idea of the work involved in this idea. |
zen is the art of being at one with the two'ness |
|
|
accord
Whole Tomato Software
United Kingdom
3287 Posts |
Posted - Sep 27 2007 : 5:17:43 PM
|
Personally I don't expect VAX code formatting. Most of the time I am pleased with Microsoft's solution...
As you said "I also have some idea of the work involved in this idea." I think if you put this time into refactoring, it can give more speedup for developers...
I believe that more and more developer will use refactoring, and it is a good news for VAX team. VAX's parser is not yet perfect, but it the most advanced ever. This plug-in is the only one, which can rename reliably even a C++ variable... So it is the most advanced AND unique feature in VAX, I think.
A lot of programmer can write some code formatting stuff, but who have the audacity to write reliable refactoring features? Only VAX team I have tried Refactor Pro, Ref++, SlickEdit, etc., but none of them was reliable...
|
Edited by - accord on Sep 27 2007 5:54:21 PM |
|
|
sl@sh
Tomato Guru
Switzerland
204 Posts |
Posted - Oct 01 2007 : 04:19:16 AM
|
Whenever I see the IDE doing an autoformat that I don't like, I just press Ctrl+Z (Undo). That normally does the job (i.e. undo the formatting )
Unfortunately sometimes (not always reproducable) it also undoes the typing . I just tried a switch-case and Undo did work as intended (by me) at least once (but not always ). So I suppose it takes a little experience to do the typing in a way that will preserve the typing after autoformat+undo.... |
Edited by - sl@sh on Oct 01 2007 04:24:31 AM |
|
|
AGPX
Senior Member
28 Posts |
Posted - Oct 22 2007 : 08:09:43 AM
|
If you write C++ code and use switch - case so necessarily, man you have something wrong in your object oriented aspect |
Edited by - AGPX on Oct 22 2007 08:26:15 AM |
|
|
feline
Whole Tomato Software
United Kingdom
19020 Posts |
Posted - Oct 22 2007 : 1:56:11 PM
|
Personally I would not say that.
Consider parsing a simple data file, with conditional fields. For a simple file format switch statements on the conditional field makes a lot of sense, and it is a lot less code than constructing the class hierarchy, especially if you only need a small amount of code for each case.
I like a good class hierarchy, virtual functions, etc, but I only use them when I feel they are useful. To me a switch statement is a simple and effective tool, so use it when it is the right tool.
Also I have the feeling that just about all auto generated windows code handling messages I have seen uses switch statements to decide which message it has just been given. |
zen is the art of being at one with the two'ness |
|
|
sl@sh
Tomato Guru
Switzerland
204 Posts |
Posted - Oct 23 2007 : 10:45:12 AM
|
Well, you *can* construct OO constructs to avoid just about any situation that otherwise would require switch statements - but that doesn't always mean it's practical to do so.
Regarding windows message handling: I've worked with an UML tool that actually gave the programmer the choice to either generate a class hierarchy or switch statements for the state machines in the model. If you chose class hierarchies, each windows event was generated into a new class. In our case, we did start out with a class hierarchy, but soon changed to switch statements because we realized the resolution of virtual function tables at runtime made us miss our realtime deadlines! But that was only a problem because it was an embedded control program with strong time constraints - for a standard PC application the class hierarchy would have worked just fine.
In general I agree that whenever you start writing a switch statement, you *should* consider for a moment, what kind of classification is the basis of this switch, and whether or not it would make sense to actually introduce objects representing this classification. Sometimes it isn't worth the hassle - but sometimes you can make your code just a little better... |
|
|
|
Topic |
|