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
Innocent Bystander
May 8, 2007
Born in the LOLbarn.

quote:

For all the folks getting excited about my quotes. Here is another - Yes, I am a terrible coder, but I am probably still better than you

This is false, even the worst coders know when to quit.

Edit: Or should I say, in PHP this is something `like` false.

Adbot
ADBOT LOVES YOU

senrath
Nov 4, 2009

Look Professor, a destruct switch!


Tiny Bug Child posted:

Having heterodox opinions on type systems doesn't make you a "troll". And if you're going to go quote mining, you might as well include what I had to say about this when Hacker News got their panties a-twist about this three months ago:

And yet that post is still as stupid today as it was 3 months ago.

Wheany
Mar 17, 2006

Spinyahahahahahahahahahahahaha!

Doctor Rope

hackbunny posted:

Oh gently caress PHP, gently caress it hard. Is there a saner language that compiles to PHP, like CoffeScript compiles to Javascript? This poo poo is un-loving-believable

Are you using an IDE? Those usually have some inspection tools to help find problematic code.

== vs === isn't really that big of a deal.

Pilsner
Nov 23, 2002

hackbunny posted:

I want to punch this page in the ear and you too for suggesting it. We get it Joel, you're an IT entrepreneur who was the youngest PM at Microsoft and held his own against Bill loving Gates, jesus christ stop fellating yourself for two seconds. And I used to admire the guy and follow his blog religiously :cripes: I even remember this particular entry and used to remember it fondly :cripes: Thanks for making me realize what kind of idiot I was, I guess?
It was written 8 years ago. You used to love the article, Joel probably wrote it with confidence back then. Why do you assume that Joel (not that I know him personally or anything) still thinks that article is great and holds water? Everyone in software thinks their own work and opinions from 8 years ago stink.

Some people are on a very high horse.

hackbunny
Jul 22, 2007

I haven't been on SA for years but the person who gave me my previous av as a joke felt guilty for doing so and decided to get me a non-shitty av

Pilsner posted:

It was written 8 years ago. You used to love the article, Joel probably wrote it with confidence back then. Why do you assume that Joel (not that I know him personally or anything) still thinks that article is great and holds water? Everyone in software thinks their own work and opinions from 8 years ago stink.

It's more the fact that Joel comes across as a complete tool

Bruegels Fuckbooks
Sep 14, 2004

Now, listen - I know the two of you are very different from each other in a lot of ways, but you have to understand that as far as Grandpa's concerned, you're both pieces of shit! Yeah. I can prove it mathematically.

Jewel posted:

:frogsiren: :gonk: :frogsiren:

This is loving terrible? Why yes remembering that if something starts with rgwch means an array of unicode wide characters IS something that's in my mind on a day to day basis, thanks!

For the punchline, click http://msdn.microsoft.com/en-us/library/aa260976(v=vs.60).aspx and scroll to the code sample.

pigdog
Apr 23, 2004

by Smythe

hieronymus posted:

For the punchline, click http://msdn.microsoft.com/en-us/library/aa260976(v=vs.60).aspx and scroll to the code sample.

"In closing, it is evident that the conventions participated in making the code more correct, easier to write, and easier to read. Naming conventions cannot guarantee good code, however; only the skill of the programmer can. " :c00lbutt:

:suicide:

hackbunny
Jul 22, 2007

I haven't been on SA for years but the person who gave me my previous av as a joke felt guilty for doing so and decided to get me a non-shitty av

quote:

PsyCreate is a good procedure name; PsyCreateCw would have been even better.

I don't even

Goat Bastard
Oct 20, 2004

Innocent Bystander posted:

This is false, even the worst coders know when to quit.

If you believe that then you've certainly had a charmed career.

Hammerite
Mar 9, 2007

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

Wheany posted:

Are you using an IDE? Those usually have some inspection tools to help find problematic code.

== vs === isn't really that big of a deal.

However, this particular PHP discussion got started by the fact that PHP's switch construct uses == comparison. Having to work around that isn't very convenient, and it is a potential source of bugs.

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe

hackbunny posted:

I don't even

oppan coding style

Strong Sauce
Jul 2, 2003

You know I am not really your father.





Hammerite posted:

However, this particular PHP discussion got started by the fact that PHP's switch construct uses == comparison. Having to work around that isn't very convenient, and it is a potential source of bugs.

Cast the input of the switch to a string. Problem solved.

Edit: Also the cases.

Strong Sauce fucked around with this message at 17:59 on Jun 12, 2013

Hammerite
Mar 9, 2007

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

Strong Sauce posted:

Cast the input of the switch to a string. Problem solved.

code:
$x = '0001000';
switch ($x) {
   case '1000':
      echo 'nope ';
   case '0001000':
      echo 'sorry ';
   default:
      echo 'PHP sucks';
}

