Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi all! We have been experiencing an issue on site where threads have been missing the latest postings. The platform host Vanilla are working on this issue. A workaround that has been used by some is to navigate back from 1 to 10+ pages to re-sync the thread and this will then show the latest posts. Thanks, Mike.
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Coding Horror

17810121322

Comments

  • Technology & Internet Moderators Posts: 28,820 Mod ✭✭✭✭oscarBravo


    250px-That's_a_paddlin'.png


  • Registered Users, Registered Users 2 Posts: 2,029 ✭✭✭Colonel Panic


    No coding standards or coding standards you don't agree with. Which is worse?


  • Registered Users, Registered Users 2 Posts: 1,465 ✭✭✭Anesthetize


    You'd hate me then, because I'd probably have written:
    if (.....) <some statement>;
    else <some statement>;
    
    <some statement>;
    
    That's a paddlin'


  • Subscribers Posts: 4,076 ✭✭✭IRLConor


    No coding standards or coding standards you don't agree with. Which is worse?

    Coding standards you don't agree with. At least when there are no coding standards, you're not angry all the time.


  • Registered Users, Registered Users 2 Posts: 13,080 ✭✭✭✭Maximus Alexander


    That's a paddlin'

    Meh. Java's unnecessarily verbose at times. I value consistency and clarity, but also brevity.


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 586 ✭✭✭Aswerty


    No coding standards or coding standards you don't agree with. Which is worse?

    Subjectively; the former. Objectively; the latter.


  • Registered Users, Registered Users 2 Posts: 8,219 ✭✭✭Calina


    No coding standards or coding standards you don't agree with. Which is worse?

    Well, if there are no coding standards you stand a chance of getting some you approve of implemented at some point.

    Coding standards you don't agree with are just a recipe for daily frustration.


  • Registered Users, Registered Users 2 Posts: 6,260 ✭✭✭Buford T Justice


    One of the many many loops in one method. The old, lets just bring everything back in an SQL query and work it all out in a controller afterwards.
    foreach ($aryLineItems as $lineItemKey => $lineItemVal) {
                        $arySelectedSupplierProducts = array();
                        if (!empty($lineItemVal['LineItem']['line_item_product_id'])) {
                            if (strpos($lineItemVal['LineItem']['line_item_product_id'], "|") !== false) {
                                $aryLineItemProductIds = explode("|", $lineItemVal['LineItem']['line_item_product_id']);
                                foreach ($aryLineItemProductIds as $lineItemProductQtyId) {
                                    if (strpos($lineItemProductQtyId, "::") !== false) {
                                        $lineItemProductId = substr($lineItemProductQtyId, 0, strpos($lineItemProductQtyId, '::'));
                                        $lineItemProductQty = substr($lineItemProductQtyId, (strpos($lineItemProductQtyId, '::') + 2));
                                    }
                                    else {
                                        $lineItemProductId = substr($lineItemProductQtyId, 0, strpos($lineItemProductQtyId, '::'));
                                        $lineItemProductQty = "1";
                                    }
                                    $arySelectedSupplierProducts[$lineItemProductId] = $lineItemProductQty;
                                }
                            }
                            else {
                                if (strpos($lineItemVal['LineItem']['line_item_product_id'], "::") !== false) {
                                    $lineItemProductQtyId = $lineItemVal['LineItem']['line_item_product_id'];
                                    $lineItemProductId = substr($lineItemProductQtyId, 0, strpos($lineItemProductQtyId, '::'));
                                    $lineItemProductQty = substr($lineItemProductQtyId, (strpos($lineItemProductQtyId, '::') + 2));
                                    $arySelectedSupplierProducts[$lineItemProductId] = $lineItemProductQty;
                                }
                                else {
                                    $lineItemProductId = $lineItemVal['LineItem']['line_item_product_id'];
                                    $lineItemProductQty = "1";
                                    $arySelectedSupplierProducts[$lineItemProductId] = $lineItemProductQty;
                                }
                            }
                        }
    
                        if (count($arySelectedSupplierProducts) > 0) {
                            $aryLineItemProducts = $this->Arrangement->LineItem->LineItemProduct->find('all', array(
                                    'recursive' => 0,
                                    'conditions' => array('LineItemProduct.id' => array_keys($arySelectedSupplierProducts)),
                                )
                            );
                            $aryLineItems[$lineItemKey]['LineItemSupplierProducts'] = $aryLineItemProducts;
                            $aryLineItems[$lineItemKey]['LineItemSupplierProductsQtys'] = $arySelectedSupplierProducts;
                        }
                        else {
                            if (!empty($lineItemVal['LineItem']['cheque_name'])) {
                                $aryLineItems[$lineItemKey]['LineItemSupplierProducts'][0]['Contact']['company_name'] = $lineItemVal['LineItem']['cheque_name'];
                            }
                        }
    
                    }
                    $aryData['LineItem'][$sLineItemType] = $aryLineItems;
                }
    

    And lets not forget
    foreach ($aryLineItems as $lineItemKey => $lineItemVal) {
                        $arySelectedSupplierProducts = array();
                        if (!empty($lineItemVal['LineItem']['line_item_product_id'])) {
                            if (strpos($lineItemVal['LineItem']['line_item_product_id'], "|") !== false) {
                                $aryLineItemProductIds = explode("|", $lineItemVal['LineItem']['line_item_product_id']);
                                foreach ($aryLineItemProductIds as $lineItemProductQtyId) {
                                    if (strpos($lineItemProductQtyId, "::") !== false) {
                                        $lineItemProductId = substr($lineItemProductQtyId, 0, strpos($lineItemProductQtyId, '::'));
                                        $lineItemProductQty = substr($lineItemProductQtyId, (strpos($lineItemProductQtyId, '::') + 2));
                                    }
                                    else {
                                        $lineItemProductId = substr($lineItemProductQtyId, 0, strpos($lineItemProductQtyId, '::'));
                                        $lineItemProductQty = "1";
                                    }
                                    $arySelectedSupplierProducts[$lineItemProductId] = $lineItemProductQty;
                                }
                            }
                            else {
                                if (strpos($lineItemVal['LineItem']['line_item_product_id'], "::") !== false) {
                                    $lineItemProductQtyId = $lineItemVal['LineItem']['line_item_product_id'];
                                    $lineItemProductId = substr($lineItemProductQtyId, 0, strpos($lineItemProductQtyId, '::'));
                                    $lineItemProductQty = substr($lineItemProductQtyId, (strpos($lineItemProductQtyId, '::') + 2));
                                    $arySelectedSupplierProducts[$lineItemProductId] = $lineItemProductQty;
                                }
                                else {
                                    $lineItemProductId = $lineItemVal['LineItem']['line_item_product_id'];
                                    $lineItemProductQty = "1";
                                    $arySelectedSupplierProducts[$lineItemProductId] = $lineItemProductQty;
                                }
                            }
                        }
    
                        if (count($arySelectedSupplierProducts) > 0) {
                            $aryLineItemProducts = $this->Arrangement->LineItem->LineItemProduct->find('all', array(
                                    'recursive' => 0,
                                    'conditions' => array('LineItemProduct.id' => array_keys($arySelectedSupplierProducts)),
                                )
                            );
                            $aryLineItems[$lineItemKey]['LineItemSupplierProducts'] = $aryLineItemProducts;
                            $aryLineItems[$lineItemKey]['LineItemSupplierProductsQtys'] = $arySelectedSupplierProducts;
                        }
                        else {
                            if (!empty($lineItemVal['LineItem']['cheque_name'])) {
                                $aryLineItems[$lineItemKey]['LineItemSupplierProducts'][0]['Contact']['company_name'] = $lineItemVal['LineItem']['cheque_name'];
                            }
                        }
    
                    }
                    $aryData['LineItem'][$sLineItemType] = $aryLineItems;
                }
    

    Only about 3K lines of code like that in one controller


  • Registered Users, Registered Users 2 Posts: 9,527 ✭✭✭irishgeo


    One of the many many loops in one method. The old, lets just bring everything back in an SQL query and work it all out in a controller afterwards.
    foreach ($aryLineItems as $lineItemKey => $lineItemVal) {
                        $arySelectedSupplierProducts = array();
                        if (!empty($lineItemVal['LineItem']['line_item_product_id'])) {
                            if (strpos($lineItemVal['LineItem']['line_item_product_id'], "|") !== false) {
                                $aryLineItemProductIds = [B]explode[/B]("|", $lineItemVal['LineItem']['line_item_product_id']);
                                foreach ($aryLineItemProductIds as $lineItemProductQtyId) {
                                    if (strpos($lineItemProductQtyId, "::") !== false) {
                                        $lineItemProductId = substr($lineItemProductQtyId, 0, strpos($lineItemProductQtyId, '::'));
                                        $lineItemProductQty = substr($lineItemProductQtyId, (strpos($lineItemProductQtyId, '::') + 2));
                                    }
                                    else {
                                        $lineItemProductId = substr($lineItemProductQtyId, 0, strpos($lineItemProductQtyId, '::'));
                                        $lineItemProductQty = "1";
                                    }
                                    $arySelectedSupplierProducts[$lineItemProductId] = $lineItemProductQty;
                                }
                            }
                            else {
                                if (strpos($lineItemVal['LineItem']['line_item_product_id'], "::") !== false) {
                                    $lineItemProductQtyId = $lineItemVal['LineItem']['line_item_product_id'];
                                    $lineItemProductId = substr($lineItemProductQtyId, 0, strpos($lineItemProductQtyId, '::'));
                                    $lineItemProductQty = substr($lineItemProductQtyId, (strpos($lineItemProductQtyId, '::') + 2));
                                    $arySelectedSupplierProducts[$lineItemProductId] = $lineItemProductQty;
                                }
                                else {
                                    $lineItemProductId = $lineItemVal['LineItem']['line_item_product_id'];
                                    $lineItemProductQty = "1";
                                    $arySelectedSupplierProducts[$lineItemProductId] = $lineItemProductQty;
                                }
                            }
                        }
    
                        if (count($arySelectedSupplierProducts) > 0) {
                            $aryLineItemProducts = $this->Arrangement->LineItem->LineItemProduct->find('all', array(
                                    'recursive' => 0,
                                    'conditions' => array('LineItemProduct.id' => array_keys($arySelectedSupplierProducts)),
                                )
                            );
                            $aryLineItems[$lineItemKey]['LineItemSupplierProducts'] = $aryLineItemProducts;
                            $aryLineItems[$lineItemKey]['LineItemSupplierProductsQtys'] = $arySelectedSupplierProducts;
                        }
                        else {
                            if (!empty($lineItemVal['LineItem']['cheque_name'])) {
                                $aryLineItems[$lineItemKey]['LineItemSupplierProducts'][0]['Contact']['company_name'] = $lineItemVal['LineItem']['cheque_name'];
                            }
                        }
    
                    }
                    $aryData['LineItem'][$sLineItemType] = $aryLineItems;
                }
    

    And lets not forget
    foreach ($aryLineItems as $lineItemKey => $lineItemVal) {
                        $arySelectedSupplierProducts = array();
                        if (!empty($lineItemVal['LineItem']['line_item_product_id'])) {
                            if (strpos($lineItemVal['LineItem']['line_item_product_id'], "|") !== false) {
                                $aryLineItemProductIds = explode("|", $lineItemVal['LineItem']['line_item_product_id']);
                                foreach ($aryLineItemProductIds as $lineItemProductQtyId) {
                                    if (strpos($lineItemProductQtyId, "::") !== false) {
                                        $lineItemProductId = substr($lineItemProductQtyId, 0, strpos($lineItemProductQtyId, '::'));
                                        $lineItemProductQty = substr($lineItemProductQtyId, (strpos($lineItemProductQtyId, '::') + 2));
                                    }
                                    else {
                                        $lineItemProductId = substr($lineItemProductQtyId, 0, strpos($lineItemProductQtyId, '::'));
                                        $lineItemProductQty = "1";
                                    }
                                    $arySelectedSupplierProducts[$lineItemProductId] = $lineItemProductQty;
                                }
                            }
                            else {
                                if (strpos($lineItemVal['LineItem']['line_item_product_id'], "::") !== false) {
                                    $lineItemProductQtyId = $lineItemVal['LineItem']['line_item_product_id'];
                                    $lineItemProductId = substr($lineItemProductQtyId, 0, strpos($lineItemProductQtyId, '::'));
                                    $lineItemProductQty = substr($lineItemProductQtyId, (strpos($lineItemProductQtyId, '::') + 2));
                                    $arySelectedSupplierProducts[$lineItemProductId] = $lineItemProductQty;
                                }
                                else {
                                    $lineItemProductId = $lineItemVal['LineItem']['line_item_product_id'];
                                    $lineItemProductQty = "1";
                                    $arySelectedSupplierProducts[$lineItemProductId] = $lineItemProductQty;
                                }
                            }
                        }
    
                        if (count($arySelectedSupplierProducts) > 0) {
                            $aryLineItemProducts = $this->Arrangement->LineItem->LineItemProduct->find('all', array(
                                    'recursive' => 0,
                                    'conditions' => array('LineItemProduct.id' => array_keys($arySelectedSupplierProducts)),
                                )
                            );
                            $aryLineItems[$lineItemKey]['LineItemSupplierProducts'] = $aryLineItemProducts;
                            $aryLineItems[$lineItemKey]['LineItemSupplierProductsQtys'] = $arySelectedSupplierProducts;
                        }
                        else {
                            if (!empty($lineItemVal['LineItem']['cheque_name'])) {
                                $aryLineItems[$lineItemKey]['LineItemSupplierProducts'][0]['Contact']['company_name'] = $lineItemVal['LineItem']['cheque_name'];
                            }
                        }
    
                    }
                    $aryData['LineItem'][$sLineItemType] = $aryLineItems;
                }
    

    Only about 3K lines of code like that in one controller

    what does explode do?:D


  • Registered Users, Registered Users 2 Posts: 13,080 ✭✭✭✭Maximus Alexander


    One of the many many loops in one method. The old, lets just bring everything back in an SQL query and work it all out in a controller afterwards.

    ...

    Only about 3K lines of code like that in one controller

    My stomach actually knotted up thinking about what that work day must have been like.


  • Advertisement
  • Moderators, Computer Games Moderators, Technology & Internet Moderators Posts: 19,241 Mod ✭✭✭✭L.Jenkins


    One of the many many loops in one method. The old, lets just bring everything back in an SQL query and work it all out in a controller afterwards.
    Some Code
    

    And lets not forget
    More Code
    

    Only about 3K lines of code like that in one controller

    computer-smash-other-guys-Mark-Wahlberg-angry.gif


  • Registered Users, Registered Users 2 Posts: 6,260 ✭✭✭Buford T Justice


    Itzy wrote: »
    computer-smash-other-guys-Mark-Wahlberg-angry.gif

    That kinda sums it up. I'm the one that's left with servicing & trying to fix this steaming pile of scutter


  • Registered Users, Registered Users 2 Posts: 1,148 ✭✭✭punk_one82


    /**
         * this method is not used.
         * 
         * @param busEntity  Business Entity. 
         * @return null 
         */
    	@Override
    	public BenefitEntity methodName(final BusinessEntity busEntity) {
    		// Not used
    		return null;
    	}
    

    Stuff like this drives me mad, but probably not uncommon at all.


  • Moderators, Computer Games Moderators, Technology & Internet Moderators Posts: 19,241 Mod ✭✭✭✭L.Jenkins


    punk_one82 wrote: »
    /**
         * this method is not used.
         * 
         * @param busEntity  Business Entity. 
         * @return null 
         */
    	@Override
    	public BenefitEntity methodName(final BusinessEntity busEntity) {
    		// Not used
    		return null;
    	}
    

    Stuff like this drives me mad, but probably not uncommon at all.

    You mean stuffing methods in or leaving a bunch of shít hanging around when it's not needed? Working on Application migration and fault finding and have found way too much unnecessary crap in nearly every file I went through.


  • Registered Users, Registered Users 2 Posts: 1,148 ✭✭✭punk_one82


    Itzy wrote: »
    You mean stuffing methods in or leaving a bunch of shít hanging around when it's not needed? Working on Application migration and fault finding and have found way too much unnecessary crap in nearly every file I went through.

    Leaving a load of crap in the code. If a method has no use and somebody has the time to comment it saying so why not just remove the method.


  • Moderators, Recreation & Hobbies Moderators, Science, Health & Environment Moderators, Technology & Internet Moderators Posts: 92,471 Mod ✭✭✭✭Capt'n Midnight


    From the Most stupid requests you've ever had at work? thread
    Wossack wrote: »
    Database admin decides he needs to save some space on their sql servers, so goes through C:\windows and deletes all files whose filenames are blue (opposed to normal uncompressed black), thinking that meant they were backed up and redundant.

    Happy with his work, he scripts it, and runs it across another 23 servers before he cops the first one has keeled over.. and, like stars winking out in the night sky, the rest gradually follow suit


  • Technology & Internet Moderators Posts: 28,820 Mod ✭✭✭✭oscarBravo


    Oh.

    My.

    Teapot.

    :eek:


  • Registered Users, Registered Users 2 Posts: 7,498 ✭✭✭BrokenArrows


    Surely noone can be that stupid.


  • Registered Users Posts: 428 ✭✭[Rasta]


    Currently we have numerous VB scripts (inside BPM application workflows) that have hardcoded strings for database access...

    Not to mention the numerous 'temporary' fixes to these workflows which still grab information from dev servers (why in the sweet jesus would you do that anyway).

    There is no documentation for these workflows, because 'we make a lot of changes and documentation would just take too much time'.
    I looked through the publish history of these workflows, most hadn't had any change in the past 3 months. Adding people to CCs on emails that are sent by the workflow was a common reason given for a publish.

    Changes are usually published to live without testing (only a peer review is done to see if both people agree that the changes shouldn't cause an issue).

    A lot of the code either lacks comments or has comments which are out of date.
    Quite often method/function/member names have no correlation with their functionality/purpose or are even entirely misleading.


    I saw an if statement:
    if(archived == false && archivedInverse == true)
    ..some code

    and at some point earlier on:
    if(archived == true)
    archivedInverse = false
    else
    archivedInverse = true


    not a coding issue but:
    We backup data onto the same machine the data is on. After 3 days it is automatically picked up by an external company who copy it onto tapes.
    Someone requested a backup 2 weeks ago. Yet to see any progress.


  • Moderators, Computer Games Moderators, Technology & Internet Moderators Posts: 19,241 Mod ✭✭✭✭L.Jenkins


    Surely noone can be that stupid.

    You'd be surprised and I wouldn't be if the first thing they did on a Linux box was to run rm -rf / as an admin to save space also.


  • Advertisement
  • Moderators, Recreation & Hobbies Moderators, Science, Health & Environment Moderators, Technology & Internet Moderators Posts: 92,471 Mod ✭✭✭✭Capt'n Midnight




  • Moderators, Computer Games Moderators, Technology & Internet Moderators Posts: 19,241 Mod ✭✭✭✭L.Jenkins



    That was one of the best reads in a long time, apparently bricking the machine it was installed on.


  • Registered Users, Registered Users 2 Posts: 798 ✭✭✭FobleAsNuck




  • Closed Accounts Posts: 1,487 ✭✭✭Pov06


    if (some_var < 0)
        another_var -= abs(some_var);
    else
        another_var -= some_var;
    

    Kill me now :eek:


  • Closed Accounts Posts: 5,361 ✭✭✭Boskowski


    Pov06 wrote: »
    if (some_var < 0)
        another_var -= abs(some_var);
    else
        another_var -= some_var;
    

    Kill me now :eek:

    At least the compiler will sort that out. ;)


  • Registered Users, Registered Users 2 Posts: 8,585 ✭✭✭brevity


    Not quite a coding horror as such but a great article nonetheless

    http://www.stilldrinking.org/programming-sucks


  • Closed Accounts Posts: 1,487 ✭✭✭Pov06


    Boskowski wrote: »
    At least the compiler will sort that out. ;)

    The more worrying part is the fact that a developer with such concepts is working on big projects.


  • Closed Accounts Posts: 5,361 ✭✭✭Boskowski


    Pov06 wrote: »
    The more worrying part is the fact that a developer with such concepts is working on big projects.

    It is - although technically it's not wrong. Just a bit .... convoluted?

    The worrying bit is the obvious lack of understanding.


  • Registered Users Posts: 263 ✭✭not1but4


    Pov06 wrote: »
    if (some_var < 0)
        another_var -= abs(some_var);
    else
        another_var -= some_var;
    
    Kill me now :eek:
    At the risk of asking a very stupid question what is the issue with this?

    Is it the case if you where to use a 16 bit integer (range being -32768 to + 32767)

    You'd get the following;
    abs(-32767) = 32767
    abs(-32768) = -32768

    EDIT:
    What would be the correct implementation of this then?


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 13,080 ✭✭✭✭Maximus Alexander


    not1but4 wrote: »
    At the risk of asking a very stupid question what is the issue with this?

    Is it the case if you where to use a 16 bit integer (range being -32768 to + 32767)

    You'd get the following;
    abs(-32767) = 32767
    abs(-32768) = -32768

    No, it's that it's totally redundant.

    It could be replaced with
    another_var -= abs(some_var);
    


  • Registered Users, Registered Users 2 Posts: 5,574 ✭✭✭Slutmonkey57b


    not1but4 wrote: »
    At the risk of asking a very stupid question what is the issue with this?

    Is it the case if you where to use a 16 bit integer (range being -32768 to + 32767)

    You'd get the following;
    abs(-32767) = 32767
    abs(-32768) = -32768

    EDIT:
    What would be the correct implementation of this then?

    It's a waste of time. If a negative value return is possible, and you don't consider it an error, then you should just always abs() the original value returned and carry on.

    But fundamentally one should be suspicious that a negative value is treated the same as its positive counterpart. They're different values for a valid reason so either you're missing an error or the calculation which returned somevar is set up incorrectly.


  • Registered Users, Registered Users 2 Posts: 586 ✭✭✭Aswerty


    But fundamentally one should be suspicious that a negative value is treated the same as its positive counterpart. They're different values for a valid reason so either you're missing an error or the calculation which returned somevar is set up incorrectly.
    But there is plenty of times where the reason for the differing signs doesn't matter with regards to what you are calculating. That's why the abs() function exists in the first place. So I don't think it is reasonable to consider ignoring the sign as fundamentally suspicious.


  • Moderators, Technology & Internet Moderators Posts: 1,336 Mod ✭✭✭✭croo


    I read this a while back and never noticed it mentioned .. anywhere never mind this thread.

    This code came from the installation script for Steam for Linux
    # figure out the absolute path to the script being run a bit
    # non-obvious, the ${0%/*} pulls the path out of $0, cd's into the
    # specified directory, then uses $PWD to figure out where that
    # directory lives - and all this in a subshell, so we don't affect
    # $PWD
    STEAMROOT="$(cd "${0%/*}" && echo $PWD)"
    
    # Scary!
    rm -rf "$STEAMROOT/"*
    
    Of course the flaw is obvious. Even to the developer given their "Scary!" comment... still it is very easy to install Linux isn't it?

    Full story was on the register a few months back.


  • Registered Users, Registered Users 2 Posts: 5,574 ✭✭✭Slutmonkey57b


    Aswerty wrote: »
    But there is plenty of times where the reason for the differing signs doesn't matter with regards to what you are calculating. That's why the abs() function exists in the first place. So I don't think it is reasonable to consider ignoring the sign as fundamentally suspicious.

    True, but you'd need the context of the original code to be sure. Without it, my first question to the dev would be "why?"


  • Registered Users, Registered Users 2 Posts: 6,236 ✭✭✭Idleater


    croo wrote: »
    I read this a while back and never noticed it mentioned .. anywhere never mind this thread.

    This code came from the installation script for Steam for Linux
    # figure out the absolute path to the script being run a bit
    # non-obvious, the ${0%/*} pulls the path out of $0, cd's into the
    # specified directory, then uses $PWD to figure out where that
    # directory lives - and all this in a subshell, so we don't affect
    # $PWD
    STEAMROOT="$(cd "${0%/*}" && echo $PWD)"
    
    # Scary!
    rm -rf "$STEAMROOT/"*
    
    Of course the flaw is obvious. Even to the developer given their "Scary!" comment... still it is very easy to install Linux isn't it?

    Full story was on the register a few months back.
    Related rhel bug ?https://bugzilla.redhat.com/show_bug.cgi?id=1202858

    Had cause to Google Heisenbug this week, and duly found Hindenbug


  • Advertisement
  • Moderators, Technology & Internet Moderators Posts: 1,336 Mod ✭✭✭✭croo


    Idleater wrote: »
    Related rhel bug ?https://bugzilla.redhat.com/show_bug.cgi?id=1202858

    Had cause to Google Heisenbug this week, and duly found Hindenbug
    Wow... steam I might forgive but RHEL & squid? That must be an extremely common combination. Amazing!
    Hindenbug
    That's a new one for me too.


  • Closed Accounts Posts: 1,487 ✭✭✭Pov06


    not1but4 wrote: »
    At the risk of asking a very stupid question what is the issue with this?

    Is it the case if you where to use a 16 bit integer (range being -32768 to + 32767)

    You'd get the following;
    abs(-32767) = 32767
    abs(-32768) = -32768

    EDIT:
    What would be the correct implementation of this then?

    Just:
    another_var -= abs(some_var);
    

    Absolute value will always return a positive number no matter whether you supply a positive or negative.

    EDIT: Didn't notice it was answered already.


  • Registered Users, Registered Users 2 Posts: 1,275 ✭✭✭tobsey


    I've just been tasked with fixing bugs in a solution that was previously looked after by one of my colleagues who was let go a couple of months ago. The main page in the asp.net site has the following in the code-behind:
    line 896: protected void buttonGo_Click(object sender, EventArgs e)
                {
                      // Loads of validation code
    
    line 994:      if (myDropdown.SelectedValue = MyValues.Value1.ToString())
                      {
                             // set a load of values in a repository
                             // trigger a change in state
                      }
    line 1291:     else if (myDropdown.SelectedValue = MyValues.Value2.ToString())
                      {
                             // set a load of the same values in a repository
                             // trigger a different change in state
                      }
    line 1306:     else if (myDropdown.SelectedValue = MyValues.Value3.ToString())
                      {
                             // set a load of the same values in a repository
                             // trigger a different change in state
                      }
    line 1321:     else if (myDropdown.SelectedValue = MyValues.Value4.ToString())
                      {
                             // set a load of the same values in a repository
                             // trigger a different change in state
                      }
    line 1456:     else if (myDropdown.SelectedValue = MyValues.Value5.ToString())
                      {
                             // set a load of the same values in a repository
                             // trigger a different change in state
                      }
    
    // six more of these else if statements
    
    line 2153: }
    


  • Moderators, Computer Games Moderators, Technology & Internet Moderators Posts: 19,241 Mod ✭✭✭✭L.Jenkins


    Did he or she ever hear of switch/case? I could understand if they were working with 2/3 cases, but 11! I'm sure that some how you could condense that down even further/tidy it up.


  • Closed Accounts Posts: 5,191 ✭✭✭Eugene Norman


    Switch statements are syntax sugar. It would still be as long a function, and long functions are my bugbear. Switch statements often -- like this else if -- have huge amounts of code per statement that could be factored out. also I don't know asp.net but surely a method could be set for each menu item.

    Edit. Oh, it looks like the same code bar some state setting is set in each if statement. I've seen the same in switch statements.


  • Advertisement
  • Technology & Internet Moderators Posts: 28,820 Mod ✭✭✭✭oscarBravo


    Interestingly, Python doesn't have a switch statement; it has an if/elif/else construct similar to the above.


  • Moderators, Science, Health & Environment Moderators, Social & Fun Moderators, Society & Culture Moderators Posts: 60,104 Mod ✭✭✭✭Tar.Aldarion


    It's either easy or hard to code switch equivalency in python, it depends on whether you view fall through as a feature or a bug :pac:


  • Registered Users, Registered Users 2 Posts: 1,275 ✭✭✭tobsey


    Switch statements are syntax sugar. It would still be as long a function, and long functions are my bugbear. Switch statements often -- like this else if -- have huge amounts of code per statement that could be factored out. also I don't know asp.net but surely a method could be set for each menu item.

    Edit. Oh, it looks like the same code bar some state setting is set in each if statement. I've seen the same in switch statements.

    Bingo. DRY seems to have been completely lost on him.

    Another favourite of mine in the codebase:
    foreach (KeyValuePair<string, string> myData in SQLDal.GetSomeData())
                {
                    if (myData.Key.ToString() == keyDropDown.SelectedValue)
                    {
                        valueDropDown.SelectedValue = myData.Key;
                    }
                    else if (keyDropDown.SelectedValue.Trim() == "")
                    {
                        valueDropDown.SelectedValue = " ";
                    }
                }
    

    For all records in DB
    --> if a field matches record, set other field.
    --> Else if field is blank, clear other field

    So if 100 records are returned from the DB and none match, we will have checked a field on our form 100 times for an empty string.


  • Moderators, Science, Health & Environment Moderators, Social & Fun Moderators, Society & Culture Moderators Posts: 60,104 Mod ✭✭✭✭Tar.Aldarion




  • Moderators, Computer Games Moderators, Technology & Internet Moderators Posts: 19,241 Mod ✭✭✭✭L.Jenkins



    One innovative way to keep a job for yourself.


  • Registered Users, Registered Users 2 Posts: 3,992 ✭✭✭Korvanica



    Our software just got slightly slower... until I come save the day.:cool:


  • Registered Users, Registered Users 2 Posts: 2,815 ✭✭✭SimonTemplar


        Our core system is written in a proprietary language developed by our vendor and used only by the vendor’s applications. I occasionally do some coding in it mostly for data extracts. Was writing a script today and it was failing (it doesn’t provide a line number or even a reason for the error, just a big fat fail). Spent over an hour trying to debug and couldn’t understand what was happening. Got support from the vendor – it turns out that the language is designed so that you can only set the value of a variable once. If you try to change a variable’s value, it will fail. What a pile of absolute crap!!


  • Registered Users, Registered Users 2 Posts: 8,219 ✭✭✭Calina


        Our core system is written in a proprietary language developed by our vendor and used only by the vendor’s applications. I occasionally do some coding in it mostly for data extracts. Was writing a script today and it was failing (it doesn’t provide a line number or even a reason for the error, just a big fat fail). Spent over an hour trying to debug and couldn’t understand what was happening. Got support from the vendor – it turns out that the language is designed so that you can only set the value of a variable once. If you try to change a variable’s value, it will fail. What a pile of absolute crap!!

    Surely that's not then a variable, but a constant, no?


  • Registered Users, Registered Users 2 Posts: 2,815 ✭✭✭SimonTemplar


    Calina wrote: »
    Surely that's not then a variable, but a constant, no?

    If that's the case, this language only has constants and no variables.


  • Registered Users, Registered Users 2 Posts: 18 jonster


    Could be immutable variables ala functional programming languages?


  • Advertisement
Advertisement