Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Ensign Expendable
Nov 11, 2008

Lager beer is proof that god loves us
Pillbug

FamDav posted:

^^ true.

This is the kind of thing where high level developers don't know about some the very basic things afforded to them through a language and its associated library. See people using -999999 instead of INT_MIN because it was "small enough."

:stare: Did someone do this in production code? This is just...unacceptable.

Adbot
ADBOT LOVES YOU

Gazpacho
Jun 18, 2004

by Fluffdaddy
Slippery Tilde
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.

Ensign Expendable
Nov 11, 2008

Lager beer is proof that god loves us
Pillbug
That is weird. Why not 255?

ShoulderDaemon
Oct 9, 2003
support goon fund
Taco Defender

Ensign Expendable posted:

That is weird. Why not 255?

Trailing dot + 3-character extension + NUL byte.

hobbesmaster
Jan 28, 2008

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.

MAX_PATH in Windows is an unbelievably immense number. Two hundred and sixty, to be exact.

Its 2012, you can afford a couple hundred bytes of memory.

pseudorandom name
May 6, 2007

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.

Blotto Skorzany
Nov 7, 2008

He's a PSoC, loose and runnin'
came the whisper from each lip
And he's here to do some business with
the bad ADC on his chip
bad ADC on his chiiiiip

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.

In short, C++ is the coding horror.

Include math.h instead of cmath. Boom, now you know you have isnan() :q:

Gazpacho
Jun 18, 2004

by Fluffdaddy
Slippery Tilde

hobbesmaster posted:

Its 2012, you can afford a couple hundred bytes of memory.
You quite missed the point (and the sarcasm). They're string buffers. For input and stuff.

Gazpacho fucked around with this message at 03:48 on Sep 6, 2012

FamDav
Mar 29, 2008

Ensign Expendable posted:

:stare: 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.

hobbesmaster
Jan 28, 2008

Otto Skorzeny posted:

Include math.h instead of cmath. Boom, now you know you have isnan() :q:

On windows its _isnan

Ensign Expendable
Nov 11, 2008

Lager beer is proof that god loves us
Pillbug

FamDav posted:

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.

That sounds terrible to debug. Was this somewhere without an exception mechanism, or is the programmer just that terrible?

Titan Coeus
Jul 30, 2007

check out my horn
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:
System.exit(1/0);

Jonnty
Aug 2, 2007

The enemy has become a flaming star!

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.

floss
Dec 7, 2008

Information wants to be free
Java code:
ActionServiceProviderFactory

pseudorandom name
May 6, 2007

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).

tef
May 30, 2004

-> some l-system crap ->
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.

:smith:

still, it isn't as bad as trying to parse http

McGlockenshire
Dec 16, 2005

GOLLOCKS!
HTTP responses are no more complex than, say mail headers.

It's all about the MIME, and MIME is a solved problem.

tef
May 30, 2004

-> some l-system crap ->

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

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
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.

MrMoo
Sep 14, 2000

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!

Bhaal
Jul 13, 2001
I ain't going down alone
Dr. Infant, MD
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:
  • On a match, update some columns on the table row with the columns on the matching csv row
  • On a csv row that has no match, insert a new row into the table with its data
  • On a table row that has no match, update one of its columns to a runtime-supplied value

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 :suicide:

Bhaal fucked around with this message at 00:18 on Sep 7, 2012

tef
May 30, 2004

-> some l-system crap ->

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.

Bhaal
Jul 13, 2001
I ain't going down alone
Dr. Infant, MD
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.

Zamujasa
Oct 27, 2010



Bread Liar

Bhaal posted:

  • On a match, update some columns on the table row with the columns on the matching csv row
  • On a csv row that has no match, insert a new row into the table with its data
  • On a table row that has no match, update one of its columns to a runtime-supplied value

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:
main
------------------------------
|id  | value    | extra      |
------------------------------
|  1 |   391830 | .... ....  |
|  2 |   391835 | .... ....  |
|  3 | NA120906 | .... ....  |
------------------------------

csv
------------------------------
|id  | csvalue  | csvextra   |
------------------------------
|  1 |  example | .... ....  |
|  2 |   555555 | .... ....  |
|  4 |   sample | .... ....  |
------------------------------
It seems like you could make this a lot easier:

code:

UPDATE `main` m 
LEFT JOIN `csv` c
 ON m.id = c.id
SET m.`value` = IFNULL(c.`csvalue`, 'MAGIC RUNTIME VALUE HERE'), 
    m.`extra` = IFNULL(c.`extracsv`, m.`extra`) /* effective nop to not update */
;

/* Requires ID to be the same and also a primary or unique key */
/* Otherwise add a WHERE to omit rows that already exist */
INSERT IGNORE INTO main
  (id, value, extra)