ctz
Feb 6, 2003

Deus Rex posted:

In our case, the strings to be compared were HMAC-MD5 hashes.

The final fix was to use the strict, non-coercing operator ===.

The 'final fix' which almost certainly leaks the correct signature through the timing side channel?

b0lt
Apr 29, 2005

ctz posted:

The 'final fix' which almost certainly leaks the correct signature through the timing side channel?

non-constant time string comparison :woop:

Strong Sauce
Jul 2, 2003

You know I am not really your father.





Hammerite posted:

code:
$x = '0001000';
switch ($x) {
   case '1000':
      echo 'nope ';
   case '0001000':
      echo 'sorry ';
   default:
      echo 'PHP sucks';
}

touché

Dessert Rose
May 17, 2004

awoken in control of a lucid deep dream...

Hammerite posted:

code:
$x = '0001000';
switch ($x) {
   case '1000':
      echo 'nope ';
   case '0001000':
      echo 'sorry ';
   default:
      echo 'PHP sucks';
}

The fact that the default block gets executed is the coup de grâce. What the gently caress?

edit: Wait, this isn't as bad as it appears. PHP has fallthrough, so of course it does.

Dessert Rose fucked around with this message at 00:34 on Jun 13, 2013

zeekner
Jul 14, 2007

Dessert Rose posted:

The fact that the default block gets executed is the coup de grâce. What the gently caress?

PHP switch statements fall through intentionally. It's not that unusual, C and others do as well.

Whether or not fallthrough is worthwhile is a whole different argument.

e: I am a really slow poster.

zeekner fucked around with this message at 00:40 on Jun 13, 2013

senrath
Nov 4, 2009

Look Professor, a destruct switch!


However, if you add in the breaks yourself it still executes the first statement rather than the second.

bobthecheese
Jun 7, 2006
Although I've never met Martha Stewart, I'll probably never birth her child.
I'll let you absorb this for a little while.

php:
<?
while ($row = mysql_fetch_row($resultAlerts)) {                                                                                   
    list($alertID, $alertSQL, $databaseLink, $alertLink, $alertName, $sort) = $row;                                               
                                                                                                                                  
    //be sure to make sure the vars are set                                                                                       
    eval('$alertSQL = "' . $alertSQL . '";');                                                                                     
                                                                                                                                  
    if ($databaseLink == null) {                                                                                                  
        $databaseLink = null;                                                                                                     
    } else {                                                                                                                      
        $databaseLink = '_' . $databaseLink;                                                                                      
        $databaseLink = $this->$databaseLink;                                                                                     
    }                                                                                                                             
                                                                                                                                  
    $resultAlert = ConnectToDatabaseWithLink($alertSQL, $databaseLink);                                                           
    $alertCount = mysql_num_rows($resultAlert);                                                                                   
                                                                                                                                  
    if ($alertCount > 0) {                                                                                                        
        //set some text vars based on the count                                                                                   
        if ($alertCount == 1) {                                                                                                   
            $s = '';                                                                                                              
            $es = '';                                                                                                             
            $hasHave = 'has';                                                                                                     
            $doDoes = 'does';                                                                                                     
        } else {                                                                                                                  
            $s = 's';                                                                                                             
            $es = 'es';                                                                                                           
            $hasHave = 'have';                                                                                                    
            $doDoes = 'do';                                                                                                       
        }                                                                                                                         
                                                                                                                                  
        //update the text with the link and replace the vars                                                                      
        eval('$alertName="' . $alertName . '";');                                                                                 
                                                                                                                                  
        //show the alert to users                                                                                                 
        $returnVal .= '<div class="pinkBox">                                                                                      
            <p class="warningTitle">' . $alertName . '</p>                                                                        
            <p class="warningText"><span class="warningLink"><a href="' . $alertLink . '">' . $alertCount . '</a></span><br /></p>
            </div>';                                                                                                              
    }                                                                                                                             
}                                                                                                                                 
?>
Go back again and think about it some more.

It's evaling and then executing SQL code that it pulls out of the loving database.

It gets worse...

code:
SELECT DISTINCT(pa.ID) AS PartAttrID
FROM dropshipDB.Parts p
  INNER JOIN dropshipDB.PartAttributes pa ON pa.PartID = p.ID
    AND pa.See = 1
WHERE p.See = 1
  AND pa.ID > 1
  AND pa.ID NOT IN (
      SELECT DropshipPartAttributeID                                             
      FROM retailDB.DropshipRetailProductBridge                      
      WHERE DropshipPartAttributeID NOT IN (                                     
          SELECT GROUP_CONCAT(DISTINCT(pa.ID))                 
          FROM dropshipDB.PartAttributes pa                      
          WHERE pa.See = 1                                                  
      )                                                                     
  )
