|
FamDav posted:^^ true. Did someone do this in production code? This is just...unacceptable.
|
# ? Sep 6, 2012 01:53 |
|
|
# ? Apr 29, 2024 10:01 |
|
Not quite as bad as (maybe I've posted this already) allocating all string buffers to MAX_PATH. Regardless of whether they are for filenames. MAX_PATH in Windows is an unbelievably immense number. Two hundred and sixty, to be exact.
|
# ? Sep 6, 2012 02:30 |
|
That is weird. Why not 255?
|
# ? Sep 6, 2012 02:36 |
|
Ensign Expendable posted:That is weird. Why not 255? Trailing dot + 3-character extension + NUL byte.
|
# ? Sep 6, 2012 02:41 |
|
Gazpacho posted:Not quite as bad as (maybe I've posted this already) allocating all string buffers to MAX_PATH. Regardless of whether they are for filenames. Its 2012, you can afford a couple hundred bytes of memory.
|
# ? Sep 6, 2012 02:44 |
|
ShoulderDaemon posted:Trailing dot + 3-character extension + NUL byte. MSDN says it's for D:\ + 256 character file name + NUL, which makes sense for Pascal strings.
|
# ? Sep 6, 2012 02:49 |
|
hobbesmaster posted:The function itself is shorter than the preprocessor directives to figure out if you have std::isnan or are using visual studio or whatever. Include math.h instead of cmath. Boom, now you know you have isnan()
|
# ? Sep 6, 2012 03:05 |
|
hobbesmaster posted:Its 2012, you can afford a couple hundred bytes of memory. Gazpacho fucked around with this message at 03:48 on Sep 6, 2012 |
# ? Sep 6, 2012 03:32 |
|
Ensign Expendable posted:Did someone do this in production code? This is just...unacceptable. So about some code we inherited through our government maintenance contract. 1. Uses negative numbers for error ( Sure, fine) 2. Uses -99999 for generic error ( Ok, but why so low...? ) 3. Does arithmetic with those errors ( What? ) We've had to track down several issues that ultimately resulted from some arithmetic being done with values that were going positive and producing erroneous results. I'm so happy I never have to touch that piece of code.
|
# ? Sep 6, 2012 04:11 |
|
Otto Skorzeny posted:Include math.h instead of cmath. Boom, now you know you have isnan() On windows its _isnan
|
# ? Sep 6, 2012 04:48 |
|
FamDav posted:So about some code we inherited through our government maintenance contract. That sounds terrible to debug. Was this somewhere without an exception mechanism, or is the programmer just that terrible?
|
# ? Sep 6, 2012 04:54 |
|
I'm going through a 5,000 line Java file (!) I am likely going to need to 'clean up' and I found this (among other things):Java code:
|
# ? Sep 6, 2012 05:01 |
|
pseudorandom name posted:MSDN says it's for D:\ + 256 character file name + NUL, which makes sense for Pascal strings. You mean C strings surely? Pascal strings prefix the string with the size rather than null terminating.
|
# ? Sep 6, 2012 11:04 |
|
Java code:
|
# ? Sep 6, 2012 14:40 |
|
Jonnty posted:You mean C strings surely? Pascal strings prefix the string with the size rather than null terminating. Well, I was thinking they would be converting Pascal strings to C strings at the syscall interface, but that doesn't make sense either with the 256 lenght (instead of 255).
|
# ? Sep 6, 2012 18:54 |
|
Have I mentioned the file formats I have to parse, for web archives? they contain http messages. One is standardized, somewhat, although everyone uses the drafts in practice to avoid iso feeds. the worse they do is skip newlines, or use different newlines from everyone else. Another is ad-hoc. you have to parse the first record body to get the information to parse the headers. oh and sometimes the space delimited headers have spaces in them too. it's a mixture of two different versions, with the same name but different headers. and these are compressed individually with gz and concatted, or concatted and then gz'd. sometimes both ways in the same file. and now i've found a file with mixed records between the two different formats. still, it isn't as bad as trying to parse http
|
# ? Sep 6, 2012 19:37 |
|
HTTP responses are no more complex than, say mail headers. It's all about the MIME, and MIME is a solved problem.
|
# ? Sep 6, 2012 20:59 |
|
McGlockenshire posted:HTTP responses are no more complex than, say mail headers. Nope, in the sense that there are two distinct formats each with slightly different rules which intermix. Yes, in the sense that most of the complexity comes from being postel-compliant. i.e reading other peoples crap output
|
# ? Sep 6, 2012 21:08 |
|
Don't try and parse the SWF format one of these days. The header that tells you how big the file is is variable-length, because of bit-packed records.
|
# ? Sep 6, 2012 21:16 |
|
hobbesmaster posted:On windows its _isnan Microsoft are odd with APIs: they refused to support NaN or ±Inf in textual form because it isn't in C98 (ref). Boost to the rescue!
|
# ? Sep 7, 2012 00:08 |
|
So say you have a MySQL table with ~40k rows, a solid handful of columns but nothing crazy, all properly indexed. And you are given a csv with about 15k rows and columns comparable to the table. Your task is to write a thing (in php let's say) that will take the csv and compare it against a 17k row subset of the table, and using some basic matching criteria create 1:1 row matches between the table and the csv, and:
This is a regular process that we run a handful of times a month (different CSVs each time, supplied from outside). It's not exactly moving around Big Data. As implemented, a modern hardware rack server running this process, while otherwise being virtually idle in terms of load, takes north of two hours. The code is very difficult to follow and has more giant loops than six flags, but I'm fairly certain the person who made this managed to somehow setup an algorithm that's greater than O(N2) time. What's worse is our business will soon be changing in ways that makes this area pretty crucial. For one we will need to rewrite it to match against the entire table and now just a ~17k row subset, and for two we are anticipating the table size to grow an order of magnitude by 2013Q1 (the CSVs get bigger but not in proportion). I'm usually a pretty firmly in the camp of "reuse don't rewrite", but for this I've got my flamethrower of code rewriting +5 at the ready when the time comes. EDIT: Oh also it's what some might call "finicky" but to the point where others might instead call it "a bug riddled minefield inside a black box" so due to that I'm rerunning it for the 3rd time today Bhaal fucked around with this message at 00:18 on Sep 7, 2012 |
# ? Sep 7, 2012 00:11 |
|
Bhaal posted:So say you have a MySQL table with ~40k rows, and you are given a csv with about 15k rows and columns comparable to the table. Your task is to write a thing (in php let's say) that will take the csv and compare it against a subset of the table, and using some basic matching criteria insert the csv into the database, in a new table with indexes. run the queries, write the database out to csv check out 13.2.6. LOAD DATA INFILE Syntax, and the mysqlimport command.
|
# ? Sep 7, 2012 01:00 |
|
Oh I know, between his approach and the best solutions there are entire oceans of improvement to cross over. He basically turned a big task / small project into a 6+ week long project with a long, fat tail of followup work resulting in something that minimally, technically works. It's the only thing he's an expert in as far as I've seen.
|
# ? Sep 7, 2012 01:06 |
|
Bhaal posted:
I'm no MySQL expert but it seems like you could get better traction by inserting the CSV into a table on its own. Then suppose you have a table like this: code:
code:
e;(sort of)f,b
|
# ? Sep 7, 2012 01:07 |
|
Yep, and we have solved that sort of problem in other areas like that, along with a 3rd table that contains all the mapping & translations needed (varies client to client). This doesn't need to be quite that complicated and is completely separate systems-wise and so we figured whatever he comes up with should work fine, so he went at it carte blanche. Lesson learned on that one.
|
# ? Sep 7, 2012 01:31 |
|
MrMoo posted:Microsoft are odd with APIs: they refused to support NaN or ±Inf in textual form because it isn't in C98 (ref). Boost to the rescue! They also don't believe in long doubles. Not that I've ever used one, but don't just silently ignore the long sitting there.
|
# ? Sep 7, 2012 06:00 |
|
Isn't the only requirement in the C++ standard that long double be at least as precise as a double?
|
# ? Sep 7, 2012 12:13 |
|
Fib posted:Isn't the only requirement in the C++ standard that long double be at least as precise as a double? Yeah, it's just like ints. Seems kinda dumb when you have that 80bit x87 hardware sitting there that's all.
|
# ? Sep 7, 2012 14:49 |
|
How to find the first name in a line containing a person's 'full name' like a boss*PHP code:
They complain that it takes me too long to make changes to this shitheap
|
# ? Sep 7, 2012 16:39 |
|
My favorite by far is $FirstName="$afulln";
|
# ? Sep 7, 2012 17:26 |
It's a good thing nobody ever has more than four words to their name, never more than one word for first name, and they always are separated by spaces.
|
|
# ? Sep 7, 2012 17:36 |
|
Multiple name fields are this year's email regexes.
|
# ? Sep 7, 2012 18:19 |
|
$FirstName, because if it involves proper nouns like a name then we certainly need to properly capitalize the variable it's stored in! *Leaves all the other variables lower case and not very descriptive.*
|
# ? Sep 7, 2012 19:30 |
|
McGlockenshire posted:HTTP responses are no more complex than, say mail headers. You seem to be implying that mail headers are simple. Go take a look at what happens when you put newlines in a quoted string inside a comment in a folded header. Mail headers are the true horror.
|
# ? Sep 7, 2012 20:31 |
|
Wrap everything in recursive XML CDATA base64 strings. Problem solved.
|
# ? Sep 7, 2012 21:16 |
|
Zombywuf posted:You seem to be implying that mail headers are simple.
|
# ? Sep 7, 2012 21:21 |
|
Munkeymon posted:How to find the first name in a line containing a person's 'full name' like a boss* Speaking of new poo poo code, we acquired a project manager who was actually a web dev previously... and I suspect he is not very good at this whole "project management" thing. Then again I don't think he's very good at the "dev" part, either: php:<? $mysql = "UPDATE remote_boxes SET idRemoteBoxes=5, boxName = 'shitheap-5', creationDate = NOW(), notes= 'Shitheap Server Numbuh 5' WHERE idRemoteBoxes=5"; $row = mysql_query($mysql); ?> And that's not even counting the other insane poo poo going on here. Updating the primary key, updating columns that are never actually used, using the fairly-standard-here creationDate column (normally creation_date, but that's another story) that's in every table as a last-heartbeat indicator... Even better, this big rewrite they want was promised by him to be done before the end of the month, and they took that as word of law. What could possibly go wrong? Oh well. Working on polishing my resume and YOTJing as soon as possible. I'm not going down with this ship.
|
# ? Sep 8, 2012 00:36 |
|
So there was a weird bug I was having with a piece of calendar code. In some places, it refused to let you search for things in the most recent year, and in some places it tried to let you search a year in advance. Seems fairly straightforward, must be an off by one error--code:
code:
code:
|
# ? Sep 8, 2012 02:50 |
|
Amarkov posted:... that's amazing and reminds me of something similar in python code:
My brain exploded.
|
# ? Sep 8, 2012 03:02 |
|
|
# ? Apr 29, 2024 10:01 |
|
PHP code:
|
# ? Sep 8, 2012 04:42 |