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
Plorkyeran
Mar 22, 2007

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

b0lt posted:

It is when there's no way to check reference equality.
Removing reference assignment wouldn't have any effect on doctor_god's snippet.

On a related note, I love this solution for the lack of reference equality in PHP4:

quote:

Well why not add a new operator ====

[e] This is even better:
code:
function comparereferences(&$a, &$b)
{
    // creating unique name for the new member variable
    $tmp = uniqid("");
    // creating member variable with the name $tmp in the object $a
    $a->$tmp = true;
    // checking if it appeared in $b
    $bResult = !empty($b->$tmp);
    // cleaning up
    unset($a->$tmp);
    return $bResult;
}

Plorkyeran fucked around with this message at 23:28 on Jun 14, 2010

Adbot
ADBOT LOVES YOU

Munkeymon
Aug 14, 2003

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



Plorkyeran posted:

On a related note, I love this solution for the lack of reference equality in PHP4:

Clearly the more you hit = the more you really mean it.

Smugdog Millionaire
Sep 14, 2002

8) Blame Icefrog

Munkeymon posted:

Clearly the more you hit = the more you really mean it.

All that research into fuzzy logic and we could've just used PHP all along.

cliffy
Apr 12, 2002

No specific code, but the following idea:

Taking unfiltered user input and using it as an xml tag. Strings starting with numbers? No problem! Spaces? Throw them right in!

I assume it was to save the 'trouble' of writing <entity><name>hurfdurf</name></entity> or <entity name="hurfdurf"></entity>. Instead we get <hurfdurf></hurfdurf> and I seriously want to strangle someone.

necrobobsledder
Mar 21, 2005
Lay down your soul to the gods rock 'n roll
Nap Ghost
I'm going to just put out a minor coding "horror" I used to try to write in C when I was just starting out as a wee lad.

code:
if (low <= x <= upper) {
  /* do stuff */
}
Everyone kept telling me programming was math so I tried to write an expression and then programmers tell me programming isn't math :smith:

cliffy posted:

Taking unfiltered user input and using it as an xml tag. Strings starting with numbers? No problem! Spaces? Throw them right in!
There's a good number of very expensive enterprise software products I won't name that do this to support custom datatypes.

