Author |
Topic |
|
BruteForce
Senior Member
Greece
32 Posts |
Posted - Sep 26 2008 : 11:36:33 AM
|
In an empty Win32 project declare one variable inside a function: BOOL bTest;
In the next line I start an if statement and type "if(b".
VA suggests the following: - BOOL - bool (default suggestion) - break - bTest
To start with 'break' is out of the question. It should not appear.
Then, since I am obviously typing an identifier (there is no extra parenthesis to suggest I might be starting a typecast) I would expect to get only identifiers in the suggestion list.
In more complex projects the list also includes macro names that start with B.
I would not call this a bug, but it would be a little welcome improvement. With the possible exception of zero-hungarian modernists :-P, I think that starting boolean variable names with 'b' is a bit common so it's a bit of a pain to get irrelevant suggestions in this case. That's why I used this example.
Warm Regards, Dimitris Staikos |
When all else fails try common sense. |
|
pjohnmeyer
New Member
9 Posts |
Posted - Sep 26 2008 : 1:57:29 PM
|
quote: Then, since I am obviously typing an identifier (there is no extra parenthesis to suggest I might be starting a typecast) I would expect to get only identifiers in the suggestion list.
I wouldn't say obviously; you can do
if ( bool b = SomeMethodThatReturnsABool() )
{
// will execute if b is true as returned by the method
}
I'm not sure WHY you would (at least with a bool -- definitely seen this with pointers when the pointer is used in the if block), but you could. |
Edited by - pjohnmeyer on Sep 26 2008 1:58:19 PM |
|
|
feline
Whole Tomato Software
United Kingdom
19021 Posts |
Posted - Sep 26 2008 : 1:58:41 PM
|
"bool" will be a default suggestion if you have a VA Snippet for bool with the shortcut "b", which is quite possible.
At this point you could be calling a function, or a class member variable, or a macro. You could also be asking for a type, since you may be about to declare a new variable. So the only one that is unreasonable is break, but this assumes that you are typing "valid" code
"valid" is a tricky one, since sometimes people want VA to be active in "it looks like C" languages.
Having said all of this I rather like the idea, but I am not sure what VA can really do, in general, that helps without causing to many problems. |
zen is the art of being at one with the two'ness |
|
|
feline
Whole Tomato Software
United Kingdom
19021 Posts |
Posted - Sep 26 2008 : 1:59:53 PM
|
Cross posting strikes again pjohnmeyer you make a very good point, and I have also seen this sort of thing done occasionally with pointers. |
zen is the art of being at one with the two'ness |
|
|
BruteForce
Senior Member
Greece
32 Posts |
Posted - Sep 27 2008 : 10:13:17 AM
|
quote: Originally posted by feline
"bool" will be a default suggestion if you have a VA Snippet for bool with the shortcut "b", which is quite possible.
I checked it out and under C++ snippets I only have your defaults for this case which is capital B ==> BOOL. Under C# snippets 'b' ==> 'bool', but I am in a C source file so I would expect the C++ snippets to be active.
quote: Originally posted by feline
At this point you could be calling a function, or a class member variable, or a macro.
I think that macros are not that probable, it wouldn't hurt much to omit them, with the possible exception of those that already appear within if conditions in earlier code. So basically the first time I use a macro in a condition you add it in VA's if-suggestion list. I think this would not be that tough to implement, however I am not in your shoes so I can't forsee all consequences [;-)] In driver development there are far too many macros and the list gets a bit messy.
quote: Originally posted by feline
You could also be asking for a type, since you may be about to declare a new variable.
quote: Originally posted by pjohnmeyer
I wouldn't say obviously; you can do
if ( bool b = SomeMethodThatReturnsABool() )
{
// will execute if b is true as returned by the method
}
I'm not sure WHY you would (at least with a bool -- definitely seen this with pointers when the pointer is used in the if block), but you could.
[:-)] Doing driver coding in C about 90% of my time I tend to wipe out of my head all these totally unnecessary "syntactic sugar" crap of C++. Still, I guess VA can figure out I am in a .C file and not suggest types where types can't appear [:-)]
quote: Originally posted by feline
So the only one that is unreasonable is break, but this assumes that you are typing "valid" code "valid" is a tricky one, since sometimes people want VA to be active in "it looks like C" languages.
That's exactly why I said I am not in your shoes! I guess it must be a really demanding job keeping every possible VA user happy. |
When all else fails try common sense. |
|
|
pjohnmeyer
New Member
9 Posts |
Posted - Sep 29 2008 : 09:53:29 AM
|
quote: [:-)] Doing driver coding in C about 90% of my time I tend to wipe out of my head all these totally unnecessary "syntactic sugar" ---- of C++. Still, I guess VA can figure out I am in a .C file and not suggest types where types can't appear [:-)]
Just an FYI, this isn't "totally unnecessary 'syntactic sugar'"... the variable declared in the if condition is limited to the scope of the if block, and limiting scope of variables, as you probably know, is generally considered good programming practice. Not that this has anything to do with your problem, just letting you know. |
|
|
BruteForce
Senior Member
Greece
32 Posts |
Posted - Sep 29 2008 : 12:11:00 PM
|
I happen to know that, thanks anyway What most people don't know though, is that in C you can declare variables practically anywhere; that is anywhere a new scope is opened with a left bracket:
void f(void)
{
...
while (some_condition)
{
void *pNextPacket = GetNextPacket();
...
}
Perfectly legal C code that I write night and day. Thus:
if (void *p = func())
{
...
}
Can be written in C as well as:
{ // Just open a new scope in the middle of a function.
void *p;
if (p = func())
{
...
}
}
which for me classifies "if (void *p = func())" as C++ syntactic sugar :-D
Cheers, Dimitris |
When all else fails try common sense. |
|
|
feline
Whole Tomato Software
United Kingdom
19021 Posts |
Posted - Sep 30 2008 : 08:17:44 AM
|
Back when I was programming in pure C I used to use extra curly braces to introduce local scopes into code, to add a local variable. I tried to avoid doing this, but there were times when it was a useful solution. I don't know how common this is, but I would expect any experienced C programmer to be aware of it.
Most of our users work in C++ rather than C, which is a bit different.
More generally though, while this idea of "only suggest valid things" is interesting, it is starting to sound very complex. In general a lot of things are valid. For an "average" programmer quite a few of these things will never be used, so can be safely excluded from VA suggestion listboxes.
However different programmers will have different things they think should be excluded.
I have the feeling this idea could get over complex rather quickly |
zen is the art of being at one with the two'ness |
|
|
|
Topic |
|