|
Tell him that if it was supposed to be that way they would have called it Development Driven Test (DDT) instead
|
|
|
|
|
I'm a great fan of shorties. I'll have to miss most of the source for the usual reasons, but the last two lines made me do a double-take...
(within class FeedMetaData, C#)
virtual FeedMetaData Send(FeedValidationErrorHandler handler)
{
this.Dispose();
return this;
}
|
|
|
|
|
Return value should be FriedMetaData then :P
[ My Blog] "Visual studio desperately needs some performance improvements. It is sometimes almost as slow as eclipse." - Rüdiger Klaehn "Real men use mspaint for writing code and notepad for designing graphics." - Anna-Jayne Metcalfe
|
|
|
|
|
Another shorty, discovered moments after submitting the last, and in the same file.
Console.WriteLine(String.Format("{0}", arg));
Again, the actual example is slightly more complex, but I'd guess that there's a redundant call in there somewhere
|
|
|
|
|
Huh... not arg.ToString() ?
|
|
|
|
|
uh, no, it should be Console.WriteLine("{0}", arg); (The string.format("{0}", arg) is superflous.
The reason to use the format specifier is that arg may itself contain formatting directives such as {0}.
Silence is the voice of complicity.
Strange women lying in ponds distributing swords is no basis for a system of government. -- monty python
Might I suggest that the universe was always the size of the cosmos. It is just that at one point the cosmos was the size of a marble. -- Colin Angus Mackay
|
|
|
|
|
I first read that as FeedMeData...
|
|
|
|
|
Thank God I wasn't the only one!
|
|
|
|
|
Just like dangling pointers in C or C++
|
|
|
|
|
Is that like Premature Eja....?
Silence is the voice of complicity.
Strange women lying in ponds distributing swords is no basis for a system of government. -- monty python
Might I suggest that the universe was always the size of the cosmos. It is just that at one point the cosmos was the size of a marble. -- Colin Angus Mackay
|
|
|
|
|
I found this moving a project from visual studio 2003 to 2005.
void RemoveChars(CString& Str, const char* pChar)
{
int iLen = Str.GetLength();
if ( !iLen )
return;
char* szStr=Str.GetBuffer(iLen);
ASSERT(szStr);
WORD iDest;
WORD iSrc;
iDest=(WORD)::strcspn(szStr, pChar);
while( iDest != ::strlen(szStr) )
{
iSrc = (WORD)::strspn(szStr+iDest,pChar);
if( iSrc )
{
::strcpy_s(szStr + iDest, iLen, szStr + iSrc + iDest);
}
else
{
*(szStr+iDest) = '\0';
}
iDest=(WORD)::strcspn(szStr, pChar);
} // while
Str.ReleaseBuffer();
}
|
|
|
|
|
Not very horrific, but I think it is kind of cute:
#define UNUSED1(a) a=a
#define UNUSED2(a,b) a=a,b=b
#define UNUSED3(a,b,c) a=a,b=b,c=c
#define UNUSED4(a,b,c,d) a=a,b=b,c=c,d=d
What use could these UNUSED functions possibly have? Well, I
had to ask one of the other programmers. If you have unused
parameters in a functions parameter list, a warning occurs
"unused parameters in the parameter list" or something like
that. How to get rid of those pesky unused parameters? Call
the UNUSED function with those unused parameters. The UNUSED
function will use the unused parameters, making them used
parameters instead. Now no warning for unused parameters will
occur! Problem solved!
|
|
|
|
|
this is a common practice.
you can do either one of the following :
void MyClass::MyMethod( int i, CString& s )
{
UNUSED( i );
UNUSED( s );
}
or
void MyClass::MyMethod( int , CString& )
{
}
or
void MyClass::MyMethod( int, CString& )
{
}
|
|
|
|
|
I'm sure it's "common practice", but why have unused parameters in the first place? It's aint right, I tells ya!
|
|
|
|
|
This is not correct.
When using a given framework, one can't choose the functions signature.
Sometimes we only need to know when an event has occured, but extra information is given which we don't need.
You could hide all warnings with the #pragma directive but that is dangerous, because that will hide alsoo the correct warnings.
Therefore you should remove/comment the parameter from the function signature or use the parameter.
Most compiler will ignore the a=a line when builded so there is no speed constaint.
I preffer to comment the unused paramters out
codito ergo sum
|
|
|
|
|
BadKarma wrote: Therefore you should remove/comment the parameter from the function signature or use the parameter.
You can also get the harmless warnings.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
[my articles]
|
|
|
|
|
Ahh just start ignoring those harmless warnings...
That way lies madness!
I'm pretty sure I would not like to live in a world in which I would never be offended.
I am absolutely certain I don't want to live in a world in which you would never be offended.
Dave
|
|
|
|
|
Automatically VS2005 generated code:
int APIENTRY _tWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
UNREFERENCED_PARAMETER(hPrevInstance);
UNREFERENCED_PARAMETER(lpCmdLine);
Actually it is just deceiving compiler to avoid warnings.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
[my articles]
|
|
|
|
|
for example, in MFC :
you have a message handler for the Left button down :
afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
In my code ( or yours ) you might not need to use the nFlags parameter, so you do something like :
void CMyWindow::OnLButtonDown(UINT , CPoint point)
{
}
|
|
|
|
|
The only reason it may be "common practice" is a policy of no warnings or to eliminate irritating warnings about something that does no harm. I have never seen it done, as it is a method/function signature thing and commenting out the parameters makes more since (aka: /*parameter*/). On the plus side, modern compilers will normally optimize out self assignment, so using such macros eliminates the warning with out producing uneeded code (well it is supposed to anyway). The down side is wasting time typing in bull<blank> code that has nothing to do with what the method/function does.
It is interesting, but I do not like the idea at all.
INTP
"Program testing can be used to show the presence of bugs, but never to show their absence."Edsger Dijkstra
|
|
|
|
|
Because the parameters are part of a published and widely used API, and as a result redefining the signature isn't an option even if the parameter is no longer needed?
Otherwise [Microsoft is] toast in the long term no matter how much money they've got. They would be already if the Linux community didn't have it's head so firmly up it's own command line buffer that it looks like taking 15 years to find the desktop.
-- Matthew Faithfull
|
|
|
|
|
It is horrific indeed.
#define UNUSED(a) a=a
could suffer from side effects caused by the assignment operator.
Consider
int x = 3;
UNUSED(++x);
return x;
Which will be the value of x?
Or it could be a function that returns an unused variable, such as
int& f(int& x) {
return ++x;
}
main() {
int x = 2, y;
UNUSED(y = f(x), y);
}
and we end up in
int& f(int& x) {
return ++x;
}
main() {
int x = 2, y;
(y = f(x), y) = (y = f(x), y);
}
UNUSED should mean one will not use the parameter in subsequent operations, but won't alter the content, nor produce side-effects - so let evaluate it but don't use the result.
UNREFERENCED_PARAMETER(a) or even ((void)(a)) will do here. Those UNUSED are really pain in the a** here.
Nuclear launch detected
|
|
|
|
|
The cleanest way I've found which compiles with both /W4 and cleanly with lint, is simply to cast the variables to void, like so (C example, but works with C++)
int myfunction (int unusedarg)
{
(void) unusedarg;
return (1);
}
Mike
|
|
|
|
|
So, I'm looking at the code for one our apps, and all of the source files start with comments like:
OK, thanks for telling me that you've been following our file-naming convention. But what does the class do?
|
|
|
|
|
What about an automated tool that deletes all code having less than 10% of comments in?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
[my articles]
|
|
|
|