Recently, I wound up having to submit escaped / wrapped XML to a web service call because the visual programming language I've been working on sucks at arbitrary length "arrays" (they don't exist - everything's a string!) and parameter argument names are static and would have to be written in the rough coding equivalent of:
(int,string,string,string,string,string) foo(arrayElem0,arrayElem1,arrayElem2,arrayElem3,arrayElem4...) {//dostuff}

So the web service provider gave us a new call that let me take the XML I'd have given to the other call and now it looks like...
<wrappedrequestdata>
&lt;requestdata&gt;&lt;blah attrib="fuckmejesus" /&gt;&lt;/requestdata&gt;</wrappedrequestdata>

We managed to make XML-RPC even less readable through this process and take up quadruple the bandwidth (and about 25% more memory on both the client and server). Sadly, this isn't the worst case of inefficiency in our system.

I've tried to write out an EBNF for the visual language and all but every time I've looked at it, it just made me sad that I've spent 4 years of my life working on trying to improve this poo poo. I've gotta get out of this poo poo or actually make it better, ugh. loving proprietary software with no user community because of paranoid customers that refuse to ever share code.

king_kilr
May 25, 2007

necrobobsledder posted:

I'm going to just put out a minor coding "horror" I used to try to write in C when I was just starting out as a wee lad.

code:
if (low <= x <= upper) {
  /* do stuff */
}
Everyone kept telling me programming was math so I tried to write an expression and then programmers tell me programming isn't math :smith:
There's a good number of very expensive enterprise software products I won't name that do this to support custom datatypes.


Python, gently caress yeah. :eng101:

TOO SCSI FOR MY CAT
Oct 12, 2008

this is what happens when you take UI design away from engineers and give it to a bunch of hipster art student "designers"

necrobobsledder posted:

I'm going to just put out a minor coding "horror" I used to try to write in C when I was just starting out as a wee lad.

code:
if (low <= x <= upper) {
  /* do stuff */
}
Everyone kept telling me programming was math so I tried to write an expression and then programmers tell me programming isn't math :smith:
Programming is math, but that doesn't mean it uses the same weird notation as algebra.

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice
I got asked to help out on a project while the guy doing the dev work was on vacation. This is what I found. Formatting and variable names preserved as found, a couple function names and a domain changed to protect the innocent. (this is javascript)

code:
    var i;
///
// 60 lines of code later
////

    for(i=0;thelist[i];i++) {	  
 p = p + '<li class=' + ((i % 2) == 0?'listOdd':'listOdd') + ' id="'+thelist[i].MemberID+'" >';
    if ( thelist[i].State == 3 || thelist[i].State == 4 ) 
      p = p + '<div class="memberNumber" id="memberNumber">&nbsp;'+(i+1)+'&nbsp;&nbsp;</div>';
    else
      p = p + (i+1);
          if ( thelist[i].UserID != userId || originator == true) {
      	p += '<img class=removeMember name="removeMember" onclick="postMessageExecRemoveMember(\''
   +((originator==true && thelist[i].MemberID == 0)?thelist[i].UserID:thelist[i].MemberID)+
            '\');return false;" title="Remove user" src="img/phoneRemoveButton.gif">';

    }

    var cname = '';
    
    if ( thelist[i].UserID.indexOf('@somedomain.com') != -1 ) {
      l2 = 'VI #' + String(displayID);
    } else
      l2 = mainPageController.contactsToolPanel.getContactLabelByNumber(mainPageController.contactsToolPanel.removeStuff(thelist[i].UserID), true);
        if ( l2 && l2 != '' ) 
          p = p + l2;
    else if ( thelist[i].DisplayName && thelist[i].DisplayName != '' )
      p = p + thelist[i].DisplayName;
        else if ( thelist[i].UserID ) {
          p = p + thelist[i].UserID;
        }
           }
I just stared at it for a while, then took the rest of the day off.

jandrese
Apr 3, 2007

by Tiny Fistpump
This may not qualify as a horror, but it always catches people when they first see it:
code:
typedef struct
{
        uint16_t s_port;
        uint16_t d_port;
        uint16_t len;
        uint16_t cksum;
        uint8_t  data[0];
} udp_header;

TOO SCSI FOR MY CAT
Oct 12, 2008

this is what happens when you take UI design away from engineers and give it to a bunch of hipster art student "designers"

Lumpy posted:

I got asked to help out on a project while the guy doing the dev work was on vacation. This is what I found. Formatting and variable names preserved as found, a couple function names and a domain changed to protect the innocent. (this is javascript)

:psyboom:

I just stared at it for a while, then took the rest of the day off.
The Cavern of COBOL: ((i % 2) == 0?'listOdd':'listOdd')

pseudorandom name
May 6, 2007

jandrese posted:

This may not qualify as a horror, but it always catches people when they first see it:
code:
typedef struct
{
        uint16_t s_port;
        uint16_t d_port;
        uint16_t len;
        uint16_t cksum;
        uint8_t  data[0];
} udp_header;

If you aren't familiar with the struct hack, I'm not sure you deserve to be called a C programmer.

HFX
Nov 29, 2004

Lumpy posted:

I got asked to help out on a project while the guy doing the dev work was on vacation. This is what I found. Formatting and variable names preserved as found, a couple function names and a domain changed to protect the innocent. (this is javascript)

code:
    var i;
///
// 60 lines of code later
////

    for(i=0;thelist[i];i++) {	  
 p = p + '<li class=' + ((i % 2) == 0?'listOdd':'listOdd') + ' id="'+thelist[i].MemberID+'" >';
    if ( thelist[i].State == 3 || thelist[i].State == 4 ) 
      p = p + '<div class="memberNumber" id="memberNumber">&nbsp;'+(i+1)+'&nbsp;&nbsp;</div>';
    else
      p = p + (i+1);
          if ( thelist[i].UserID != userId || originator == true) {
      	p += '<img class=removeMember name="removeMember" onclick="postMessageExecRemoveMember(\''
   +((originator==true && thelist[i].MemberID == 0)?thelist[i].UserID:thelist[i].MemberID)+
            '\');return false;" title="Remove user" src="img/phoneRemoveButton.gif">';

    }

    var cname = '';
    
    if ( thelist[i].UserID.indexOf('@somedomain.com') != -1 ) {
      l2 = 'VI #' + String(displayID);
    } else
      l2 = mainPageController.contactsToolPanel.getContactLabelByNumber(mainPageController.contactsToolPanel.removeStuff(thelist[i].UserID), true);
        if ( l2 && l2 != '' ) 
          p = p + l2;
    else if ( thelist[i].DisplayName && thelist[i].DisplayName != '' )
      p = p + thelist[i].DisplayName;
        else if ( thelist[i].UserID ) {
          p = p + thelist[i].UserID;
        }
           }
I just stared at it for a while, then took the rest of the day off.

That is better then 90% of the Javascript I have to fix on a daily basis for the project I am on now. I give you one of the less stroke inducing bits of code today since it is small and not very identifying. Well maybe not 90, it is getting better... slowly.. :smith:

code:

switch(variable) {
 case undefined:
       return undefined
 case true: 
       return true;
 case false:
       return false;
}

HFX fucked around with this message at 00:20 on Jun 19, 2010

shrughes
Oct 11, 2008

(call/cc call/cc)

jandrese posted:

This may not qualify as a horror, but it always catches people when they first see it:
code:
typedef struct
{
        uint16_t s_port;
        uint16_t d_port;
        uint16_t len;
        uint16_t cksum;
        uint8_t  data[0];
} udp_header;

Especially since a feature has been built into C99 for this very purpose.

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe

Janin posted:

Programming is math, but that doesn't mean it uses the same weird notation as algebra.
The form of mathematical notation that that code attempts to replicate

(a) is a fairly natural way to express binary relations between mathematical objects,
(b) needn't be seen as having any greater connection to algebra (in either the layman's or the mathematician's use of the word) than it does to any other field in which set theory is used.

Zakalwe
May 12, 2002

Wanted For:
  • Terrorism
  • Kidnapping
  • Poor Taste
  • Unlawful Carnal Gopher Knowledge

shrughes posted:

Especially since a feature has been built into C99 for this very purpose.

Perhaps he means the zero size data array? It's a trick used in a lot of header structs where the data size is variable. The actual size of the data member is actually 0, but of course using it as an array allows you to access the data past the header.

Dijkstracula
Mar 18, 2003

You can't spell 'vector field' without me, Professor!

Zakalwe posted:

Perhaps he means the zero size data array? It's a trick used in a lot of header structs where the data size is variable. The actual size of the data member is actually 0, but of course using it as an array allows you to access the data past the header.
He does, but shrughes is saying that C99 has a feature, flexible array members, intended for this purpose

sklnd
Nov 26, 2007

NOT A TRACTOR
Because c99 implementation is complete and consistent between compiler vendors.

Right?

This is the coding horror.

pseudorandom name
May 6, 2007

Zero length arrays are a GCC extension that predates the C99 array[] syntax.

Regardless, even if you've never heard of the GCC extension, a proper C programmer should be aware of the struct hack and be able to infer the meaning of that code on seeing it.

Tikki
Aug 13, 2007
Life is too short for... No. Life is just too short!
Found this beauty today, while looking through our setup-process.. There has got to be a faster way of populating that table.
code:
desc "populate issue_number_sequences"
task :populate_issue_number_sequence => :environment do
  200000.times do |i|
    IssueNumberSequence.create!({:number => i+1}) if IssueNumberSequence.find_by_number(i+1).nil?
  end
end

Tikki fucked around with this message at 10:09 on Jun 21, 2010

tef
May 30, 2004

-> some l-system crap ->
http://blog.devinterface.com/2010/06/design-patterns-in-ruby-abstract-factory/

manero
Jan 30, 2006

Tikki posted:

Found this beauty today, while looking through our setup-process.. There has got to be a faster way of populating that table.
code:
desc "populate issue_number_sequences"
task :populate_issue_number_sequence => :environment do
  200000.times do |i|
    IssueNumberSequence.create!({:number => i+1}) if IssueNumberSequence.find_by_number(i+1).nil?
  end
end

How long does this take to run?

POKEMAN SAM
Jul 8, 2004

manero posted:

How long does this take to run?

I don't really understand that moon-language, but it doesn't sound that expensive (obviously it's a coding horror nonetheless) because it's only going to do IssueNumberSequence.create! 200,000 times (and I doubt it's expensive) and 20,000,000,000 comparisons for the find_by_number to work, assuming it's O(n). 20 billion isn't very many times for a computer to do something.

king_kilr
May 25, 2007
a) It's not doing 20 billion anythings (no idea where you got that).

b) Hitting disk 200,000 times is quite a few, I hope you've got that wrapped in a transaction ;)

Kilson
Jan 16, 2003

I EAT LITTLE CHILDREN FOR BREAKFAST !!11!!1!!!!111!

king_kilr posted:

a) It's not doing 20 billion anythings (no idea where you got that).

