What's the f()?!
-
Here's a little gem I came across a while back.
private bool f(params object[] args) { return 0 != (int)Convert.ToUInt32(args[args.Length - 1]); }
It's employed all over the code module. Here's one place:
byte[][] outBuf = new byte[2][];
outBuf[0] = new byte[256];
outBuf[1] = new byte[256];//
// Skip some stuff
//for (int i = 0, j = 0; j < outBuf[i].Length || f(j = 0, ++i < 2); j++)
outBuf[i][j] = 0x20; //outBuf initializationIt would seem that the coder was disapointed that C# wouldn't allow abuse of the comma operator. So he substituted an argument list! Here's another place where it's used.
public bool Visible
{
get { return f(_RawData[1] & VISIBLE); }
set
{
if(f(_RawData[1] & VISIBLE) != value )
_RawData[1] ^= VISIBLE;
}
}Well, that explains the name. Is this clever or a horror?
-
Here's a little gem I came across a while back.
private bool f(params object[] args) { return 0 != (int)Convert.ToUInt32(args[args.Length - 1]); }
It's employed all over the code module. Here's one place:
byte[][] outBuf = new byte[2][];
outBuf[0] = new byte[256];
outBuf[1] = new byte[256];//
// Skip some stuff
//for (int i = 0, j = 0; j < outBuf[i].Length || f(j = 0, ++i < 2); j++)
outBuf[i][j] = 0x20; //outBuf initializationIt would seem that the coder was disapointed that C# wouldn't allow abuse of the comma operator. So he substituted an argument list! Here's another place where it's used.
public bool Visible
{
get { return f(_RawData[1] & VISIBLE); }
set
{
if(f(_RawData[1] & VISIBLE) != value )
_RawData[1] ^= VISIBLE;
}
}Well, that explains the name. Is this clever or a horror?
From that, it look like a horror. Did he comment it at all? Or just throw it together and walk away? 'Cause if he didn't, it's probably time he met Mr Ugly Stick...
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
-
Here's a little gem I came across a while back.
private bool f(params object[] args) { return 0 != (int)Convert.ToUInt32(args[args.Length - 1]); }
It's employed all over the code module. Here's one place:
byte[][] outBuf = new byte[2][];
outBuf[0] = new byte[256];
outBuf[1] = new byte[256];//
// Skip some stuff
//for (int i = 0, j = 0; j < outBuf[i].Length || f(j = 0, ++i < 2); j++)
outBuf[i][j] = 0x20; //outBuf initializationIt would seem that the coder was disapointed that C# wouldn't allow abuse of the comma operator. So he substituted an argument list! Here's another place where it's used.
public bool Visible
{
get { return f(_RawData[1] & VISIBLE); }
set
{
if(f(_RawData[1] & VISIBLE) != value )
_RawData[1] ^= VISIBLE;
}
}Well, that explains the name. Is this clever or a horror?
That is definately an absolute horror. I hate it when people think they are smart because they write such code. It is totally unmaintainable and unreadable to anyone (including the author of it a couple of weeks after he wrote it!)
-
Here's a little gem I came across a while back.
private bool f(params object[] args) { return 0 != (int)Convert.ToUInt32(args[args.Length - 1]); }
It's employed all over the code module. Here's one place:
byte[][] outBuf = new byte[2][];
outBuf[0] = new byte[256];
outBuf[1] = new byte[256];//
// Skip some stuff
//for (int i = 0, j = 0; j < outBuf[i].Length || f(j = 0, ++i < 2); j++)
outBuf[i][j] = 0x20; //outBuf initializationIt would seem that the coder was disapointed that C# wouldn't allow abuse of the comma operator. So he substituted an argument list! Here's another place where it's used.
public bool Visible
{
get { return f(_RawData[1] & VISIBLE); }
set
{
if(f(_RawData[1] & VISIBLE) != value )
_RawData[1] ^= VISIBLE;
}
}Well, that explains the name. Is this clever or a horror?
if (C++)
delete pBrain; -
Here's a little gem I came across a while back.
private bool f(params object[] args) { return 0 != (int)Convert.ToUInt32(args[args.Length - 1]); }
It's employed all over the code module. Here's one place:
byte[][] outBuf = new byte[2][];
outBuf[0] = new byte[256];
outBuf[1] = new byte[256];//
// Skip some stuff
//for (int i = 0, j = 0; j < outBuf[i].Length || f(j = 0, ++i < 2); j++)
outBuf[i][j] = 0x20; //outBuf initializationIt would seem that the coder was disapointed that C# wouldn't allow abuse of the comma operator. So he substituted an argument list! Here's another place where it's used.
public bool Visible
{
get { return f(_RawData[1] & VISIBLE); }
set
{
if(f(_RawData[1] & VISIBLE) != value )
_RawData[1] ^= VISIBLE;
}
}Well, that explains the name. Is this clever or a horror?
-
Here's a little gem I came across a while back.
private bool f(params object[] args) { return 0 != (int)Convert.ToUInt32(args[args.Length - 1]); }
It's employed all over the code module. Here's one place:
byte[][] outBuf = new byte[2][];
outBuf[0] = new byte[256];
outBuf[1] = new byte[256];//
// Skip some stuff
//for (int i = 0, j = 0; j < outBuf[i].Length || f(j = 0, ++i < 2); j++)
outBuf[i][j] = 0x20; //outBuf initializationIt would seem that the coder was disapointed that C# wouldn't allow abuse of the comma operator. So he substituted an argument list! Here's another place where it's used.
public bool Visible
{
get { return f(_RawData[1] & VISIBLE); }
set
{
if(f(_RawData[1] & VISIBLE) != value )
_RawData[1] ^= VISIBLE;
}
}Well, that explains the name. Is this clever or a horror?
What do you mean by "C# wouldn't allow abuse of the comma operator"? C# doesn't have a comma operator. A quick search pulled up this little gem (I wonder how it got copied from the MSDN foum :sigh: ): http://www.dotnetmonster.com/Uwe/Forum.aspx/dotnet-csharp/93126/C-for-loop-and-comma-operator[^] Yes, that's a horror -- the method should have a better name and it could even be made generic!
public T
LastOf
(
params object[] list
)
{
return ( (T) list [ list.Count - 1 ] ) ;
}It's still silly, but this just points up how easy it is to implement a way to get around the limitation. Come to think of it, couldn't you do it with Linq? I don't know Linq, but something like:
(new int[] { a++ , b++ }).Last
? P.S. Here's a little test of the concept:int i = 0 ; int j = 0 ; while ( (new int\[\] { i++ , j += 2 }).Last() < 10 ) { System.Console.WriteLine ( "{0} {1}" , i , j ) ; } for ( i = 0 , j = 0 ; (new int\[\] { i++ , j += 2 }).Last() < 10 ; ) { System.Console.WriteLine ( "{0} {1}" , i , j ) ; }