I think my WTF per minute counter just overflowed...
-
if (count == 1) {
var charge = list.FirstOrDefault();
netAmount = charge.NetAmount ?? 0;
isSingleCharge = true;
}
else if (count == 2) // added on 15/03/2016 because some single charges
// were adjusted by query and didn't remove the declaration
{
var fcharge = list.FirstOrDefault();
var scharge = list.LastOrDefault();
var dt = Convert.ToDateTime("31 OCT 2015"); // assuming records were raised on that datebool raisedon25th = (((DateTime)fcharge.DateRaised).Date.Equals(dt.Date) || ((DateTime)scharge.DateRaised).Date.Equals(dt.Date)); bool sameAgent = fcharge.Agent.Id == scharge.Agent.Id; isSingleCharge = raisedon25th && sameAgent;
}
"If you don't fail at least 90 percent of the time, you're not aiming high enough." Alan Kay.
And they completely forget about the netAmount in the second case.
-
if (count == 1) {
var charge = list.FirstOrDefault();
netAmount = charge.NetAmount ?? 0;
isSingleCharge = true;
}
else if (count == 2) // added on 15/03/2016 because some single charges
// were adjusted by query and didn't remove the declaration
{
var fcharge = list.FirstOrDefault();
var scharge = list.LastOrDefault();
var dt = Convert.ToDateTime("31 OCT 2015"); // assuming records were raised on that datebool raisedon25th = (((DateTime)fcharge.DateRaised).Date.Equals(dt.Date) || ((DateTime)scharge.DateRaised).Date.Equals(dt.Date)); bool sameAgent = fcharge.Agent.Id == scharge.Agent.Id; isSingleCharge = raisedon25th && sameAgent;
}
"If you don't fail at least 90 percent of the time, you're not aiming high enough." Alan Kay.
-
Wow! I honestly think that's as bad as anything I've ever seen in far more years than I'd care to mention.
Whenever you find yourself on the side of the majority, it is time to pause and reflect. - Mark Twain
Yes, I sat there dumbfounded for a good few minutes after encountering this gem. I still have no idea why it exists.
"If you don't fail at least 90 percent of the time, you're not aiming high enough." Alan Kay.
-
If I understand the code fragment correctly, this sort of thing always rankled me too. Instead of finding and fixing the root cause of something, sometimes you'd see this:
if(the conditions under which bug report #n occur are true)
{
fix things up and carry on;
}Is it humanly possible to truly understand code like this? Believe me, it makes no more sense given the context.
"If you don't fail at least 90 percent of the time, you're not aiming high enough." Alan Kay.
-
if (count == 1) {
var charge = list.FirstOrDefault();
netAmount = charge.NetAmount ?? 0;
isSingleCharge = true;
}
else if (count == 2) // added on 15/03/2016 because some single charges
// were adjusted by query and didn't remove the declaration
{
var fcharge = list.FirstOrDefault();
var scharge = list.LastOrDefault();
var dt = Convert.ToDateTime("31 OCT 2015"); // assuming records were raised on that datebool raisedon25th = (((DateTime)fcharge.DateRaised).Date.Equals(dt.Date) || ((DateTime)scharge.DateRaised).Date.Equals(dt.Date)); bool sameAgent = fcharge.Agent.Id == scharge.Agent.Id; isSingleCharge = raisedon25th && sameAgent;
}
"If you don't fail at least 90 percent of the time, you're not aiming high enough." Alan Kay.
I see... They tried to make the thing future proof, and provide a possibility to seamlessly add more special cases (
count == 3
etc). But then they forgot to safeguard this code block from currently invalid values... The great handling of Dates looks like that of a special colleague of mine:Convert.ToDateTime("31 OCT 2015")
and((DateTime)fcharge.DateRaised).Date
. At least, they did not invent their ownDate.Equals
function (or did they?). And then followed by the very clear naming of a variableraisedon25th
- yeah, what's special about the 25th? Oh, nothing, that's just part of the variable name... :thumbsup:Oh sanctissimi Wilhelmus, Theodorus, et Fredericus!
-
I see... They tried to make the thing future proof, and provide a possibility to seamlessly add more special cases (
count == 3
etc). But then they forgot to safeguard this code block from currently invalid values... The great handling of Dates looks like that of a special colleague of mine:Convert.ToDateTime("31 OCT 2015")
and((DateTime)fcharge.DateRaised).Date
. At least, they did not invent their ownDate.Equals
function (or did they?). And then followed by the very clear naming of a variableraisedon25th
- yeah, what's special about the 25th? Oh, nothing, that's just part of the variable name... :thumbsup:Oh sanctissimi Wilhelmus, Theodorus, et Fredericus!
It is in the number base. OCT 31 = DEC 25 That is why programmers never know whether it is Christmas or Halloween.
-
if (count == 1) {
var charge = list.FirstOrDefault();
netAmount = charge.NetAmount ?? 0;
isSingleCharge = true;
}
else if (count == 2) // added on 15/03/2016 because some single charges
// were adjusted by query and didn't remove the declaration
{
var fcharge = list.FirstOrDefault();
var scharge = list.LastOrDefault();
var dt = Convert.ToDateTime("31 OCT 2015"); // assuming records were raised on that datebool raisedon25th = (((DateTime)fcharge.DateRaised).Date.Equals(dt.Date) || ((DateTime)scharge.DateRaised).Date.Equals(dt.Date)); bool sameAgent = fcharge.Agent.Id == scharge.Agent.Id; isSingleCharge = raisedon25th && sameAgent;
}
"If you don't fail at least 90 percent of the time, you're not aiming high enough." Alan Kay.
Wow. Since most of our business logic is in the database, we hope to fix problems there, because that means we can slip a db correction into production without having to do an app deployment. 99.99% of the time, it works out that way.
".45 ACP - because shooting twice is just silly" - JSOP, 2010
-----
You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
-----
When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013 -
And they completely forget about the netAmount in the second case.
-
if (count == 1) {
var charge = list.FirstOrDefault();
netAmount = charge.NetAmount ?? 0;
isSingleCharge = true;
}
else if (count == 2) // added on 15/03/2016 because some single charges
// were adjusted by query and didn't remove the declaration
{
var fcharge = list.FirstOrDefault();
var scharge = list.LastOrDefault();
var dt = Convert.ToDateTime("31 OCT 2015"); // assuming records were raised on that datebool raisedon25th = (((DateTime)fcharge.DateRaised).Date.Equals(dt.Date) || ((DateTime)scharge.DateRaised).Date.Equals(dt.Date)); bool sameAgent = fcharge.Agent.Id == scharge.Agent.Id; isSingleCharge = raisedon25th && sameAgent;
}
"If you don't fail at least 90 percent of the time, you're not aiming high enough." Alan Kay.
I've been using JS for the last 2-3 years. This is par for the course ;P
KeithBarrow.net[^] - It might not be very good, but at least it is free!
-
if (count == 1) {
var charge = list.FirstOrDefault();
netAmount = charge.NetAmount ?? 0;
isSingleCharge = true;
}
else if (count == 2) // added on 15/03/2016 because some single charges
// were adjusted by query and didn't remove the declaration
{
var fcharge = list.FirstOrDefault();
var scharge = list.LastOrDefault();
var dt = Convert.ToDateTime("31 OCT 2015"); // assuming records were raised on that datebool raisedon25th = (((DateTime)fcharge.DateRaised).Date.Equals(dt.Date) || ((DateTime)scharge.DateRaised).Date.Equals(dt.Date)); bool sameAgent = fcharge.Agent.Id == scharge.Agent.Id; isSingleCharge = raisedon25th && sameAgent;
}
"If you don't fail at least 90 percent of the time, you're not aiming high enough." Alan Kay.
-
I see... They tried to make the thing future proof, and provide a possibility to seamlessly add more special cases (
count == 3
etc). But then they forgot to safeguard this code block from currently invalid values... The great handling of Dates looks like that of a special colleague of mine:Convert.ToDateTime("31 OCT 2015")
and((DateTime)fcharge.DateRaised).Date
. At least, they did not invent their ownDate.Equals
function (or did they?). And then followed by the very clear naming of a variableraisedon25th
- yeah, what's special about the 25th? Oh, nothing, that's just part of the variable name... :thumbsup:Oh sanctissimi Wilhelmus, Theodorus, et Fredericus!
How about this gem then, hot from some inherited code:
CREATE VIEW [dbo].[vwSomething]
AS
SELECT dbo.AA_SomeTable.some_table_id AS parent_id,
...
CASE WHEN SUBSTRING(CONVERT(nvarchar(30), dbo.AA_SomeTable.date_created, 126), 9, 2)
+ '/' + SUBSTRING(CONVERT(nvarchar(30), dbo.AA_SomeTable.date_created, 126), 6, 2) + '/'
+ SUBSTRING(CONVERT(nvarchar(30), dbo.AA_SomeTable.date_created, 126), 0, 5)
+ ' ' + SUBSTRING(CONVERT(nvarchar(30), dbo.AA_SomeTable.date_created, 126), 12, 2) + ':'
+ SUBSTRING(CONVERT(nvarchar(30), dbo.AA_SomeTable.date_created, 126), 15, 2) IS NULL
THEN 'None'
ELSE SUBSTRING(CONVERT(nvarchar(30), dbo.AA_SomeTable.date_created, 126), 9, 2) + '/'
+ SUBSTRING(CONVERT(nvarchar(30), dbo.AA_SomeTable.date_created, 126), 6, 2)
+ '/' + SUBSTRING(CONVERT(nvarchar(30), dbo.AA_SomeTable.date_created, 126), 0, 5) + ' '
+ SUBSTRING(CONVERT(nvarchar(30), dbo.AA_SomeTable.date_created, 126), 12, 2)
+ ':' + SUBSTRING(CONVERT(nvarchar(30), dbo.AA_SomeTable.date_created, 126), 15, 2) END AS
date_details
FROM dbo.AA_SomeTable INNER JOIN
dbo.AA_Other ON dbo.AA_SomeTable.SomeTable_user_id_FK = dbo.AA_Other.user_idUmmmmmmm? (Table & Column names changed to protect the guilty)