If IssueNumberSequence.find_by_number() is O(n) in the sequence length, then it takes approximately 20 billion comparisons to fill the sequence.

markerstore
Dec 5, 2003
Canny!

Ugg boots posted:

20 billion isn't very many times for a computer to do something.

Coding horror found.

king_kilr
May 25, 2007

Kilson posted:

If IssueNumberSequence.find_by_number() is O(n) in the sequence length, then it takes approximately 20 billion comparisons to fill the sequence.

Uhh, doubtful. It's far more likely to be O(lg n).

shrughes
Oct 11, 2008

(call/cc call/cc)

king_kilr posted:

Uhh, doubtful. It's far more likely to be O(lg n).

Did you just say lg? They never said "lg" when I was in school.

Kids these days!

Edit: Er, I mean, this is the real coding horror.

shrughes fucked around with this message at 06:21 on Jun 22, 2010

manero
Jan 30, 2006

Ugg boots posted:

I don't really understand that moon-language, but it doesn't sound that expensive (obviously it's a coding horror nonetheless) because it's only going to do IssueNumberSequence.create! 200,000 times (and I doubt it's expensive) and 20,000,000,000 comparisons for the find_by_number to work, assuming it's O(n). 20 billion isn't very many times for a computer to do something.

I was asking him literally, how much wall time it took him to run in practice, while it filled the database with stupidity.

NotShadowStar
Sep 20, 2000
code:
desc "populate issue_number_sequences"
task :populate_issue_number_sequence => :environment do
  sequences = Array.new
  for n in 2..200001
    sequences << IssueNumberSequence.new :number => n
  end
  
  begin
    IssueNumberSequence.transaction do
      for seq in sequences
        seq.save!
      end
    end
  rescue => e
    Logger.debug "Couldn't create a sequence number: #{e}"
  end
end
This assumes you have validates_uniqueness_of :number. If not then... you're completely hosed and your team needs to go back to ActiveRecord 101. Note the transaction is going to be atomic, if just one out of 200000 fails for some reason, they all fail.

The real question is why the hell are you populating 200000 blank entries.

POKEMAN SAM
Jul 8, 2004

shrughes posted:

Did you just say lg? They never said "lg" when I was in school.

Kids these days!

Edit: Er, I mean, this is the real coding horror.

We always used lg(x) when it was base 2, log(x) for base 10, and obviously ln(x) for base e. Obviously it doesn't matter for asymptotic analysis like this, but yeah.

Tikki
Aug 13, 2007
Life is too short for... No. Life is just too short!
The table only contains the numbers, it's (apparently) the fastest way of checking if an issue number is already taken.

I usually go grab some tea while it crunches. I think it takes around 10 minutes on my late-2008 MacBook.

I just realized, that the clever way to do it would to dump the table once it's done, then use that to populate it instead.

NotShadowStar
Sep 20, 2000

Tikki posted:

The table only contains the numbers, it's (apparently) the fastest way of checking if an issue number is already taken.

Real horror has been uncovered. This is seriously hosed.

Shumagorath
Jun 6, 2001

Tikki posted:

I usually go grab some tea while it crunches. I think it takes around 10 minutes on my late-2008 MacBook.
Even my worst image analysis code in undergrad didn't take ten minutes to run on a modern laptop, and I was using nested loops in Matlab.

Zhentar
Sep 28, 2003

Brilliant Master Genius

NotShadowStar posted:

Real horror has been uncovered. This is seriously hosed.

That disturbs me, and I was just working with 15-20 year old MUMPS code on a near daily basis for a couple months.

Kelson
Jan 23, 2005

Tikki posted:

The table only contains the numbers, it's (apparently) the fastest way of checking if an issue number is already taken.

I usually go grab some tea while it crunches. I think it takes around 10 minutes on my late-2008 MacBook.

I just realized, that the clever way to do it would to dump the table once it's done, then use that to populate it instead.
Invert the table; assume IssueNumber is taken unless it is in the table (vs the apparent current approach of assuming it is free unless in the table). Only IssueNumbers in use will be in the table that way, so no need to initialize 200k values.

Tikki
Aug 13, 2007
Life is too short for... No. Life is just too short!
I think there might be some confusion, as to how the issue numbers are used.

The table is only populated once (or every time we start from a clean database in development). No numbers are being deleted in production.

We have a number of events, that people buy tickets to.
If a ticket is canceled, there is a hole in the Issue number sequence for that event.
This table is then (apparently) used to very quickly find the first hole in the sequence for the next ticket...

At least that's how a coworker explained it to me. I haven't actually gone and looked at the code... I'm not sure if I dare.

pixelpusherbot
Jun 3, 2009
What happened when a junior developer forgot http://php.net/manual/en/function.strrev.php

About 4 major horrors in 10 lines. At least it worked (on anything but words with "xxx" in them).

code:
<?PHP

$string = "2010";

$char_array = str_split($string);

for($i = 0; $i < count($char_array); $i++) {
	$array_to_reverse[] = $char_array[$i];
}

$reversed_array = array_reverse($array_to_reverse);
 
$reverse_string = implode("xxx", $reversed_array);
$reverse_string = str_replace("xxx", "", $reverse_string);

echo $reverse_string;

?>

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe
code:
$reverse_string = implode("xxx", $reversed_array);
$reverse_string = str_replace("xxx", "", $reverse_string);
This bit in particular is a bit odd. Why not just use implode('', $reversed_array)?

POKEMAN SAM
Jul 8, 2004

Hammerite posted:

code:
$reverse_string = implode("xxx", $reversed_array);
$reverse_string = str_replace("xxx", "", $reverse_string);
This bit in particular is a bit odd. Why not just use implode('', $reversed_array)?

Again, coding horrors thread. Logic need not apply.

Adbot
ADBOT LOVES YOU

TOO SCSI FOR MY CAT
Oct 12, 2008

this is what happens when you take UI design away from engineers and give it to a bunch of hipster art student "designers"
I propose a new phrase "ozark bugs", meaning a bunch of errors which combine to mostly work.

Just spent four hours disentangling a mess of this; every time I fixed one error the system stopped working because another broken part of it had (by coincidence) worked only with the previous bug.

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