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
baquerd
Jul 2, 2007

by FactsAreUseless

npe posted:

Dear Penthouse:

I never thought it would happen to me. For years, I've been reading sordid tales of the "for case" paradigm, but I never thought they actually happened! But today, I found this in svn...

I'm not familiar with VB, but is the solution to store a pointer to the objects in an array I assume?

Adbot
ADBOT LOVES YOU

Tad Naff
Jul 8, 2004

I told you you'd be sorry buying an emoticon, but no, you were hung over. Well look at you now. It's not catching on at all!
:backtowork:

Wheany posted:

code:
row = table.insertRow(-1);
cell = row.insertCell(-1);
cell.colSpan = 2;
div = document.createElement('div');
div.appendChild(document.createElement('br'));
cell.appendChild(div);
Much better (and clearer and easier to maintain) than, say
code:
html += '<tr><td colspan="2"><div><br></div></td></tr>';

Hey now, never mix presentation and logic, that can be very confusing!

php:
<?
    public static function weeaboo() {
        $obj = (anObject::getCurrent()->isChild())
            ? anObject::getCurrent()->getParent() : anObject::getCurrent();

        $dxml = new myDOMDocument('1.0', 'utf-8');
        $dxml->loadXML('<form/>');
        $dxml->documentElement->setAttribute('method', 'get');
        $dxml->documentElement->setAttribute(
            'action', trim(dirname($_SERVER['PHP_SELF']), '/')
        );

        $sel = $dxml->createElement('select');
        $sel->setAttribute('onchange',
            sprintf("window.location = '/%s/%s%s/' + this.value",
                trim(dirname($_SERVER['PHP_SELF']), '/'),
                (dmTEConfig::getInstance()->isRewriteEnabled()) ? '' : '?r=',
                trim(anObject::getCurrent()->getAlias(), '/')));

        foreach ($obj->getChildren() as $c) {
            $opt = $dxml->createElement(
                'option', dmString::websafe($c->getMetadata('title')));
            $opt->setAttribute('value', $c->getPtr());
            if ($c->getPtr() == anObject::getCurrent()->getPtr()) {
                $opt->setAttribute('selected', 'selected');
            }
            $sel->appendChild($opt);
        }

        $dxml->documentElement->appendChild($sel);
        return $dxml->saveXML($dxml->documentElement);
    }
?>

Fiend
Dec 2, 2001
Wait there's such a thing as a repeater? Why don't you implement my control that displays a single business object. Yes I know this 600 lines of code is for displaying a single object and generates 14-20 lines of HTML source code! Quit changing the subject:
code:
// Please note the div & img objects are classes derived from HtmlGenericControl and HtmlImage to make this code easier to read.  
div div = null;
div root = new div() { cssClass = "rootNode" };
this.Controls.Add(root);
div = new div() { cssClass = "name" };
div.Controls.Add(new HyperLink() 
{ 
	CssClass = string.Empty, 
	Text = classObj.longName, 
	NavigateUrl =  string.Format("/servicearea/info.aspx?id={0}", classObj.id) 
});
root.Controls.Add(div);
root.Controls.Add(new div() 
{ 
	cssClass = "displayRate", 
	InnerHtml = string.Format("<span class=\"title\">from</span> <span class=\"value\">{0:c}</span>", classObj.displayRate) 
});
div = new div() { cssClass = "thumbnailimage" };
div.Controls.Add(new img() 
{ 
	Src = string.Format("/{0}", classObj.thumbnail), 
	Alt = classObj.shortName, navigateUrl = string.Format("/servicearea/info.aspx?ID={0}", classObj.id) 
});
root.Controls.Add(div);
string description = classObj.description;
div = new div() { cssClass = "description" };
// THIS GOES ON FOR 600 LINES!
Mind you, this is how we control the layout of properties of a class in a repeater. Why? Well, we don't want to require our junior web developers to know HTML and instead just have them do something like this to generate a list of class objects in the UI!
code:
<business:classObjectRepeater runat="server" id="classObjRepeater" />

// classObjectRepeater code behind magic!
protected override void OnInit(EventArgs e)
{
	this.DataSource = classObjCollection; // passed by page logic
	this.DataBind();
	this.ItemDataBound += new RepeaterItemEventHandler(classList_ItemDataBound);
}

protected void classList_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
	classObj theClass = ((classObj)e.Item.DataItem);
	classNode cn = new classNode()
	{
		classObj = theClass
	};
	this.Controls.Add(cn);
}
Oh wait... this is going to be displayed on 10 different sites where certain properties will appear in radically different areas or omitted altogether?

