|
Only use a ternary where you can't use an if ; why the elephant would you ever use one in an if ?
|
|
|
|
|
Doing so is very iffy.
Keep Clam And Proofread
--
√(-1) 23 ∑ π...
And it was delicious.
|
|
|
|
|
Maybe it's just my brain but the ternary expression is clearer for me That being the case I'd never write it this way in code. Complex conditions would most likely be moved into variables like someone has answered already, i.e.:
bool tabsAreLogical = logicalTabs ? tabs_General1.cbException.Focused : tabs_General1.cbJobStatus.Focused;
if(tabsAreLogical && e.KeyCode == Keys.Up) {
}
This makes it easier to read/change later, as well as making the condition reusable later in code.
|
|
|
|
|
public class ErrorLogging
{
/// <summary>
/// Insert into error log
/// </summary>
/// <param name="errorMessage"></param>
/// <param name="errorTrace"></param>
/// <param name="errorLocation"></param>
public void insertErrorLog(string errorMessage, string errorTrace, string location)
{
int? errorID = 0;
XXXXX_DataAccess.common.XXXXX_CMSTableAdapters.XXXXXCMS_TA ta = new common.XXXXX_CMSTableAdapters.XXXXXCMS_TA();
try
{
ta.usp_ErrorLogInsert(ref errorID, errorMessage, errorTrace, location);
}
catch (Exception ex)
{
ta.usp_ErrorLogInsert(ref errorID, ex.Message, ex.StackTrace, "insertErrorLog - XXXXX_DataAccess");
}
}
}
|
|
|
|
|
I see in my crystal ball that your future will include something called a "stack overflow". I wonder what that means?
What is this talk of release? I do not release software. My software escapes leaving a bloody trail of designers and quality assurance people in its wake.
|
|
|
|
|
Where? he's not calling the method recursively, the max that can happen is a unhandled SqlException.
I'm brazilian and english (well, human languages in general) aren't my best skill, so, sorry by my english. (if you want we can speak in C# or VB.Net =p)
"Given the chance I'd rather work smart than work hard." - PHS241
"'Sophisticated platform' typically means 'I have no idea how it works.'"
|
|
|
|
|
Oops! Misread that.
What is this talk of release? I do not release software. My software escapes leaving a bloody trail of designers and quality assurance people in its wake.
|
|
|
|
|
Hm, yes i see something wrong. It looks like a programming question in The Weird and The Wonderful. Please read carefully what the red text say.
Microsoft ... the only place where VARIANT_TRUE != true
|
|
|
|
|
My colleague found this in some production code for a very well known company. I'm wondering what horrors we'll exhume next.
|
|
|
|
|
Mardy Git wrote: <param name="errorLocation"></param>
Mardy Git wrote: insertErrorLog(string errorMessage, string errorTrace, string location)
There it is!
Also, the lack of documentation for the parameters.
And the camel-case method names. (Public members should always use Pascal case).
And the lower-case namespace "common".
And the underscores in the namespaces "XXXXX_DataAccess" and "XXXXX_CMSTableAdapters".
And the underscore in the class name "XXXXXCMS_TA".
But other than that, it's fine. It's not like a database insert would fail twice in a row, is it?
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Needless use of a nullable?
Mardy Git wrote: XXXXX_DataAccess.common.XXXXX_CMSTableAdapters.XXXXXCMS_TA ta = new common.XXXXX_CMSTableAdapters.XXXXXCMS_TA();
Inconsistent use of fully qualified name.
Even I don't put empty lines at the beginning and end of a block.
|
|
|
|
|
The next gem is to be expected in the Untested Sql Procedure (usp_ ) ErrorLogInsert : in case of an exception happening there, it will check the location parameter, and if it starts with "insertErrorLog " not throw an exception but set errorID to null (that's why it's nullable). And the guy never checks the value of errorID after execution!
|
|
|
|
|
I just produced this Gem:
template <class T> struct Expectation{
T expected;
Expectation(T e)
: expected(e){}
bool Expect(const T &other){
return (other == expected);
}
};
Which shall be used as
foo firstFoo(1);
Expectation<foo> myExpectation();
foo anotherFoo(1);
if(myExpectation.Expect(anotherFoo)){
}
After I got a coffee (proud of the genius work I did) I returned to my desk an all of sudden I realised that I just could've written
foo firstFoo(1);
foo anotherFoo(1);
if(firstFoo == anotherFoo){
}
One hour left, it's definately time for me to get outta here
You know the world is going crazy when the best rapper is a white guy, the best golfer is a black guy, the tallest guy in the NBA is Chinese, the Swiss hold the America's Cup, France is accusing the U.S. of arrogance, Germany doesn't want to go to war, and the three most powerful men in America are named "Bush", "Dick", and "Colon."
|
|
|
|
|
which in addition should return false as long as its a reference type and you didn't overwrite the Equals Operator
|
|
|
|
|
Nicholas Marty wrote: you didn't overwrite the Equals Operator
I overwrote it.
Well, better: I had to implement it since QObject (the base class for objects in the Qt framework) has not implemented it (means not implementing the equals operator would've led to a compiler error, anyways).
Edit: QObject has also a private copy constructor, means that you have to implement a copy constructor yourself before doing something like
foo myFoo = GetFoo();
You know the world is going crazy when the best rapper is a white guy, the best golfer is a black guy, the tallest guy in the NBA is Chinese, the Swiss hold the America's Cup, France is accusing the U.S. of arrogance, Germany doesn't want to go to war, and the three most powerful men in America are named "Bush", "Dick", and "Colon."
|
|
|
|
|
Assuming this is C#, shouldn't the example be like this?
foo myFoo = new foo(GetFoo())
At the moment you only assign the reference, not requiring a copy constructor.
The good thing about pessimism is, that you are always either right or pleasently surprised.
|
|
|
|
|
Freak30 wrote: Assuming this is C#
It is not. It is C++.
Freak30 wrote: At the moment you only assign the reference, not requiring a copy constructor.
The foo class is inherited from QObject, where an assignment automatically invokes the copy constructor (despite you are working with pointers, off course).
You know the world is going crazy when the best rapper is a white guy, the best golfer is a black guy, the tallest guy in the NBA is Chinese, the Swiss hold the America's Cup, France is accusing the U.S. of arrogance, Germany doesn't want to go to war, and the three most powerful men in America are named "Bush", "Dick", and "Colon."
|
|
|
|
|
Don't all C++ object assignments invoke the copy constructor?
I'm brazilian and english (well, human languages in general) aren't my best skill, so, sorry by my english. (if you want we can speak in C# or VB.Net =p)
"Given the chance I'd rather work smart than work hard." - PHS241
"'Sophisticated platform' typically means 'I have no idea how it works.'"
|
|
|
|
|
I suppose they do - Except for some special cases (private copy constructor, as seen in the QObject class).
You know the world is going crazy when the best rapper is a white guy, the best golfer is a black guy, the tallest guy in the NBA is Chinese, the Swiss hold the America's Cup, France is accusing the U.S. of arrogance, Germany doesn't want to go to war, and the three most powerful men in America are named "Bush", "Dick", and "Colon."
|
|
|
|
|
Wrong asssumption, the
template <class T> struct Expectation bit gives it away.
"If you don't fail at least 90 percent of the time, you're not aiming high enough."
Alan Kay.
|
|
|
|
|
haha:
int p = 0
int i = 2
int m = i
int o = m * i
if (p = 10){
o = i;
print(o);
p++;
goto haha;
}
else
{
p++
}
i don't know what i just wrote, but yeh, have fun XD
|
|
|
|
|
Its exactly the same as if you had written:
while (true)
{
print(2);
}
Although I think that this is not code you've run. First of all "print" isn't a function (nor does it take an integer parameter if it was printf). Next, the "if" statement isn't a check (it will always be true), and it won't compile with all the missing semi-colons.
|
|
|
|
|
It may a language with which neither of us is familiar.
But, yes, more likely a language with which the poster is unfamiliar.
|
|
|
|
|
Hi
Found this Little gem in our codebase:
public static class volldepp
{
public static string getRant()
{
return "Moron";
}
}
volldepp is german and i - with my Little knowledge - would translate it to bleeding fool/moron...
it´s a "self-produced gem"...i must have been really pissed of by my own stupidity while coding...
edit: the Point is, btw, i can´t even remember writing that class...
|
|
|
|
|
And the class name isn't even capitalised...
speramus in juniperus
|
|
|
|