Loopy Discounts
-
Customer: When I apply this coupon, I get $0 discount on the order
Me: Can't repro, let me check the code.Setup the exact same data they have, set a break point, find this.
Function SetDiscountForItem(CartLine) ... For Each PromoItem in GroupOfItemsThisCouponAppliesTo LineDiscount = 0 If PromoItem.ItemNo = CartLine.ItemNo LineDiscount = CartLine.Item.Cost * Coupon.PercentageDiscount End If CartLine.LineDiscount = LineDiscount Next End Function
Do you see? DO YOU SEE?
If not, here's a hint. I've added item 123A. The items in the group that can be applied to are, in order:
ABC Qwerty 123A OompaLoompaOomBop SomeOtherFuckingItem
Do you see now?
-
You're using VB, one step
updown from PHP?
-
-
@Lorne_Kates said:
Do you see? DO YOU SEE?
Yes. You're not indenting inside the function. Shameful.
Visual Studio auto-applies its own indentation to VB.NET code. No idea why since it doesn't do this in C#.
-
Had to read it three or four times, but yes. Thanks for the hint.
-
@Lorne_Kates said:
SomeOtherFuckingItem
is the only item that will return a value other than 0 when the loop ends, assuming that isn't also 0. Sad.
-
Strongly-typed language would have caught that.
EDIT: or not I guess. Oops.
-
Developer Kudos: -1
Developer Ranking: +1 Gzillion
Developer Balls upgraded to STEEL
Developer Shame Rating: 0But then I might be wrong in thinking that only SomeOtherFuckingThing gets discounted
Fucking by @redwizard, but I CBA to edit and acknowledge it.
-
It's always hard to spot this kind of error because sometimes this is a useful pattern and you want that behavior. Not here of course :(
-
-
Yes. You're not
indentingputting four spacesinside the function. Shameful.Discourse fuckup. I've literally killed people for not indenting properly.
-
It still super-boggles me (thinking about it on the drive home) that the loop even exists. Like, what was so hard with:
If BunchaFuckingItems.ContainsByID(CartLine.ItemID) Then CartLine.Discount = ... End If
-
Whoever wrote it didn't know about
ContainsByID
? It happens. I had a co-worker at my last job who re-implementedString.Split
.
-
For flup's sake:
If CCSetup.PaddingValue <> 0 Then Order.CreditCardAuthorizedAmount = Order.OrderTotal.OrderTotalAmount * (1 + CCSetup.PaddingValue / 100) Else Order.CreditCardAuthorizedAmount = Order.OrderTotal.OrderTotalAmount End If
-
So, when you say "customer" do you mean your customer (business) or the customer that's supposed to get the discount?
Because I don't know why the business would be complaining...it's really good for their bottom line.
BTW, I saw it right away; I didn't even need the clue. Very broken; whoever wrote it managed to foreclose every one-line fix; looks like rewrite time. Especially if the code needs to account for multiple matches.
-
So, when you say "customer" do you mean your customer (business) or the customer that's supposed to get the discount?
We're a Navision shop, so everyone's a customer. It's confusing.
In this example, it's a customer of us (we provide their ecomm solution). They were setting up a new set of coupons, and the coupons had been customized for them in the past.
And, of note, any code I post is either:
- From a previous place I worked at or
- Written by a dev who no longer works here, for obvious raisins.
-
Gotta save that arithmetic overhead by doing some arithmetic and then having a branch instruction fuck up the pipeline.
-
Visual Studio auto-applies its own indentation to VB.NET code. No idea why since it doesn't do this in C#.
As everybody knows[citation needed], VB is a language that's only used (and useful) for teaching children how to code before they're ready to move on to real languages. And since they often have trouble indenting properly while still learning, Visual Studio helps them with that so they can get accustomed to it.
Failed under: All aboard the
-
Gotta save that arithmetic overhead by doing some arithmetic and then having a branch instruction fuck up the pipeline.
Lorne's 37th Law of Development:
- If you have a branch, and the same logic is applied via copy/paste to both branches, someone will fuck up the logic in one of the branches
- Corollary: If changes are applied to the logic, someone will forget to apply the changes to one of the branches
-
@Lorne_Kates said:
I've literally killed people for not indenting properly.
You're doing God's work there. May He give you money.
-
You're doing God's work there. May He give you money.
I feel I should quote this, because the amount of laughing this caused cannot be reciprocated by a single like.
-
@Lorne_Kates said:
I've literally killed people for not indenting properly.
You're doing God's work there. May He give you money.
I'm working on getting "executive decision" powers on people who intermix one-line if statements with if / end if blocks. Right now it has to go through a tribunal, which is a waste of time.
-
@Lorne_Kates said:
I've literally killed people for not indenting properly.
What if the programming language you used required you to indent the wrong way, like Python?
-
@Lorne_Kates said:
I've literally killed people for not indenting properly.
What if the programming language you used required you to indent the wrong way, like Python?
Corollary: I will murder people for using Python.
-
@Lorne_Kates said:
Discourse fuckup. I've literally killed people for not indenting properly.
Tabs or spaces though?
-
VB is a language that's only used (and useful) for teaching children how to code before they're ready to move on to real languages.
Why do you hate children? Let them waste their time watching TV. Or teach them Python so they learn something useful.
@Lorne_Kates said:
Corollary: I will murder people for using Python.
Hmm.
-
@Lorne_Kates said:
Discourse fuckup. I've literally killed people for not indenting properly.
Tabs or spaces though?
Guess. {sharpens knives}
-
-
My professor uses 2 spaces until he gets to 4 indents and then switches to one tab and repeats.
-
My professor
uses 2 spaces until he gets to 4 indents and then switches to one tab and repeatsis a monster.FTFY.
-
My professor uses 2 spaces
I quite like 3 spaces. It messes with all sorts of peoples' heads.
-
It indents nicely in
for
loops though!
-
My professor uses 2 spaces until he gets to 4 indents and then switches to one tab and repeats.
My professor does not use any spaces if possible, he uses
a
,b
, ... for variable names, and has no comments in the code. He writes some heavy mathematical code just fine. I will never hire him, not that we are interested in MATLAB script writers.
Professors rarely follow good software practices, otherwise they could pursue a more financially rewarding career path than academia.
-
Professors rarely follow good software practices, otherwise they could pursue a more financially rewarding career path than academia.
I think you underestimate how much top professors earn. OTOH, I think you overestimate just how able most professors are at writing code.
-
I quite like 3 spaces. It messes with all sorts of peoples' heads.
My tab stops are set to a sequence of prime numbers.
-
I think you underestimate how much top professors earn.
Not every professor can be top, based on definition. I have seen those who bring funds for the university, also earn more. It is more connections and namesake, than pure talent though.
OTOH, I think you overestimate just how able most professors are at writing code.
Most know how to get by, that is far from what I consider writing code.
OTOH, I claimed if they were in fact very capable coders, they would not stay in academia for long. There used to be a time that mathematics/ statistics code writers were not in high demand, that time is long passed.
-
Visual Studio auto-generated XML files (like app.config or whatnot) use 2-space tabs, ignoring the tabbing setting in Options.
That always has bugged me. If you open one and use "Auto-format" it corrects the tabbing though.
-
https://raw.githubusercontent.com/tdwtf/WtfWebApp/master/TheDailyWtf/Web.config uses CR line endings.
-
Ok?
Lubar stop with the non-sequiturs. Mostly because I have to look up how to spell "non-sequitur" every time.
-
I use tabs for indentation and spaces for alignment. I never use spaces for indentation or tabs for alignment. Some people call it "using both" which is sometimes easier to communicate.
-
Most know how to get by, that is far from what I consider writing code.
I've seen people “program” by cutting and pasting from their cheatsheet file into an interactive session. The idea of actually creating a file containing their program that they can run a second time, exactly the same as before, seems to them like it comes from another planet.Except this particular person was an astronomer. He would have paid more attention to getting it all right if it had come from another planet…
@dse said:OTOH, I claimed if they were in fact very capable coders, they would not stay in academia for long. There used to be a time that mathematics/ statistics code writers were not in high demand, that time is long passed.
There's far more to programming than writing mathematics and statistics code.
-
Not every professor can be top, based on definition.
And the ones who are top are not the ones teaching incoming undergrads their good (or not) coding habits.
-
Developer Kudos: -1
Developer Ranking: +1 Gzillion
Developer Balls upgraded to STEEL
Developer Shame Rating: 0But then I might be wrong in thinking that only SomeOtherFuckingThing gets discounted
Fucking by @redwizard, but I CBA to edit and acknowledge it.
I'm not a developer, so if I could spot the WTF in code, it BELONGS in the Side Bar WTF section.
-
I use tabs for indentation and spaces for alignment. I never use spaces for indentation or tabs for alignment. Some people call it "using both" which is sometimes easier to communicate.
You're a fucking monster. I hope you stub you big toe on something everyday. What else do you do that will scar my psyche. Comics Sans or Pappyrus. I hope you forget your coat and it starts raining.
-
@tar said:
Tabs or spaces though?
Oh god, you're one of those "it can't be both" people!
Funny, in logic class "or" means "at least one of these is true". Meaning they both can be true. Why are you assuming he's using the English definition of "or"?
Filed under: Oh, wait, this is TDWTF forum. Of course we're going to assume the worst... ;-)
Filed that under: Thinking literally today because Turkey.
-
So the correct answer to "tabs or spaces?" is "yes".
-
That is a good yesman answer. "yes" is also a good answer to the question about "sex:" in the forms. But to be polite it should be "yes please".
-
-- spaces or tabs?
-- yes please
-
tabs or spaces?
It's a moot discussion. Both are indistinguishable at a glance and ultimately confusing. Instead, I propose the only reasonable solution:
public class Program { /**/public static void Main() /**/{ /******/Console.WriteLine("Hello, world!"); /**/} }
-
E_CONTAINS_WHITESPACE
<a