Well make sure the junior developers understand the CSS box model.

That won't work? Let me make 9 more rendering methods to control the layout for each of those sites and add a switch statement in the classNode's constructor so it displays differently!

Opinion Haver
Apr 9, 2007

Dicky B posted:

That is truly tragic.

:911:

11/18 NEVER FORGET

bobthecheese
Jun 7, 2006
Although I've never met Martha Stewart, I'll probably never birth her child.
I just found this today.
php:
<?
    function getSettings() {
        $query = "SELECT * FROM `system_settings` LIMIT 1";

        $result = mysql_query($query);
        $row = mysql_fetch_row($result);
            $s['1']= $row[0];
            $s['2']= $row[1];
            $s['3']= $row[2];
            $s['4']= $row[3];
            $s['5']= $row[4];
            $s['6']= $row[5];
            $s['setting1']= $row[6];
            $s['setting2']= $row[7];
            $s['setting3']= $row[8];
            $s['7']= $row[9];            
        return $s;
    } 
?>
I... I... maybe there's a reason?

php:
<?
for ($index = 0; $index < count(getSettings()); $index = $index + 1) {
    switch ($index){
        case 0:
           $s = getSettings();
           $admin_Email = $s['1'];
           break;
        case 1:
           $s = getSettings();
           $adminname = $s['2'];
           break;
        case 2:
           $s = getSettings();
           $sendEmailFrom = $s['3'];
           break;
...
?>
I don't know what to say. I really don't. :suicide:

bobthecheese fucked around with this message at 00:24 on Nov 19, 2010

Fiend
Dec 2, 2001

bobthecheese posted:

I just found this today.
php:
<?
    function getSettings() {
        $query = "SELECT * FROM `system_settings` LIMIT 1";

        $result = mysql_query($query);
        $row = mysql_fetch_row($result);
            $s['1']= $row[0];
            $s['2']= $row[1];
            $s['3']= $row[2];
            $s['4']= $row[3];
            $s['5']= $row[4];
            $s['6']= $row[5];
            $s['setting1']= $row[6];
            $s['setting2']= $row[7];
            $s['setting3']= $row[8];
            $s['7']= $row[9];            
        return $s;
    } 
?>
I... I... maybe there's a reason?

php:
<?
for ($index = 0; $index < count(getSettings()); $index = $index + 1) {
    switch ($index){
        case 0:
           $s = getSettings();
           $admin_Email = $s['1'];
           break;
        case 1:
           $s = getSettings();
           $adminname = $s['2'];
           break;
        case 2:
           $s = getSettings();
           $sendEmailFrom = $s['3'];
           break;
...
?>
I don't know what to say. I really don't.
Add 90 more lines and then fly a plane into it?

markerstore
Dec 5, 2003
Canny!

Wheany posted:

FUCKIN' AJAX, MOTHERFUCKERS! :science:
code:
row = table.insertRow(-1);
cell = row.insertCell(-1);
cell.colSpan = 2;
div = document.createElement('div');
div.appendChild(document.createElement('br'));
cell.appendChild(div);

Wait, where's the AJAX?

Fiend
Dec 2, 2001

markerstore posted:

Wait, where's the AJAX?

Not Shown: AJAX.

npe
Oct 15, 2004

baquerd posted:

I'm not familiar with VB, but is the solution to store a pointer to the objects in an array I assume?

Everything in there is 100% pure insanity. There is no fix.

If you must think about it, though, just know that most of the current code in there can be replaced with a few dozen lines of code that uses ThreadPool.QueueUserWorkItem() and follows some of the ideas in http://msdn.microsoft.com/en-us/library/ms973903.aspx

But we are way past that. Fuckin' arrays, how do they work?!

Wheany
Mar 17, 2006

Spinyahahahahahahahahahahahaha!

Doctor Rope

markerstore posted:

Wait, where's the AJAX?

The javascript file is in the subdirectory 'ajax' :rolleyes:

Actually, there is this bit:
code:
$.ajaxSetup({
  async: false,                 // set ajax calls globally "synchronous"
  timeout: 5000
});
So it's SJAX

Without X

Wheany fucked around with this message at 06:09 on Nov 19, 2010

markerstore
Dec 5, 2003
Canny!

Wheany posted:

Actually, there is this bit:
code:
$.ajaxSetup({
  async: false,                 // set ajax calls globally "synchronous"
  timeout: 5000
});

Oh sweet, so he is using jQuery, but only for long enough to turn off the useful parts.

Wheany
Mar 17, 2006

Spinyahahahahahahahahahahahaha!

Doctor Rope

markerstore posted:

Oh sweet, so he is using jQuery, but only for long enough to turn off the useful parts.

Oh hell yes he's used jQuery:

code:
find -name '*jquery*.js' | wc -l
129
I just have to do this one feature on a tight deadline, then I can start cleaning up for reals :smithicide:

I've already deleted a bunch of .old.php and .php.old files and commented-out code.

e: To be fair: many of those jquery files are legit, but there are several versions of the base library.

Wheany fucked around with this message at 07:41 on Nov 19, 2010

Lysandus
Jun 21, 2010
This might not be a horror for some of you but gently caress.

code:
if( bananas )
     grabBanana();
God drat I don't care if it's one line. Put some {} on that poo poo.

Orzo
Sep 3, 2004

IT! IT is confusing! Say your goddamn pronouns!

Lysandus posted:

This might not be a horror for some of you but gently caress.

code:
if( bananas )
     grabBanana();
God drat I don't care if it's one line. Put some {} on that poo poo.
This is a preference and probably the furthest thing from a horror I can think of. Follow your team's guidelines when it comes to this one.

Shavnir
Apr 5, 2005

A MAN'S DREAM CAN NEVER DIE

Orzo posted:

This is a preference and probably the furthest thing from a horror I can think of. Follow your team's guidelines when it comes to this one.

While it is a minor quibble after maybe the third or fourth time someone accidentally fucks up an if block by adding another line you start putting the {}s everywhere you can.

Lysandus
Jun 21, 2010

Orzo posted:

This is a preference and probably the furthest thing from a horror I can think of. Follow your team's guidelines when it comes to this one.

Our department made it a guideline long ago because we all hate it. I was reminded of it today while looking though a library from another department.

Dessert Rose
May 17, 2004

awoken in control of a lucid deep dream...
The only time I leave off braces is when I do an early return (if (!foo) return false;) and then I put it all on one line so I can't make the mistake of adding lines to it.

Mustach
Mar 2, 2003

In this long line, there's been some real strange genes. You've got 'em all, with some extras thrown in.
Do you guys not test your code or something? Is it really that big of a deal if somebody somehow temporarily forgets that they're coding in a language that uses braces to delimit blocks and puts a statement outside of the if?

Fiend
Dec 2, 2001

Mustach posted:

Do you guys not test your code or something? Is it really that big of a deal if somebody somehow temporarily forgets that they're coding in a language that uses braces to delimit blocks and puts a statement outside of the if?

It's more of a readability issue rather than a testing issue. Plus we use StyleCop to help enforce a standardized style and make it easier to maintain and peer-review.

tef
May 30, 2004

-> some l-system crap ->

Mustach posted:

Do you guys not test your code or something? Is it really that big of a deal if somebody somehow temporarily forgets that they're coding in a language that uses braces to delimit blocks and puts a statement outside of the if?

You'd be surprised how often it happens. Many people never write ifs without braces, and so don't notice when they aren't there :shobon:

Orzo
Sep 3, 2004

IT! IT is confusing! Say your goddamn pronouns!
The code following an if statement should never be more than one line regardless, so it's a non-issue.

Fiend
Dec 2, 2001

Orzo posted:

The code following an if statement should never be more than one line regardless, so it's a non-issue.
What if you want to iterate or create an instance of a class with data not accessible in a constructor?

code:
SuperFunPony myLittlePwny;
if (args.Count() > 0)
	for (int i = 0; i < args.Count(); i++)
		Console.WriteLine("argument {0} is {1}", i, args[i]);
else if (args.Count() == 0)
	myLittlePwny = new SuperFunPony()
	{
		Size = "big",
		Age = 10,
		HasRainbow = true,
		PonyName = "Beatrice"
	};
else
	throw new System.ArgumentNullException("aaaarrrrgggggg", "no pony!!!");
LOOK AT WHAT YOU MADE ME DO!

edit:

quote:

SA1305: The variable name 'myLittlePwny' begins with a prefix that looks like Hungarian notation. Remove the prefix or add it to the list of allowed prefixes.

GOD drat YOU STYLECOP! GOD drat YOU!

Fiend fucked around with this message at 00:41 on Nov 20, 2010

Shavnir
Apr 5, 2005

A MAN'S DREAM CAN NEVER DIE

Orzo posted:

The code following an if statement should never be more than one line regardless, so it's a non-issue.

Real horror found.

Fiend
Dec 2, 2001

Shavnir posted:

Real horror found.

No man you just create a new method with all the logic in there, that way you only need curly braces to encapsulate methods and classes and poo poo.

mr_jim
Oct 30, 2006

OUT OF THE DARK

Orzo posted:

The code following an if statement should never be more than one line regardless, so it's a non-issue.

Fiend posted:

No man you just create a new method with all the logic in there, that way you only need curly braces to encapsulate methods and classes and poo poo.

:stare:

Why?

Fiend
Dec 2, 2001

mr_jim posted:

:stare:

Why?
To help flush out the architectural nuances pertinent to pointless and cumbersome style practices.

npe
Oct 15, 2004
Coming up next in the Coding Horrors thread, after the break:

tabs v spaces
brace styles
toilet paper under/over

Orzo
Sep 3, 2004

IT! IT is confusing! Say your goddamn pronouns!
Yeah, uh, I was joking by the way.

Vanadium
Jan 8, 2005

Just having a single expression inside each branch of an if-then-else expression has always worked fine for me, I do not see what the big deal is

how do curly braces play into this again

evensevenone
May 12, 2001
Glass is a solid.
I just remove all non-semantic whitespace and line breaks before I check anything in, that way whenever any else sees the code they just assume that something in the CVS hosed up the formatting and they'll autoformat it to their liking.

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe
Curly braces inside parentheses are how you get functional composition of expressions in C.

code:
main(x,y) long x, y; {
  return ({ static void*data; for (; --x; puts(*(typeof(*"")**)(
    {long z = y + ({long a = x; a += x; a += a; a += a * ((1L << 32) >> 32); }); &z[data]; }))); 0; });
}

Amarkov
Jun 21, 2010

rjmccall posted:

Curly braces inside parentheses are how you get functional composition of expressions in C.

code:
main(x,y) long x, y; {
  return ({ static void*data; for (; --x; puts(*(typeof(*"")**)(
    {long z = y + ({long a = x; a += x; a += a; a += a * ((1L << 32) >> 32); }); &z[data]; }))); 0; });
}

puts(*(typeof(*"")**)

what the gently caress does this do and why does it compile

Vanadium
Jan 8, 2005

*"" is '\0', typeof('\0') is char, (char**) is a cast to pointer to pointer to char, and the * dereferences it so you get a pointer to char to pass to puts, which happens to point at successive elements of argv.

Bozart
Oct 28, 2006

Give me the finger.

Vanadium posted:

*"" is '\0', typeof('\0') is char, (char**) is a cast to pointer to pointer to char, and the * dereferences it so you get a pointer to char to pass to puts, which happens to point at successive elements of argv.

That is hosed.

Dicky B
Mar 23, 2004

I would love a weekly "explain what the following obfuscated code does" contest. Kind of like ioccc but in reverse.

NotShadowStar
Sep 20, 2000

Dicky B posted:

I would love a weekly "explain what the following obfuscated code does" contest. Kind of like ioccc but in reverse.

Just read the Perl thread.

dark_panda
Oct 25, 2004

Vanadium posted:

Just having a single expression inside each branch of an if-then-else expression has always worked fine for me, I do not see what the big deal is

how do curly braces play into this again

Part of the idea is "durability under edit". With braces, if someone goes in and adds more lines later, the braces are already there and it reduces chances of a logic error. Doesn't matter if it's a temporary thing to insert maybe debugging statements or totally new code or whatever -- it's just a matter of reducing the potential of subtle errors in logic.

Mustach
Mar 2, 2003

In this long line, there's been some real strange genes. You've got 'em all, with some extras thrown in.

rjmccall posted:

Curly braces inside parentheses are how you get functional composition of expressions in C.
This is an extension, right? Searching for "({" doesn't bring up anything relevant in n1256.

Flobbster
Feb 17, 2005

"Cadet Kirk, after the way you cheated on the Kobayashi Maru test I oughta punch you in tha face!"

Mustach posted:

This is an extension, right? Searching for "({" doesn't bring up anything relevant in n1256.

It looks like it's a GNU C extension, along with typeof:

http://gcc.gnu.org/onlinedocs/gcc-2.95.3/gcc_4.html#SEC62

Adbot
ADBOT LOVES YOU

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe
Yeah, the full inventory is three GCC extensions, two unportable assumptions, either one or three instances of undefined behavior, and an illegal declaration of main.

EDIT: Well, plus an extra unportable assumption mixed in with the undefined behavior.

rjmccall fucked around with this message at 06:16 on Nov 21, 2010

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