|
Mustach posted:If that's what you really meant, then I'm going to drop it, too. My biggest problem was with the idea that pointer-as-out was some kind of replacement for reading function documentation/asking a coworker; the rest just spun off of that and is apparently well-beaten horse. Sure. I wasn't arguing for it to be a replacement for documentation, but simply as a way to avoid having to look up the documentation less often, given that certain conditions hold (large code base, enforceable code standards, limited interaction with third-party apps, etc.). TTS gave a pretty good summary of the differences between his and my view point, and I agree that his position (that the "nullability" of a parameter is an important piece of information to keep) is a valid one. Honestly, the whole thing would be moot if C++ had some way to return multiple values. Okay let's stop derailing this thread.
|
# ? Sep 2, 2008 03:29 |
|
|
# ? May 15, 2024 17:51 |
|
boost tuples http://www.boost.org/doc/libs/1_36_0/libs/tuple/doc/tuple_users_guide.html TR1 has tuples, but that poo poo isn't really official of course. Roll on 0x
|
# ? Sep 2, 2008 03:33 |
|
floWenoL posted:Honestly, the whole thing would be moot if C++ had some way to return multiple values. Yeah, I'm not a good person to argue either side of this because I either use boost::tuple or just roll a POD struct if boost isn't allowed by the project spec.
|
# ? Sep 2, 2008 04:04 |
|
JoeNotCharles posted:
|
# ? Sep 2, 2008 16:02 |
|
KaeseEs posted:Done making GBS threads on the thread, here's a classic from php land, quoted from elsewhere: I'm curious, just because I'm not a good C coder - what's the proper way to check for overflow?
|
# ? Sep 2, 2008 19:48 |
|
ashgromnies posted:I'm curious, just because I'm not a good C coder - what's the proper way to check for overflow? Let's say you want to check if the expression "a + b" (a, b >= 0) overflows: code:
code:
Standish fucked around with this message at 21:58 on Sep 2, 2008 |
# ? Sep 2, 2008 21:28 |
|
Standish posted:a * b (a >= 0, b > 0): Wouldn't this check fail in several cases due to integer math? For example, when a = 40000 and b = 53688: A * B = 2,147,520,000 INT_MAX = 2,147,483,648 INT_MAX / b = 39999.32, which will be rounded down to 39999. Since A > 39999, it'll pass the overflow test. I'm not sure of the best way to do it either so I'll have to let someone else chime in with how to check for overflows with multiplication.
|
# ? Sep 2, 2008 22:23 |
|
Aredna posted:Wouldn't this check fail in several cases due to integer math? Standish fucked around with this message at 22:51 on Sep 2, 2008 |
# ? Sep 2, 2008 22:44 |
|
Aredna posted:INT_MAX / b = 39999.32, which will be rounded down to 39999. So? It's still greater than the "real" answer, 39999.32, which is fine.
|
# ? Sep 2, 2008 23:55 |
|
floWenoL posted:So? It's still greater than the "real" answer, 39999.32, which is fine. 39999.32 is the most you can multiply B by without overflowing. 40000 > 39999.32, so it will overflow. A > INT_MAX / B returns true when A is 40000, so the test works. 39999 < 39999.32, so it will NOT overflow. A > INT_MAX / B returns false when A is 39999, so again the test works. EDIT: oops, I thought you were replying "So?" to Standish's explanation.
|
# ? Sep 3, 2008 00:28 |
|
Oops... guess I should have looked at a test that passes before replying.
Aredna fucked around with this message at 03:03 on Sep 3, 2008 |
# ? Sep 3, 2008 02:35 |
|
Ranma4703 posted:I've been looking through a large system recently, since I just started a new co-op and I have to get caught up. This one coder (who I've never met) has stuff like this in all his classes: I do this (I'm a coding newbie), mostly because I can't figure out how to get poo poo to work correctly in VBscript. Example: code:
|
# ? Sep 3, 2008 14:32 |
|
This may be a little simple for CoC, but my boss set this as a startup script under the default domain policy yesterday. systems.txt is a text file that contains the names of the computers in our domain.code:
|
# ? Sep 3, 2008 16:08 |
|
Ranma4703 posted:I've been looking through a large system recently, since I just started a new co-op and I have to get caught up. This one coder (who I've never met) has stuff like this in all his classes: These are some of the things that exist in the code I'm working with now: code:
|
# ? Sep 4, 2008 04:36 |
|
Kilson posted:These are some of the things that exist in the code I'm working with now:
|
# ? Sep 4, 2008 08:58 |
|
Kilson posted:These are some of the things that exist in the code I'm working with now: So what is it that makes people think it's a good idea to use these constants with long-rear end names instead of typing two quotes and a character? I've seen this quite a lot and there has to be a reason, right?!
|
# ? Sep 4, 2008 18:42 |
|
BattleMaster posted:So what is it that makes people think it's a good idea to use these constants with long-rear end names instead of typing two quotes and a character? I've seen this quite a lot and there has to be a reason, right?! Increases readability!
|
# ? Sep 4, 2008 18:44 |
|
BattleMaster posted:So what is it that makes people think it's a good idea to use these constants with long-rear end names instead of typing two quotes and a character? I've seen this quite a lot and there has to be a reason, right?! Yeah you could but what if the value of five billion changes next week
|
# ? Sep 4, 2008 18:45 |
|
KaeseEs posted:Yeah you could but what if the value of five billion changes next week In the case of five billion it sort of makes sense because if you're typing 5000000 over and over again it's really easy to drop a 0 accidentally. But the constant SHOULD be named something that explains what that number is used for, not just what the number is.
|
# ? Sep 4, 2008 18:52 |
|
JoeNotCharles posted:In the case of five billion it sort of makes sense because if you're typing 5000000 over and over again it's really easy to drop a 0 accidentally. If you were using Perl you'd be able to type 5_000_000.
|
# ? Sep 4, 2008 19:54 |
|
floWenoL posted:If you were using Perl you'd be able to type 5_000_000. We can probably come up with something that lets you type num<5,000,0wait this is not going to work
|
# ? Sep 4, 2008 19:58 |
|
floWenoL posted:
For example, 5 billion has 9 zeros instead of 6.
|
# ? Sep 4, 2008 20:01 |
|
Vanadium posted:We can probably come up with something that lets you type num<5,000,0wait this is not going to work code:
code:
|
# ? Sep 4, 2008 20:07 |
|
Karanth posted:
|
# ? Sep 4, 2008 20:17 |
|
Karanth posted:
int num = big_number(5,010,000); printf("num = %d\n", num); quote:num = 5008000
|
# ? Sep 4, 2008 20:20 |
|
Flobbster posted:int num = big_number(5,010,000);
|
# ? Sep 4, 2008 20:25 |
|
Standish posted:gently caress octal seriously, has anyone ever encountered it where it wasn't causing a weird bug with leading zeroes? chmod(1)
|
# ? Sep 4, 2008 20:31 |
|
Flobbster posted:int num = big_number(5,010,000); code:
Edit: VVV You could, but then you wouldn't be able to quiz the newbie programmers every time they type a constant. Karanth fucked around with this message at 20:42 on Sep 4, 2008 |
# ? Sep 4, 2008 20:39 |
|
Karanth posted:
That won't work, but if you're sly, you can do it with that syntax using macros
|
# ? Sep 4, 2008 20:40 |
|
JoeNotCharles posted:In the case of five billion it sort of makes sense because if you're typing 5000000 over and over again it's really easy to drop a 0 accidentally. I suppose I should have been more explicit with what I was getting at, eg. "What if in two months English switches commas with apostrophes!"
|
# ? Sep 5, 2008 06:05 |
|
I recently started working as a web developer for a small company. My first task was completing and fixing a web shop built by a previous employee. Now, he had built a (mostly) fine MVC framework to handle the whole thing, but the thing was slow as hell, so we tried to find some way to optimize this. The way it works is that as soon as anyone enter the shop (it's for cellphones, by the way) we give them a session only for that visit, and store all session data in the database. As a session ID, we give them an md5 of the auto_increment value for their order (a simple mask, really, so people won't go poking around with the query string too much). First he used the brilliant code to get the last insert id code:
code:
But the best part was how he got their session from the database using the ID they sent code:
We quickly stored the md5 in a seperate field and added an index to that field, lowering the execution speed from a few seconds to a few milliseconds. Nehle fucked around with this message at 16:46 on Sep 6, 2008 |
# ? Sep 6, 2008 16:37 |
|
Nehle posted:
You don't want to do this. What if two people are accessing the website at the same time? Your two queries are not one atomic operation, meaning that two individuals' INSERT statements could fire and then their two SELECT statements (not always INSERT SELECT INSERT SELECT). Then they'd both get the same result back from LAST_INSERT_ID() which is obviously NOT what you want.
|
# ? Sep 6, 2008 20:27 |
|
Ugg boots posted:You don't want to do this. What if two people are accessing the website at the same time? Your two queries are not one atomic operation, meaning that two individuals' INSERT statements could fire and then their two SELECT statements (not always INSERT SELECT INSERT SELECT). Then they'd both get the same result back from LAST_INSERT_ID() which is obviously NOT what you want. The function returns the last ID inserted on the current connection. As long as those two users' inserts were performed on different connections, they will NOT get the same result from LAST_INSERT_ID().
|
# ? Sep 6, 2008 20:41 |
|
DaTroof posted:The function returns the last ID inserted on the current connection. As long as those two users' inserts were performed on different connections, they will NOT get the same result from LAST_INSERT_ID(). I believe you mean transaction instead of connection, but obviously each connection will be a different transaction
|
# ? Sep 6, 2008 21:41 |
|
No Safe Word posted:I believe you mean transaction instead of connection, but obviously each connection will be a different transaction The value of LAST_INSERT_ID() is still connection-specific without transactions.
|
# ? Sep 6, 2008 22:22 |
|
DaTroof posted:The function returns the last ID inserted on the current connection. As long as those two users' inserts were performed on different connections, they will NOT get the same result from LAST_INSERT_ID(). That's fair then.
|
# ? Sep 6, 2008 23:33 |
|
Nehle posted:
|
# ? Sep 7, 2008 00:24 |
|
kalleboo posted:In PHP you can even do mysql_insert_id() and avoid the whole mysql_query() bit. Of course, you should be using mysqli.... We have or own DAO wrapper for MySQl though, and I'm pretty sure I've read somewhere that mysql_insert_id() / mysqli->insert_id may give undesirable results and that doing a proper SELECT is preferred.
|
# ? Sep 7, 2008 01:15 |
|
There's more ifs in the original source but I felt this illustrated the point sufficiently:code:
|
# ? Sep 7, 2008 14:18 |
|
|
# ? May 15, 2024 17:51 |
|
Hmmcode:
|
# ? Sep 8, 2008 02:43 |