SELECT id, csvalue, csvextra
FROM csv
This is just an idea, but maybe it will work better than whatever mess you have now. It really depends on how much is going on behind the scenes. :shobon:



e;(sort of)f,b

Bhaal
Jul 13, 2001
I ain't going down alone
Dr. Infant, MD
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.

hobbesmaster
Jan 28, 2008

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.

pseudopresence
Mar 3, 2005

I want to get online...
I need a computer!
Isn't the only requirement in the C++ standard that long double be at least as precise as a double?

hobbesmaster
Jan 28, 2008

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.

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



How to find the first name in a line containing a person's 'full name' like a boss*

PHP code:
$fulln=$_POST['fullname'];
$infocomfns = explode(' ', $fulln);
list($afulln,$bfulln,$cfulln,$dfulln) = $infocomfns;
$fname=rawurlencode($_POST['fullname']);
$FirstName="$afulln";
$LastName2="$bfulln~~$cfulln~~$dfulln";
$LastName=str_replace("~~"," ","$LastName2");
*not my boss thank gently caress, but of course I still end up dealing with his poo poo. Replace characters in a string and store it back into the same variable? Sorcery! Oh, and the result of rawurlencode there? Never used! Well, maybe - this is PHP after all.

They complain that it takes me too long to make changes to this shitheap :shepicide:

Golbez
Oct 9, 2002

1 2 3!
If you want to take a shot at me get in line, line
1 2 3!
Baby, I've had all my shots and I'm fine
My favorite by far is $FirstName="$afulln";

nielsm
Jun 1, 2009



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.

Doc Hawkins
Jun 15, 2010

Dashing? But I'm not even moving!


Multiple name fields are this year's email regexes.

Strong Sauce
Jul 2, 2003

You know I am not really your father.





$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.*

Zombywuf
Mar 29, 2008

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.

UraniumAnchor
May 21, 2006

Not a walrus.
Wrap everything in recursive XML CDATA base64 strings. Problem solved. :colbert:

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed

Zombywuf posted:

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.
Or even just something as simple as unicode in a header field.

Zamujasa
Oct 27, 2010



Bread Liar

Munkeymon posted:

How to find the first name in a line containing a person's 'full name' like a boss*

PHP code:
$fulln=$_POST['fullname'];
$infocomfns = explode(' ', $fulln);
list($afulln,$bfulln,$cfulln,$dfulln) = $infocomfns;
$fname=rawurlencode($_POST['fullname']);
$FirstName="$afulln";
$LastName2="$bfulln~~$cfulln~~$dfulln";
$LastName=str_replace("~~"," ","$LastName2");
*not my boss thank gently caress, but of course I still end up dealing with his poo poo. Replace characters in a string and store it back into the same variable? Sorcery! Oh, and the result of rawurlencode there? Never used! Well, maybe - this is PHP after all.

They complain that it takes me too long to make changes to this shitheap :shepicide:
What the gently caress? That looks exactly like the kind of poo poo my boss would pull. :stare:



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);
?>
If you remember the previous installments of Shitcode From Above, you might also remember that our database naming standard basically doesn't exist, but there are still some conventions. For example, id_shittable (an auto-generated primary key), shittable, shittable_id, id, or any of the above. Conspicuously absent is any and all shitTable or its camelCase brethren. (Small exception for 3 columns that are horribly misnamed and mostly not used, but that's three columns out of several hundred.) That didn't stop this guy. So now we have yet another naming scheme to keep in mind.

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... :psyboom:


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.

Amarkov
Jun 21, 2010
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:
 String[] yearList = {"2004", "2005", "2006", "2007", "2008", "2009", "2010", "2011"} 
code:
 String[] yearList = {"2007", "2008", "2009", "2010", "2011", "2012", "2013"} 
code:
 request.getSession().setAttribute("yearList", yearList)

MeruFM
Jul 27, 2010

that's amazing and reminds me of something similar

in python
code:
lastNum = 5
...
...
lastNum = "lastNum"
...
...
lastNum = lastNum + "= 5"
...
...
in production code.

My brain exploded.

Adbot
ADBOT LOVES YOU

ixnay
Jun 11, 2002

rainbow dash why are you making such a cool face?!
PHP code:
$si="insert into ps_interface_unresolvedurl value (".$interf_id.",'".$_POST["unresolved_url"]."')";

$rs=sql_exec_direct($si);
/*if($rs)
        echo "Unresolved Url value has been set";
else
        echo "Failed to set Unresolved Url";*/

sql_commit();
sql_free($rs);
Discovered this on a customer's site. Thanks, professional services! :negative:

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply