|
Vanadium posted:This "*_ptr is haaaard, man" stuff is why most C++ people need to use Rust instead I'm sure a place that bans *_ptr will think highly of it. (Nobody here said they were hard)
|
# ? Aug 4, 2014 19:02 |
|
|
# ? May 17, 2024 02:01 |
|
Scaramouche posted:Not quite the horror of C pointers (which is kind of a horror in itself) but I've been doing some client work that involves importing Purchase Orders from a large online marketplace. Tucked away in the documentation is: Is there any assurance that PO numbers are unique even within the same day if they can be duplicated between days?
|
# ? Aug 5, 2014 06:10 |
I'm hoping it cycles through a number sequence then goes back to 0 when it hits an upper limit, one that would not normally be reached within a day, or week or year. But since this is the coding horrors thread, I'll assume that each PO is just given a random number.
|
|
# ? Aug 5, 2014 17:40 |
|
Well the POs are 7 digits, the leading number can be 0, and they go up incrementally, so that's a number space of 9 or 10 million I guess. It's wrapped around once in a 9 month period. Just seems weird; how hard is it to guarantee uniqueness? Amazon somehow does it across several countries with a much larger number of orders, albeit with way harder to remember numbers (3-7-7 or XXX-YYYYYYY-ZZZZZZZ). Just introduce 1-3 character fields to the 7 digits and you're probably gold.
|
# ? Aug 5, 2014 18:07 |
|
This is an IValueConverter called NaNToStringEmptyConverter.code:
not
|
# ? Aug 5, 2014 21:11 |
|
Returns the heading to render but if parameter is "ConvertZeroHeading" then it returns a string and returns "360" instead of "000" if value is less than 0.5 because that's how headings are rendered.
|
# ? Aug 5, 2014 21:34 |
|
If I worked with someone who wrote nested, ternary ifs I wold be fired almost immediately for doing a completely inappropriate amount of yelling.
|
# ? Aug 6, 2014 00:36 |
|
That sort of yelling is going to be the reason I get fired.
|
# ? Aug 6, 2014 00:51 |
|
Mr. Crow posted:
|
# ? Aug 6, 2014 01:50 |
|
Sedro posted:Oh, so that's how booleans work I always slowly shake my head when I see that.
|
# ? Aug 6, 2014 02:01 |
|
That looks like whoever wrote it was high on some bad Scheme at the time.
|
# ? Aug 6, 2014 02:36 |
|
Corla Plankun posted:If I worked with someone who wrote nested, ternary ifs I wold be fired almost immediately for doing a completely inappropriate amount of yelling. I really like chaining ternaries if they're formatted properly. code:
|
# ? Aug 6, 2014 04:25 |
|
Sedro posted:Oh, so that's how booleans work Don't get caught writing code like this. Just use my handy function: code:
Dr. Stab fucked around with this message at 04:46 on Aug 6, 2014 |
# ? Aug 6, 2014 04:43 |
|
Dr. Stab posted:Don't get caught writing code like this. Just use my handy function:
|
# ? Aug 6, 2014 05:16 |
|
JavaScript is easymode for this thread. But every now and then, you find something "extra" special. date = new Date(2013,08,12); This is: a) Illegal, because the 0 prefix specifies octal, and 8 isn't an octal digit. b) Really means 2013-09-12, because unlike days, JS months are 0-indexed. c) Used in so many sites that browsers have to keep supporting it. Of course, you can argue that JS itself is the horror for the weird indexing, but why oh why would you write dates as "2013-01-01" when *it actually means something different anyway*.
|
# ? Aug 6, 2014 09:08 |
|
Skuto posted:JavaScript is easymode for this thread. But every now and then, you find something "extra" special. The early edict to ape Java's DateTime APIs are going to be painful unto the end of days. Even at 20 I knew better than to accept the project from my kindly manager to fix the Netscape implementation. (The handy rule is "if you would use it as an index into an array of strings to display, it's zero-based"]: month, day-of-week, etc.) Octal went away in ES5 though, no?
|
# ? Aug 6, 2014 09:25 |
|
Subjunctive posted:Octal went away in ES5 though, no? Only in strict mode. In ES6 it's back with different prefixes, one of which I'm going to mention because it's appropriate here: 0O. (Admittedly I can't think of a case in which that would cause bugs, no matter how silly it looks) Maybe you're thinking of parseInt enforcing base10 in ES5? The problem is the ES6 spec claims the code in the previous post is illegal. On the internet, this means the spec is wrong, because for sure nobody is going to fix their website. What makes it so grating is that the uses are mostly the date example given, so they're are not just wrong, they're downright stupid, misguided, and in some cases likely subtle bugs of their own. As I said, JavaScript is an easy punching bag, but this one is another level of "extra-special".
|
# ? Aug 6, 2014 10:27 |
|
Usually its a good idea to use a date time library in any language, but that's especially the case in JavaScript. new Date() is just an unintuitive, verbose mess.
|
# ? Aug 6, 2014 10:30 |
|
Yeah, I was thinking of parseInt. The 08 extension is still legal under the extensibility section, but I wonder if we'll see octal actually drop. Breaking changes aren't impossible, and ES6 is a descendent of ES5-strict so there will be some already.
|
# ? Aug 6, 2014 10:36 |
|
Ithaqua posted:I always slowly shake my head when I see that. We have 27 pages of search results on our code indexer for the search term "? true : false;".
|
# ? Aug 6, 2014 11:25 |
|
PIGEOTO posted:We have 27 pages of search results on our code indexer for the search term "? true : false;". At least you can fix it easily.
|
# ? Aug 6, 2014 11:29 |
|
GrumpyDoctor posted:That looks like whoever wrote it was high on some bad Scheme at the time. The best / worst part is that it was originally a reasonable class (oddly specific but whatever), doing a simple Double.IsNaN(value) ? String.Empty : value; and then the rest of the abomination was added within the last 3 months. We have mandatory code reviews and no QC. That thing passed two code reviews
|
# ? Aug 6, 2014 14:19 |
|
PIGEOTO posted:We have 27 pages of search results on our code indexer for the search term "? true : false;". It is possible, depending on language, that some boolean-ish value needs to be coerced to an actual boolean. For example, in Objective-C (and this anecdote belongs in this thread for one reason or another), the boolean type used to be a typedef'd char, with the values YES and NO defined as 1 and 0. So you could return something like 17 as a boolean, and since it's just C it works when you do if (myBoolValuedSeventeen), but as soon as some joker tried if (myBoolValuedSeventeen == YES) they hosed themselves. The competent library writer would thus make sure they returned YES or NO. Obviously there are superior ways to coerce a boolean than abusing the ternary operator, but a blind find/replace might not do wonders for your bug count.
|
# ? Aug 6, 2014 18:24 |
|
pokeyman posted:For example, in Objective-C (and this anecdote belongs in this thread for one reason or another), the boolean type used to be a typedef'd char, with the values YES and NO defined as 1 and 0. So you could return something like 17 as a boolean, and since it's just C it works when you do if (myBoolValuedSeventeen), but as soon as some joker tried if (myBoolValuedSeventeen == YES) they hosed themselves. UGGHHHHHHHHH
|
# ? Aug 6, 2014 18:26 |
|
C booleans led to such crazy things.
|
# ? Aug 6, 2014 18:37 |
|
pokeyman posted:It is possible, depending on language, that some boolean-ish value needs to be coerced to an actual boolean. For example, in Objective-C (and this anecdote belongs in this thread for one reason or another), the boolean type used to be a typedef'd char, with the values YES and NO defined as 1 and 0. So you could return something like 17 as a boolean, and since it's just C it works when you do if (myBoolValuedSeventeen), but as soon as some joker tried if (myBoolValuedSeventeen == YES) they hosed themselves. The competent library writer would thus make sure they returned YES or NO. "used to be" (also, it's a signed char) hobbesmaster posted:C booleans led to such crazy things. !!x is the best idiom ever
|
# ? Aug 6, 2014 18:44 |
|
Who writes "x == true" anyway, when in every widely used language that means exactly the same as just "x"?
|
# ? Aug 6, 2014 18:48 |
|
b0lt posted:"used to be" I don't really get why people even use BOOL in any new objective-c code written in the last decade or so.
|
# ? Aug 6, 2014 18:51 |
|
Soricidus posted:Who writes "x == true" anyway, when in every widely used language that means exactly the same as just "x"? It parallels "false == x"
|
# ? Aug 6, 2014 19:00 |
|
Soricidus posted:Who writes "x == true" anyway, when in every widely used language that means exactly the same as just "x"? Someone hasn't spent enough time around stupid C++ operator overloading.
|
# ? Aug 6, 2014 19:27 |
|
Soricidus posted:Who writes "x == true" anyway, when in every widely used language that means exactly the same as just "x"?
|
# ? Aug 6, 2014 19:29 |
|
Bonfire Lit posted:Except it doesn't in Python, C, Ruby, Javascript, etc. Hmm? == is type-converting in JS, and IIRC is defined as the same ToBoolean operation used in if. What's a case where C would let it compile but give a different answer?
|
# ? Aug 6, 2014 19:36 |
|
Subjunctive posted:Hmm? == is type-converting in JS, and IIRC is defined as the same ToBoolean operation used in if. code:
|
# ? Aug 6, 2014 19:39 |
|
That's an argument *against* writing == true, though.
|
# ? Aug 6, 2014 19:52 |
|
b0lt posted:(also, it's a signed char) It was once just char, and unless you set a compiler flag it ends up the same thing, so... good point I guess?
|
# ? Aug 6, 2014 19:54 |
|
Skuto posted:That's an argument *against* writing == true, though.
|
# ? Aug 6, 2014 19:57 |
|
I wrote if var == true { ... } in Swift recently for checking an optional bool, but then concluded that looked dumb and replaced it with if var ?? false { ... }.
|
# ? Aug 6, 2014 20:20 |
|
Bonfire Lit posted:Except it doesn't in Python, C, Ruby, Javascript, etc. Allow me to rephrase it, then, for the benefit of literal-minded pedants: Who, ignoring newcomers unfamiliar with standard idioms, discounting the possibility that bad coding standards might mandate the use of unidiomatic code, and ignoring a handful of unusual edge cases when one might actually care about the distinction between "true" and other values which evaluate to true in a boolean context, writes "x == true" when in the context of a conditional expression, i.e. the only situation in which the vast majority of programmers will ever check whether a value is "true" or "false", it Soricidus fucked around with this message at 20:32 on Aug 6, 2014 |
# ? Aug 6, 2014 20:29 |
|
Plorkyeran posted:I wrote if var == true { ... } in Swift recently for checking an optional bool, but then concluded that looked dumb and replaced it with if var ?? false { ... }. Ooh, this is a good idea. I'm going to use it if I find myself in this situation in the C# code I have to write.
|
# ? Aug 6, 2014 22:23 |
|
|
# ? May 17, 2024 02:01 |
|
Subjunctive posted:Hmm? == is type-converting in JS, and IIRC is defined as the same ToBoolean operation used in if. If anybody's interested, in JS, for example: code:
code:
|
# ? Aug 6, 2014 22:25 |