That loving query, with cross-database joins in it, was stored in the database. I'm trying to move the dropship database to a new server, and everything explodes at me because some bastard thought that it would be a brilliant idea to store this query in the database instead of in the code with the rest of the loving queries.

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
code:
    //be sure to make sure the vars are set                                                                                       
    eval('$alertSQL = "' . $alertSQL . '";');                                                                                     
Wait, is it using SQL injection as a feature?

bobthecheese
Jun 7, 2006
Although I've never met Martha Stewart, I'll probably never birth her child.

Suspicious Dish posted:

code:
    //be sure to make sure the vars are set                                                                                       
    eval('$alertSQL = "' . $alertSQL . '";');                                                                                     
Wait, is it using SQL injection as a feature?

Not exactly, but pretty close to (actually it used to use SQL injection as a feature elsewhere in the code with the justification "but the script is private!". I fixed it and shouted at people.)

To be fair, the code is quite old for a PHP project (the oldest code that's still in use was written, at best guess, in '99). A lot of it was also written by someone who, although a nice guy, had no loving idea what he was doing, and the boss eventually let him go because his code was dangerously bad, and has now hired better people to drag this thing kicking-and-screaming into a secure system.

bobthecheese fucked around with this message at 02:05 on Jun 13, 2013

LOOK I AM A TURTLE
May 22, 2003

"I'm actually a tortoise."
Grimey Drawer
What's the most indented line of code you've ever seen? I've got one that's 19 levels deep, which with 4 spaces per tab means that the line in question begins at column 77. I don't really care about the old 79-chars-per-line rule when doing C#, but you know something is wrong when you're practically already there before you've even written anything.

I won't show the actual method since it's 777 lines long, but here's what the hierarchy looks like:
code:
namespace
    class
        method
            foreach
                try
                    foreach
                        try
                            if
                                if
                                    else
                                        else
                                            if
                                                else
                                                    if
                                                        else
                                                            if
                                                                if
                                                                    if
                                                                        while
I'll show you the last part with the while loop, since it's quite precious:
C# code:
EditionCollection ec = newProduct.Frequency.GetEditions(); // (Comment added by me: EditionCollection inherits from ArrayList)
if (ec.Count < newProduct.NumberOfEditions)
{
    int iEditions = ec.Count;
    while (iEditions > newProduct.NumberOfEditions)
    {
        ec.RemoveAt(0);
        iEditions = ec.Count;
    }
}
ArrayList.RemoveAt is O(n), and RemoveAt(0) is presumably always the worst case since every other element needs to be shifted. Also, while writing this post I've spotted that the while loop will never actually be entered, since ec.Count has to be both smaller than and bigger than newProduct.NumberOfEditions.

ephphatha
Dec 18, 2009




More adventures in legacy code. Today I found this in the entry point of one of our web scripts:

