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
TSDK
Nov 24, 2003

I got a wooden uploading this one
In any case, the correct form of the test is:
code:
if ( IsPowerOfTwo( num ) )
{
    ...
That way there's no questions about what the test is actually doing, and you only ever need to look at the (num)&(num-1) shenenigans if you're in the middle of reading a function called IsPowerOfTwo - by which time it's obvious what the bit twiddling is for.

Adbot
ADBOT LOVES YOU

vapid cutlery
Apr 17, 2007

php:
<?
"it's george costanza" ?>
At one of my old jobs people didn't really understand the idea of CVS conflicts. If there was a conflict they would just open the file and delete all the "arrow things" and mark it as resolved.

Cazlab
Oct 25, 2003

php:
<?
private string ValidateFileContent()
        {
            // Validates the file content against the selected target
            // table.
            //if (StringUtil.EqualsIgnoreCase(this.DataTarget, this.TableName) == false)
            //{
            //    // Does not match target type.
            //    return "Invalid";
            //}

            // No errors.
            return null;
        }
?>
I ran into this just now. After being told to validate the file against potential EOF problems (trailing carriage returns and poo poo.)

Edit: c# not php, just did that for coloring.

Dessert Rose
May 17, 2004

awoken in control of a lucid deep dream...

Cazlab posted:

php:
<?
private string ValidateFileContent()
        {
            // Validates the file content against the selected target
            // table.
            //if (StringUtil.EqualsIgnoreCase(this.DataTarget, this.TableName) == false)
            //{
            //    // Does not match target type.
            //    return "Invalid";
            //}

            // No errors.
            return null;
        }
?>
I ran into this just now. After being told to validate the file against potential EOF problems (trailing carriage returns and poo poo.)

Edit: c# not php, just did that for coloring.

This isn't necessarily terrible. I mean, the fact that it's a string instead of a bool or throwing an exception is pretty bad, but the way they removed the check isn't terrible, since maybe a lot of code calls it. Yes, that's what search and replace is for, but maybe they wanted the code to stay for now.

It's bad, but not a horror.

Cazlab
Oct 25, 2003

Ryouga Inverse posted:

This isn't necessarily terrible. I mean, the fact that it's a string instead of a bool or throwing an exception is pretty bad, but the way they removed the check isn't terrible, since maybe a lot of code calls it. Yes, that's what search and replace is for, but maybe they wanted the code to stay for now.

It's bad, but not a horror.

At first I was willing to give the benefit of the doubt as well.
And I should have mentioned this in my post, but the only time that function is called is on page load where a variable is assigned it's value and that variable is not referenced anywhere else other than the assignment.

Al Azif
Nov 1, 2006

return0 posted:

It is however slightly incorrect in that zero is incorrectly considered to be a power of two, I think this can be used to fix that:

Two to the negative infinity! :3:

IcePotato
Dec 29, 2003

There was nothing to fear
Nothing to fear
from the forum bug reporting thread

ElDouche posted:

Seriously, the database needs to "warm up"? That is stupidest thing I've ever read, aside from Dreamhost and their excuses.

I was going to give it as pass as just someone who thought they knew more than they did, then I noticed that in this guy's profile it said "code monkey".

oh jeez.

Laserjet 4P
Mar 28, 2005

What does it mean?
Fun Shoe
Oh, Slashdot :v:

http://developers.slashdot.org/article.pl?sid=08/06/03/210224 leads to the following reply:

http://developers.slashdot.org/comments.pl?sid=572807&cid=23645679

quote:

I agree that there hasn't been enough progress in this field, just slow, incremental improvements.

I'm constantly having to compromise with the physical limitations of my database, such as having to pick and choose which attributes to delete, as the tables in my Oracle database reached it's 1000 column limit a long time ago. While these limits have forced me clean up the data and consolidate, it's a major annoyance that I shouldn't have to deal with.

MySql's 4096 column limit is enough to make me want to switch.

Hey, if you have perpendicular harddisks, you could try perpendicular database tables, right? :downs:

ashgromnies
Jun 19, 2004

IcePotato posted:

from the forum bug reporting thread


I was going to give it as pass as just someone who thought they knew more than they did, then I noticed that in this guy's profile it said "code monkey".

oh jeez.

The amount of downtime was pretty ridiculous. We have sites that get 30,000 requests per minute and don't allow that to happen. Then again, this is just a pretty small website ran by a handful of people and not a company.

chutwig
May 28, 2001

BURLAP SATCHEL OF CRACKERJACKS

Yoozer posted:

Hey, if you have perpendicular harddisks, you could try perpendicular database tables, right? :downs:

What, didn't you know joins take a long time? gently caress that noise.

ZorbaTHut
May 5, 2005

wake me when the world is saved

Yoozer posted:

Hey, if you have perpendicular harddisks, you could try perpendicular database tables, right? :downs:

I'm having a hard time coming up with any design that involves 1000 columns, unless you're doing something retarded like altering the table to add more columns whenever you need a new relation.

I will admit I did this once, before I really understood databases :(

blorpy
Jan 5, 2005

I wonder how many NULLs are in that table. That is probably one of the most sparse tables ever created.

Triple Tech
Jul 28, 2006

So what, are you quitting to join Homo Explosion?

Chain Chomp posted:

I wonder how many NULLs are in that table. That is probably one of the most sparse tables ever created.

IS_FLAG, IS_NOT_FLAG

dustgun
Jun 20, 2004

And then the doorbell would ring and the next santa would come

ZorbaTHut posted:

I'm having a hard time coming up with any design that involves 1000 columns, unless you're doing something retarded like altering the table to add more columns whenever you need a new relation.

I will admit I did this once, before I really understood databases :(

quote:

My database stores the behaviors of visitors to develop predicative modeling applications for a mid-sized online retailer. The data collection process is automated, and responses can fill up the tables very fast. I've found that takes a lot of data to accurately run a regression, as the behaviors of Internet users is pretty much random. In my system, each participant is a row, and each response is a column. Many people tend to revisit the site on a regular basis, and it is not uncommon at all for the click-throughs of certain users to exceed the 1000 column limit over a period of time.

I don't mind having to break the data up into chunks when it comes time to import the data into SPSS for analysis, however, I do get annoyed by having to store the data in chunks.

I think there is a high demand for scalability on disgusting proportions, I for one, would benefit from this.
Is his reply when someone asks what the hell he's doing with 1000 columns.

I tend not to get angry at people over the internet, but, man I really want to yell at this guy.

No Safe Word
Feb 26, 2005

Not what I've seen, but what a friend just told me about :

quote:

buddy: I think .. I may have found some of the worst PHP code ever
written
buddy: instead of just using include() ... this guy is opening the
file manually, seeking down to a certain line number,
reading in $n lines, then closing

blorpy
Jan 5, 2005

Ok, I was right, that table is incredibly sparse.

It's kind of funny that an hour's worth of reading about database theory would have eliminated this problem.

Dessert Rose
May 17, 2004

awoken in control of a lucid deep dream...

Chain Chomp posted:

Ok, I was right, that table is incredibly sparse.

It's kind of funny that an hour's worth of reading about database theory would have eliminated this problem.

I can't even figure out what he's thinking. Two minutes of asking a question would have solved his problem.

I remember when I was first trying to figure out how to make a web-based game, having only done one in mIRC script (christ, that's a coding horror all its own) and coming to the conclusion that I was probably going to have to make a separate table for each player.

I had to ask someone how I'd pull that off and she was like "wtf??? NO" and that pretty much fixed me.

blorpy
Jan 5, 2005

Ryouga Inverse posted:

I can't even figure out what he's thinking. Two minutes of asking a question would have solved his problem.

I remember when I was first trying to figure out how to make a web-based game, having only done one in mIRC script (christ, that's a coding horror all its own) and coming to the conclusion that I was probably going to have to make a separate table for each player.

I had to ask someone how I'd pull that off and she was like "wtf??? NO" and that pretty much fixed me.

For "easy" languages like web programming, I've always learned just by reading others' code and doing some basic playing with the code, and then delving into books. It removes all those reinventing the wheel obstacles.

duz
Jul 11, 2005

Come on Ilhan, lets go bag us a shitpost


Ryouga Inverse posted:

I can't even figure out what he's thinking. Two minutes of asking a question would have solved his problem.

I remember when I was first trying to figure out how to make a web-based game, having only done one in mIRC script (christ, that's a coding horror all its own) and coming to the conclusion that I was probably going to have to make a separate table for each player.

I had to ask someone how I'd pull that off and she was like "wtf??? NO" and that pretty much fixed me.

I think he's thinking he has to put each visitor into their own row and add a column for each time they click. I'm not sure how one would ever come to that `solution`.

blorpy
Jan 5, 2005

duz posted:

I think he's thinking he has to put each visitor into their own row and add a column for each time they click. I'm not sure how one would ever come to that `solution`.

It would look like this I guess

code:

..........  Click000      Click001       Click002 ...
Visitor000  index.php     NULL           NULL
Visitor001  index.php     contact.php    products.php
Visitor002  products.php  index.php      NULL
.
.
.
substitute real links for the above

:barf:

Smackbilly
Jan 3, 2001
What kind of a name is Pizza Organ! anyway?

Chain Chomp posted:

It would look like this I guess

code:

..........  Click000      Click001       Click002 ...
Visitor000  index.php     NULL           NULL
Visitor001  index.php     contact.php    products.php
Visitor002  products.php  index.php      NULL
.
.
.
substitute real links for the above

:barf:


Not only is that a retarded DB design, it also is completely useless. Nothing that a database can do that a spreadsheet (or hell a flat text file) cannot do is applicable to that layout.

ymgve
Jan 2, 2004


:dukedog:
Offensive Clock

ZorbaTHut posted:

I'm having a hard time coming up with any design that involves 1000 columns, unless you're doing something retarded like altering the table to add more columns whenever you need a new relation.

I will admit I did this once, before I really understood databases :(

It was un-elegant, but I actually had a DB with about 200 columns. Though that was for the result of lab tests, where each test gave 200 distinct values.

I'm not proud of it, though.

jarito
Aug 26, 2003

Biscuit Hider

ymgve posted:

It was un-elegant, but I actually had a DB with about 200 columns. Though that was for the result of lab tests, where each test gave 200 distinct values.

I'm not proud of it, though.

My current project has a 180+ column table for medical records since each claim is 180 fields. I argued that we could normalize it further (i.e. don't store duplicate drug descriptions and the like) but I was shot down :(.

such a nice boy
Mar 22, 2002

I'm fixing an application right now for a children's foster home. Previously, they went with the lowest bidder they could find ($20/hr, I think). That guy apparently subcontracted it out to someone who charged even less. None of them understood databases or DRY or much of anything. Here's some of their work:

code:
	if($behavior["BehaviorGroupID"]==70)
	{
		if($behavior["BehaviorID"]==148)
			$this->childimmediaterecall="intact";
		else if($behavior["BehaviorID"]==149)
			$this->childimmediaterecall="mild loss";
		else if($behavior["BehaviorID"]==150)
			$this->childimmediaterecall="moderate loss";
		else if($behavior["BehaviorID"]==151)
			$this->childimmediaterecall="severe loss";
		else 
			$this->childimmediaterecall="";
	}
Hey, some of these text fields might have more than one line of information. How could we put that into a PDF?
code:
$this->childeducational= $clientIntake[0]["EducationAssessmt"];

$this->childeducational1=substr($this->childeducational,0,100);
$this->childeducational2=substr($this->childeducational,100,100);
$this->childeducational3=substr($this->childeducational,200,100);
$this->childeducational4=substr($this->childeducational,300,100);
$this->childeducational5=substr($this->childeducational,400,100);
$this->childeducational6=substr($this->childeducational,500,100);

...

$this->Text(20,65,$this->childeducational1);
$this->Text(20,70,$this->childeducational2);
$this->Text(20,75,$this->childeducational3);
$this->Text(20,80,$this->childeducational4);
$this->Text(20,85,$this->childeducational5);
Note the misspellings. They're all over the place. I think I've seen "client" spelled 3 different ways.

The PDF rendering code is broken up logically into "RenderPage1", "RenderPage2", and so on. So if I want to delete a section, everything has to be moved "up a function" to get the pagination right.

I hate this codebase so much. The guys who wrote it have been working on it since last November.

sarehu
Apr 20, 2007

(call/cc call/cc)

return0 posted:

if( ((num-1) & (num)) == 0 ) is not a test for evenness, it's checking for if num is a power of two.

It is however slightly incorrect in that zero is incorrectly considered to be a power of two,

But zero is a power of two.

2**64 = 0.

Sewer Adventure
Aug 25, 2004
For a Facebook app I inherited there was a function to add some code to your profile, but since this code was dynamically generated there was a PHP script to do it. This script was called by a php script which used curl on it.

hey wiz
Jun 18, 2005

Someone from my team decided to check this in today:
code:
while (value.contains("&amp;amp;")) {
	int index = value.indexOf("&amp;amp;");
	value = value.substring(0,       index+1) + 
		value.substring(index+5, value.length());
}
this.value = value;
Bonus point if you can spot the bug.

this.value = value.replaceAll("&amp;", "&");

hey wiz fucked around with this message at 03:50 on Jun 10, 2008

JoeNotCharles
Mar 3, 2005

Yet beyond each tree there are only more trees.
No, I don't see it. What's the bug?

EDIT: oh, yeah, index.length(). Easy to miss for a human - shouldn't the compiler catch that, though?

JoeNotCharles fucked around with this message at 03:00 on Jun 10, 2008

dustgun
Jun 20, 2004

And then the doorbell would ring and the next santa would come
index.length() should be value.length() ?

notfred
Dec 1, 2005

hey wiz posted:

Someone from my team decided to check this in today:
code:
while (value.contains("&amp;amp;")) {
	int index = value.indexOf("&amp;amp;");
	value = value.substring(0,       index+1) + 
		value.substring(index+5, value.length());
}
this.value = value;
Bonus point if you can spot the bug.

this.value = value.replaceAll("&amp;", "&");

While that's not ideal code, it's hardly a horror. It looks a lot like everything every C programmer ever wrote in javascript.

hey wiz
Jun 18, 2005

dustgun posted:

index.length() should be value.length() ?
fixed

JoeNotCharles posted:

No, I don't see it. What's the bug?

EDIT: oh, yeah, index.length(). Easy to miss for a human - shouldn't the compiler catch that, though?
look what happens when value = "&amp;amp;" or "&amp;amp;amp;". Granted it's not a big issue but it's still incorrect.

ashgromnies
Jun 19, 2004
Who would have thought that this code would have resulted in issues?

code:
my $user = getUser();

if ($user) {
  doStuff();
} else {
  $user = getUser();
  return 0 if ( !$user );
}
and most of it is equally unreadable... blargh.

MrMoo
Sep 14, 2000

ashgromnies posted:

and most of it is equally unreadable... blargh.

It leans more towards retarded than unreadable, quite a few people skip using unless but it's a bit sill considering the post-conditional check.

ashgromnies
Jun 19, 2004

MrMoo posted:

It leans more towards retarded than unreadable, quite a few people skip using unless but it's a bit sill considering the post-conditional check.

Well it makes it unreadable because I pared it down a little. There are big ol' chunks of code inside those if-else blocks that you have to read to... then you realize the code in the else block won't do anything because the second line is "return if the condition that got me here is still false".

If not user.. try harder to get the user! :downs:

Rusty Lead Pipe
Sep 9, 2003
Worthless Misogynist
Old QuickBasic program:
code:
score=100
OPEN "tmp.tmp" FOR OUTPUT AS #1
PRINT #1, score
CLOSE #1
OPEN "tmp.tmp" FOR INPUT AS #1
INPUT #1, cScore$
CLOSE #1
PRINT "Your score is" + cScore$
Forgive any syntax, as I am recalling it from memory, but this was how I converted integers into strings before I found the lovely INT() and STR() functions. I was only 12 or 13, but thought "I guess that's why all my Sierra games grind the harddrive so much!"

Zombywuf
Mar 29, 2008

This one from my previous job just floated into my mind:
code:
template<class T>
void free(void *pointer) {
  delete (T *)pointer;
}
It's pretty representative. Well actually it only covers a tiny portion of the horror, like using skiplists as a way to store multi GB indexes on disk. That, and storing url encoded argument lists in DB tables instead of adding more columns. Also there was one giant xref table that handled all m to n mappings between tables. There was also this.

Randomosity
Sep 21, 2003
My stalker WAS watching me...
My boss found this today in our app.

code:
if( is_ipLogin ){
         auth.setSession_id( getLoginSessionId( returnHash.get( "user_id" ),returnHash.get( "contract_id" ),returnHash.get( "status_id" ), true ) );
} else {
         auth.setSession_id( getLoginSessionId( returnHash.get( "user_id" ), returnHash.get( "contract_id" ),returnHash.get( "status_id" ), false ) );
}	
Edit: Typo trying to format.

Randomosity fucked around with this message at 16:11 on Jun 13, 2008

JoeNotCharles
Mar 3, 2005

Yet beyond each tree there are only more trees.
Was the . vs , typo in the original, or did you make that just now?

npe
Oct 15, 2004
Today's horror is that I'm still arguing with people about why you can't delimit a file with literal 0xFE bytes when you want the delimited data to contain utf8 multibyte characters.

A couple of people have now actually said "...but I thought all bytes were valid utf8?" :psyduck:

Adbot
ADBOT LOVES YOU

JoeNotCharles
Mar 3, 2005

Yet beyond each tree there are only more trees.

yaoi prophet posted:

Today's horror is that I'm still arguing with people about why you can't delimit a file with literal 0xFE bytes when you want the delimited data to contain utf8 multibyte characters.

You mean CAN, right? 0xFE and 0xFF aren't valid in UTF-8, which is why they're good markers for UTF-16 data.

Can the delimited data contain U+0000? If not, I'd just use 0x00 - it's clearer, UTF-8 is guaranteed never to use a 0 byte anywhere except the representation of U+0000, and it makes it less likely some one will look at your stream of UTF-8-plus-0xFE-delimiters and conclude it's UTF-16 because part of a BOM is present. (On the other hand, it means you have to be careful not to treat it as a 0-terminated string.)

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