|
I'm sure this has been mentioned a million times, but I see this EVERY day and it winds me up.code:
|
# ? Jun 20, 2008 19:27 |
|
|
# ? May 14, 2024 03:47 |
|
Why does it wind you up? Because some_variable evaluates to true? Aren't there programming languages that only accept the boolean data type instead of a free form expression? If it was a language like that then that sort of construction would be necessary.
|
# ? Jun 20, 2008 20:06 |
|
jonnii posted:I'm sure this has been mentioned a million times, but I see this EVERY day and it winds me up. I do it because it makes my code look cleaner. I usually don't use == true for if statements whose conditions are method calls, provided that the method has a meaningful name. I'll do, for example, if (m_isOpening == true) { }
|
# ? Jun 20, 2008 20:44 |
|
I just ran into a class that has a member variable boolean m_immutable; In every loving mutator function, it tests this, and if it's true, it just returns. For example: code:
|
# ? Jun 20, 2008 21:19 |
|
Triple Tech posted:Why does it wind you up? Because some_variable evaluates to true? code:
|
# ? Jun 20, 2008 21:26 |
|
Standish posted:Because it's needlessly verbose and also because "some_variable" can evaluate to true while "some_variable == true" evaluates to false. That's pretty cool. I take it that it would have to be a type conversion or something? Could you post an example?
|
# ? Jun 20, 2008 21:29 |
|
Evis posted:That's pretty cool. I take it that it would have to be a type conversion or something? Could you post an example? It's just the way languages like C handle their if statements. Java specifically decided to not allow it to work that way because of the specter of "ambiguity".
|
# ? Jun 20, 2008 21:57 |
|
Standish posted:Because it's needlessly verbose and also because "some_variable" can evaluate to true while "some_variable == true" evaluates to false e.g. TRex EaterofCars posted:It's just the way languages like C handle their if statements. Java specifically decided to not allow it to work that way because of the specter of "ambiguity". zootm fucked around with this message at 22:07 on Jun 20, 2008 |
# ? Jun 20, 2008 22:04 |
|
See how many problems you can spot here:code:
JoeNotCharles fucked around with this message at 22:10 on Jun 20, 2008 |
# ? Jun 20, 2008 22:07 |
code:
|
|
# ? Jun 20, 2008 23:18 |
|
TRex EaterofCars posted:It's just the way languages like C handle their if statements. Java specifically decided to not allow it to work that way because of the specter of "ambiguity". I guess I missed this aspect of C since I've almost exclusively worked in C++. http://en.wikipedia.org/wiki/Boolean_datatype has even more information on it. To JoeNotCharles: based on the code I can see, WrapperClass::AllocateStuff() always returns false. Even without that, an error in the first objAlloc call would never be seen. There's also a memory leak if AllocateStuff is called twice. Edit: this really depends on what objAlloc does I guess.
|
# ? Jun 21, 2008 00:08 |
|
Evis posted:I guess I missed this aspect of C since I've almost exclusively worked in C++. http://en.wikipedia.org/wiki/Boolean_datatype has even more information on it. C++ is not immune to this.
|
# ? Jun 21, 2008 02:21 |
|
Evis posted:To JoeNotCharles: based on the code I can see, WrapperClass::AllocateStuff() always returns false. Even without that, an error in the first objAlloc call would never be seen. There's also a memory leak if AllocateStuff is called twice. Oops, I forgot to add "if (mInitialize) return false;" at the beginning. Which would take care of the memory leak, if it worked. So you can add: - mInitialize never gets set to anything - there's no reason for "err" to be a class member, since it's never used except to set lsuccess - if you're using a bool for an error code, true should mean success, not false (meaning lsuccess is misnamed) - either it should be cleaning up an aborting after each error, or there should be a comment explaining why it doesn' t do this
|
# ? Jun 21, 2008 02:56 |
|
floWenoL posted:C++ is not immune to this. Not if they're implementing bool in the same way it was done in C, but if you're using the builtin type is it still potentially a problem? I could see weirdness if there was an order of operations issue that the coder wasn't aware of. I suppose if you were doing some more explicit manipulation of memory you could run into something weird too. (I'm not really advocating using ==true, I'm really just interested in learning more about the issue)
|
# ? Jun 21, 2008 04:00 |
|
Evis posted:Not if they're implementing bool in the same way it was done in C, but if you're using the builtin type is it still potentially a problem? I could see weirdness if there was an order of operations issue that the coder wasn't aware of. I suppose if you were doing some more explicit manipulation of memory you could run into something weird too. (I'm not really advocating using ==true, I'm really just interested in learning more about the issue) What are you talking about
|
# ? Jun 22, 2008 21:31 |
|
floWenoL posted:C++ is not immune to this. Especially when you use #define bool int
|
# ? Jun 24, 2008 00:50 |
|
I just came upon this. There are about 20 different variations for different properties, all almost identical, only the property names and default values differ.code:
|
# ? Jun 24, 2008 10:42 |
|
dwazegek posted:I just came upon this. There are about 20 different variations for different properties, all almost identical, only the property names and default values differ. I actually wrote a String C# extension method to do something like this. But I think it was String.NullOrEmpty() or something.
|
# ? Jun 24, 2008 23:29 |
|
So we picked up a contract to do some work for a church organisation. Part of their donation system had this gem in it: code:
|
# ? Jun 25, 2008 05:42 |
|
Ryouga Inverse posted:I actually wrote a String C# extension method to do something like this. But I think it was String.NullOrEmpty() or something. That's not that bad, it's actually pretty understandable. The horror from that snippet is that he's copy/pasted the same 8 identical lines of code 20 times instead of just sticking it in a method and calling that method multiple times (which would drop the length of the method from ~170 lines to ~30). He's also doing the same look up every time he needs the value, instead of just doing it once and reusing that result. Another horror that can't be seen from that snippet is that the entire operation is completely wrong. If the key doesn't exist the dictionary will throw an exception, it won't return null. And if it does return null or an empty string, then it's because that's the value that has been entered, probably for a reason. The correct method would be something like: code:
|
# ? Jun 25, 2008 08:01 |
|
dwazegek posted:dict.TryGetValue I just learned something new. Thanks.
|
# ? Jun 25, 2008 10:45 |
|
dwazegek posted:If the key doesn't exist the dictionary will throw an exception, it won't return null. NameValueCollection.Item Property posted:This property returns a null reference (Nothing in Visual Basic) in the following cases: 1) if the specified key is not found; and 2) if the specified key is found and its associated value is a null reference (Nothing in Visual Basic). This property does not distinguish between the two cases.
|
# ? Jun 25, 2008 13:47 |
|
this is kinda lengthy but bear with me. So here is 250-point Division 2 problem from TopCoder SRM topcoder posted:Problem Statement for HappyCells and this is someone's solution: code:
|
# ? Jun 26, 2008 01:58 |
|
Entheogen posted:So here is 250-point Division 2 problem from TopCoder SRM
|
# ? Jun 26, 2008 02:09 |
|
Sivart13 posted:I wrote a Conway's game of life implementation in High School that looked like that and I was so proud I printed out the source and carried it around with me. how long did it take you to do it?
|
# ? Jun 26, 2008 02:10 |
|
Entheogen posted:this is kinda lengthy but bear with me.
|
# ? Jun 26, 2008 02:26 |
|
Incoherence posted:Programming contest solutions tend not to be known for their elegance. elegance has nothing to do with this. More like super-retarded brute-force approach that is not even really brute force, just brute brain
|
# ? Jun 26, 2008 02:30 |
|
Incoherence posted:Programming contest solutions tend not to be known for their elegance. I've seen some elegant solutions at programming competitions: code:
|
# ? Jun 26, 2008 02:40 |
|
Entheogen posted:how long did it take you to do it?
|
# ? Jun 26, 2008 03:00 |
|
One of my earliest programs was Tic-Tac-Toe. I never finished it because it was taking too long to code all of the possibilities.ryanmfw posted:Took a team the entire length of the competition to write (6 hours), and it didn't even pass.
|
# ? Jun 26, 2008 18:30 |
|
OneEightHundred posted:I was actually in a competition and we did that problem the right way. A team which did it the brute-force way won because ours was the only other one that actually worked, but we spelled "forty" wrong so we lost. They told us that it was incorrect and if we were programmers at, say, Microsoft, they wouldn't have allowed that to ship because of it. Don't most competitions have judge systems that demands a specific input? At least those I've participated in have been like that. Which can be pretty annoying if you're one space character off, but it seems better than the alternative you experienced.
|
# ? Jun 26, 2008 19:00 |
|
Yes, outputting incorrect output was an automatic fail. I just find it very humorous that they failed us and suggested Microsoft would rather have programmers with immaculate spelling ability than ones that write non-terrible code.
|
# ? Jun 26, 2008 20:09 |
|
OneEightHundred posted:Yes, outputting incorrect output was an automatic fail. I just find it very humorous that they failed us and suggested Microsoft would rather have programmers with immaculate spelling ability than ones that write non-terrible code. who hosted that competition? Also did they look at source code before doing their recommendations? As much as it is easy to make fun of Micro$oft, I highly doubt that it hires people like this to do any serious programing for them.
|
# ? Jun 26, 2008 20:48 |
|
Entheogen posted:who hosted that competition? Also did they look at source code before doing their recommendations? They did look at the source, the quality of the source was what the ratings were based on, but incorrect output was an automatic fail. In this case, "fourty" instead of "forty" failed, and the only team left got the right output with some copy-pasted abomination.
|
# ? Jun 26, 2008 21:10 |
|
Programming competitions should be viewed as nerd social events and really not much else, for exactly the reasons outlined here.
|
# ? Jun 26, 2008 21:12 |
|
OneEightHundred posted:One of my earliest programs was Tic-Tac-Toe. I never finished it because it was taking too long to code all of the possibilities. That's actually pretty funny because I misspelled "forty" as well which led to the same problem. We didn't get that stupid bullshit about MS though. Those competitions were so pathetic. We beat the second place team by 50% the first year. One retarded group gave up an hour into it and played a flash based version of DDR. quote:Programming competitions should be viewed as nerd social events and really not much else, for exactly the reasons outlined here. Minus the social part, yeah. I didn't go to them to meet people. It was a lot more fun crushing their hopes and dreams....
|
# ? Jun 26, 2008 21:33 |
|
I still do the ACM competitions at my school and usually score in the top 5. I still dream that next year I'll make it to the Nationals.
|
# ? Jun 26, 2008 21:48 |
|
I go to the ACM programming competitions mainly for the free food, soda, and entertainment. Watching an underclassman refuse help, get angry, demand that he get to use the submittal computer whenever he wants, and turn his code into a pile of crap is a good day in my book.
|
# ? Jun 26, 2008 23:16 |
|
MEAT TREAT posted:I still do the ACM competitions at my school and usually score in the top 5. I still dream that next year I'll make it to the Nationals. I went to nationals with my school and we sucked so bad it was really embarrassing. We didn't solve a single problem correctly in 6 hours ACM is hardcore.
|
# ? Jun 27, 2008 00:10 |
|
|
# ? May 14, 2024 03:47 |
|
more falafel please posted:What are you talking about I was actually running under the assumption that the code above written in C++ would work. I'm an idiot.
|
# ? Jun 28, 2008 01:07 |