code:
sub main() {
    system("kill -9 8765 8876 8760 8882");
...
}
That call had been present in the script since the day it was put into source control. Naturally no comments as to why it was there or why those particular PIDs were being killed (especially since PIDs are assigned on process spawn, they can't have been targetting a specific process...).

Wheany
Mar 17, 2006

Spinyahahahahahahahahahahahaha!

Doctor Rope

Ephphatha posted:

More adventures in legacy code. Today I found this in the entry point of one of our web scripts:

code:
sub main() {
    system("kill -9 8765 8876 8760 8882");
...
}
That call had been present in the script since the day it was put into source control. Naturally no comments as to why it was there or why those particular PIDs were being killed (especially since PIDs are assigned on process spawn, they can't have been targetting a specific process...).

Well now you know what caused those weird Heisenbugs in other projects.

QuarkJets
Sep 8, 2008

My advisor in grad school (physics) suggested indenting as much as possible in Python in order to help with flow control. So while I was writing stuff like this:

Python code:
def event_is_interesting(event):
  if(len(event.Leptons) != 2):
    return False
  if(event.Leptons[0].Pt() < 20.0):
    return False
  if(event.Leptons[1].Pt() < 20.0):
    return False
  if(event.MET() < 60.0):
    return False
  ... #at least 10 other if statements
  return True
He'd suggest to write stuff like this:

Python code:
#In main loop
if(len(event.Leptons) == 2):
    if(event.Leptons[0].Pt() < 20.0):
        if(event.Leptons[1].Pt() < 20.0): 
             #etc, then do something if everything passes
It'd easily go 20 if statements deep for a more complicated event selection process

The Gripper
Sep 14, 2004
i am winner

QuarkJets posted:

My advisor in grad school (physics) suggested indenting as much as possible in Python in order to help with flow control. So while I was writing stuff like this:

It'd easily go 20 if statements deep for a more complicated event selection process
Well you can also wrap if statements across lines if you really want:
Python code:
def event_is_interesting(event):
  if(len(event.Leptons) != 2 or 
    event.Leptons[0].Pt() < 20.0 or
	event.Leptons[1].Pt() < 20.0 or
    event.MET() < 60.0):
      return False
  return True
Your advisor is a pretty terrible person and I'd hate to see how crappy his actual production code is, if he thinks nesting for things like that is a good idea I can just imagine the other "me learning VB6" style choices he makes.

Civil Twilight
Apr 2, 2011

Ephphatha posted:

or why those particular PIDs were being killed (especially since PIDs are assigned on process spawn, they can't have been targetting a specific process...).

At a job I used to have, before I took over system administration, the only way that my boss knew to reload the DNS configuration was "kill -1 81" or reboot the machine so that the pid was right again.

Sang-
Nov 2, 2007

Civil Twilight posted:

At a job I used to have, before I took over system administration, the only way that my boss knew to reload the DNS configuration was "kill -1 81" or reboot the machine so that the pid was right again.

cargo culting at its best

Sagacity
May 2, 2003
Hopefully my epitaph will be funnier than my custom title.

Suspicious Dish posted:

I love corporate open-source dumps.

code:
//
// SONY CONFIDENTIAL
//
void main(
    float4     color_in  : COLOR,
    float4 out color_out : COLOR)
{
    color_out = color_in;
}

This is actually a pretty normal diffuse-only pixel shader. It might be a horror that you need one in the first place, if all you want to do is return the input color, but that's hardly Sony's fault :)

prefect
Sep 11, 2001

No one, Woodhouse.
No one.




Dead Man’s Band

Sagacity posted:

This is actually a pretty normal diffuse-only pixel shader. It might be a horror that you need one in the first place, if all you want to do is return the input color, but that's hardly Sony's fault :)

Could you give us (me) a capsule explanation of why you'd need this? I'm curious to get an actual understanding. :tipshat:

Hammerite
Mar 9, 2007

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

The Gripper posted:

Your advisor is a pretty terrible person

:rolleyes: Bad code => bad person, yeah no problems with that worldview especially when applied to people whose actual job isn't programming.

I'd imagine a physics professor employing Python for number-crunching doesn't have much need for a distinction between "development" and "production" code, either.

RoadCrewWorker
Nov 19, 2007

camels aren't so great

Sagacity posted:

This is actually a pretty normal diffuse-only pixel shader. It might be a horror that you need one in the first place, if all you want to do is return the input color, but that's hardly Sony's fault :)
And here i was trying to pretend the joke was just the giant "CONFIDENTIAL" label on what's basically a default NOP pass-through function used in millions of other shaders.

Of course that only works if the unquoted rest of the pass is equally trivial and it's not just an auto-generated file header.

Sagacity
May 2, 2003
Hopefully my epitaph will be funnier than my custom title.

prefect posted:

Could you give us (me) a capsule explanation of why you'd need this? I'm curious to get an actual understanding. :tipshat:
Well, graphics API's typically require you to provide a pixel/fragment shader even if it's the simplest no-oppiest one in the world.

Although, yes, maybe I should've followed RoadCrewWorker's cue and laughed at the CONFIDENTIAL message. :spergin:

Bizarro Buddha
Feb 11, 2007

prefect posted:

Could you give us (me) a capsule explanation of why you'd need this? I'm curious to get an actual understanding. :tipshat:

If your vertex shader provides a colour directly you still need to provide a pixel shader to link that to the output stage.

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
Note that such shaders are extremely common to the point where it's one of the few shaders drivers usually detect and have a special fast path for. I was laughing at the SONY CONFIDENTIAL header, which they also slapped on a few other no-op shaders, a blank header file, and a copy of malloc.c from an old glibc.

Dren
Jan 5, 2001

Pillbug
But writing a sed script to remove the SONY CONFIDENTIAL header before doing the open source dump would have been haaaaaaaaaarrrrrrrrrddddddd.

Sagacity
May 2, 2003
Hopefully my epitaph will be funnier than my custom title.
I'm used to these 30-line copyright notices at the top of C++ projects in our company. I have no idea why they are on there since the source code's for internal use only.

Maybe they enjoy scrolling down after opening a file.

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
You should have copyright notices on code for internal use, thought I struggle to imagine how you get one to 30 lines. The one I usually paste in is

code:
/* ========================================
 *
 * Copyright (c) $company, $year.
 * All Rights Reserved.
 * UNPUBLISHED, LICENSED SOFTWARE.
 *
 * By $developer.
 *
 * CONFIDENTIAL AND PROPRIETARY INFORMATION
 * WHICH IS THE PROPERTY OF $company.
 *
 * ========================================
*/

Adbot
ADBOT LOVES YOU

shrughes
Oct 11, 2008

(call/cc call/cc)
We just have

code:
// Copyright 2010-2012 <employer>, all rights reserved.

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