New OOTS products from CafePress
New OOTS t-shirts, ornaments, mugs, bags, and more
Page 1 of 2 12 LastLast
Results 1 to 30 of 42

Thread: Raaaagggghhhh

  1. - Top - End - #1
    Titan in the Playground
     
    Planetar

    Join Date
    Dec 2006
    Location
    Raleigh NC
    Gender
    Male

    Default Raaaagggghhhh

    Dear fellow programmers.

    This is me, your friendly neighborhood senior R&D guy and software engineer, just working through reverse engineering someone else's pile of , erm, handcrafted "masterpiece".

    Imagine, if you will, that one of your attributes is an array.

    Imagine, if you will, that this is in a language which can either be zero-based or one-based. That is, the first index can be either 0 or 1, depending on how the array is constructed.

    Imagine that I, the maintainer, am tasked with a guessing game of figuring out which it is based on context.

    You know what?

    If I find this in two different methods in the same class?

    for (i=0;i<nStuff;i++){}
    for (i=1;i<=nstuff;i++){}

    Then SOMEONE IS GOING TO DIE SCREAMING AND IT IS NOT ME.

    *Pant pant pant*

    Thank you.

    Returning now to his normal respectful self,

    Brian P.
    "Every lie we tell incurs a debt to the truth. Sooner or later, that debt is paid."

    -Valery Legasov in Chernobyl

  2. - Top - End - #2
    Colossus in the Playground
    Join Date
    Dec 2010
    Location
    right behind you

    Default Re: Raaaagggghhhh

    /puts on jock face "NEEERRRRRRRRRRDDDDDD!!!!!!!!!"

    That out of the way, I have no idea what the hell any of that means, but I can tell by the context that you are a mite frustrated. I hopw things work out for you. (Did my generic well wishes help?)
    "Interdum feror cupidine partium magnarum Europae vincendarum"
    Translation: "Sometimes I get this urge to conquer large parts of Europe."

    Quote Originally Posted by Nerd-o-rama View Post
    Traab is yelling everything that I'm thinking already.
    "If you don't get those cameras out of my face, I'm gonna go 8.6 on the Richter scale with gastric emissions that'll clear this room."

  3. - Top - End - #3
    Titan in the Playground
     
    Planetar

    Join Date
    Dec 2006
    Location
    Raleigh NC
    Gender
    Male

    Default Re: Raaaagggghhhh

    They did, yes. :)

    To get some idea of the frustration level, try to imagine that someone handed you a 3.5 character sheet, and it had a bunch of leftover stuff like THAC0 from previous editions on it, and it was your job to make sense of it.

    I suspect what most DMs would do is tell the player their character was tragically killed by a meteor strike and to roll up a new one properly this time.

    Respectfully,

    Brian P.
    "Every lie we tell incurs a debt to the truth. Sooner or later, that debt is paid."

    -Valery Legasov in Chernobyl

  4. - Top - End - #4
    Troll in the Playground
     
    gooddragon1's Avatar

    Join Date
    Dec 2005
    Location
    In the playground

    Default Re: Raaaagggghhhh

    Quote Originally Posted by pendell View Post
    They did, yes. :)

    To get some idea of the frustration level, try to imagine that someone handed you a 3.5 character sheet, and it had a bunch of leftover stuff like THAC0 from previous editions on it, and it was your job to make sense of it.

    I suspect what most DMs would do is tell the player their character was tragically killed by a meteor strike and to roll up a new one properly this time.

    Respectfully,

    Brian P.
    All I got out of your initial comment was 2 for loops. I have no idea how you're supposed to guess stuff like that. Then again I have not much of an idea about how people make trainers for games that I have difficulty even using cheat engine on and the addresses change each time and yet somehow they make it work? Well good luck to you. I'm still learning java :(
    There is no emotion more useless in life than hate.

  5. - Top - End - #5
    Titan in the Playground
     
    TuggyNE's Avatar

    Join Date
    Jun 2011
    Gender
    Male

    Default Re: Raaaagggghhhh

    Quote Originally Posted by pendell View Post
    Imagine, if you will, that one of your attributes is an array.

    Imagine, if you will, that this is in a language which can either be zero-based or one-based. That is, the first index can be either 0 or 1, depending on how the array is constructed.

    Imagine that I, the maintainer, am tasked with a guessing game of figuring out which it is based on context.

    You know what?

    If I find this in two different methods in the same class?

    for (i=0;i<nStuff;i++){}
    for (i=1;i<=nstuff;i++){}
    That is pretty painful. But take heart! At least there's no loop that goes
    for (i=0;i<=nStuff;i++){}
    or
    for (i=1;i<nstuff;i++){}

    … right? Right?

    Spoiler: Commiserating example of my own
    Show
    I think my favorite horrible code was a sample program for a commercial web API product, which consisted chiefly of a single large multi-tab form in VB.NET. And by "large" I mean not only physically, but code-wise, and there was enormous duplication of everything. There were maybe a dozen event procedures to handle several dozen API calls, each thousands of lines long and filled with nested conditionals six deep, and I'm not sure if there weren't a few labels for gotoing in there too. Worse yet, there were very few comments, error handling was minimal and inconsistent, the examples were not wholly complete, and I could observe the occasional apparent error in the code, which made it decidedly less than useful for most purposes. But since all we had was that, our own experience with the API, and sparse online documentation, we had to use it anyway. *tear*
    Quote Originally Posted by Water_Bear View Post
    That's RAW for you; 100% Rules-Legal, 110% silly.
    Quote Originally Posted by hamishspence View Post
    "Common sense" and "RAW" are not exactly on speaking terms
    Projects: Homebrew, Gentlemen's Agreement, DMPCs, Forbidden Knowledge safety, and Top Ten Worst. Also, Quotes and RACSD are good.

    Anyone knows blue is for sarcas'ing in · "Take 10 SAN damage from Dark Orchid" · Use of gray may indicate nitpicking · Green is sincerity

  6. - Top - End - #6
    Bugbear in the Playground
     
    shawnhcorey's Avatar

    Join Date
    Dec 2010
    Location
    The Great White North
    Gender
    Male

    Default Re: Raaaagggghhhh

    And, of course, the documentation explains it all.
    How do you keep a fool busy? Turn upside down for answer.
    ˙ɹǝʍsuɐ ɹoɟ uʍop ǝpısdn uɹnʇ ¿ʎsnq ןooɟ ɐ dǝǝʞ noʎ op ʍoɥ

  7. - Top - End - #7
    Titan in the Playground
     
    Planetar

    Join Date
    Dec 2006
    Location
    Raleigh NC
    Gender
    Male

    Default Re: Raaaagggghhhh

    All I got out of your initial comment was 2 for loops.
    The key point is that I'm trying to figure out whether the array is zero-based or one-based, and the writer did it both ways . Because he could .

    Correct procedure would have been to stay consistent -- either do it all zero-based or do it all one-based, but for pity's sake don't mix the two.

    This is especially true if this array is being populated by ... well, never mind. That's too much information. Suffice it to say this array is being interacted with from multiple sources, and therefore the ordering and position are critical.

    Here is a truth of coding: Unless you are doing something like hard-realtime, where every microsecond counts, readability and consistency win over clever any day of the week and twice on Sunday.

    I solved it and made it consistent, of course. Still won't stop me nailing the coder up by his figgin* if I ever find him.

    @TuggyNE: Totally agreed and commisseration shared. :).

    Respectfully,

    Brian P.

    * A small pastry with raisins.
    Last edited by pendell; 2013-11-12 at 05:55 PM.
    "Every lie we tell incurs a debt to the truth. Sooner or later, that debt is paid."

    -Valery Legasov in Chernobyl

  8. - Top - End - #8
    Colossus in the Playground
     
    Flickerdart's Avatar

    Join Date
    Mar 2008
    Location
    NYC
    Gender
    Male

    Default Re: Raaaagggghhhh

    Why does the language even allow one to have one-based arrays? Zero-based can do everything that one-based can.
    Quote Originally Posted by Inevitability View Post
    Greater
    \ˈgrā-tər \
    comparative adjective
    1. Describing basically the exact same monster but with twice the RHD.
    Quote Originally Posted by Artanis View Post
    I'm going to be honest, "the Welsh became a Great Power and conquered Germany" is almost exactly the opposite of the explanation I was expecting

  9. - Top - End - #9
    Troll in the Playground
    Join Date
    Jan 2012

    Default Re: Raaaagggghhhh

    Quote Originally Posted by Flickerdart View Post
    Why does the language even allow one to have one-based arrays? Zero-based can do everything that one-based can.
    Could that even be an option? If you can start an array at zero, couldn't you also just start it at one just as easily?

  10. - Top - End - #10
    Surgebinder in the Playground Moderator
     
    Douglas's Avatar

    Join Date
    Aug 2005
    Location
    Mountain View, CA
    Gender
    Male

    Default Re: Raaaagggghhhh

    Allow me to introduce you to a great big regularly updated repository of similar stories for you to shake your head at and be glad at least you're not dealing with <insert X entry here>.

    Degree of coding terribleness varies highly between entries. Some situations described there will be less bad than yours.
    Like 4X (aka Civilization-like) gaming? Know programming? Interested in game development? Take a look.

    Avatar by Ceika.

    Archives:
    Spoiler
    Show
    Saberhagen's Twelve Swords, some homebrew artifacts for 3.5 (please comment)
    Isstinen Tonche for ECL 74 playtesting.
    Team Solars: Powergaming beyond your wildest imagining, without infinite loops or epic. Yes, the DM asked for it.
    Arcane Swordsage: Making it actually work (homebrew)

  11. - Top - End - #11
    Colossus in the Playground
     
    BlackDragon

    Join Date
    Feb 2007
    Location
    Manchester, UK
    Gender
    Male

    Default Re: Raaaagggghhhh

    Quote Originally Posted by Flickerdart View Post
    Why does the language even allow one to have one-based arrays? Zero-based can do everything that one-based can.
    But if you actually *want* your array to start at 1, and your language only allows zero base, you end up allocating an array element that you'll never use. It's actually possible in some languages (VB.NET, for example) to declare an array whose starting bound is any arbitrary number you choose, and that can sometimes be darned useful!

  12. - Top - End - #12
    Troll in the Playground
    Join Date
    May 2011
    Location
    France
    Gender
    Female

    Default Re: Raaaagggghhhh

    I remember, during my computer lessons, I once came up with code that functioned perfectly well but used some weird logic (can't remember the language though). The teacher looked at me skeptically, and he'd never seen such a thing, but had to admit it worked. He didn't seem to enjoy my thinking outside the box, but I never quite understood why. I mean, it worked! And I couldn't imagine a situation where it wouldn't!
    Now, I'm starting to understand his pain.
    Apologizing to you by proxy.
    Quote Originally Posted by on Dwarf Fortress succession games
    I have no idea where anything is. I have no idea what anything does. This is not merely a madhouse designed by a madman, but a madhouse designed by many madmen, each with an intense hatred for the previous madman's unique flavour of madness.
    Quote Originally Posted by Dwarf Fortress 0.40.01 bugs
    - If an adventurer shouts and nobody is around to hear it, the game crashes
    - War Dogs appear to run from themselves in terror
    - New tree generation frequently causes birds to explode

  13. - Top - End - #13
    Troll in the Playground
     
    Flumph

    Join Date
    Nov 2006
    Location
    England. Ish.
    Gender
    Male

    Default Re: Raaaagggghhhh

    Quote Originally Posted by pendell View Post
    The key point is that I'm trying to figure out whether the array is zero-based or one-based, and the writer did it both ways . Because he could .

    Correct procedure would have been to stay consistent -- either do it all zero-based or do it all one-based, but for pity's sake don't mix the two.

    ...

    I solved it and made it consistent, of course. Still won't stop me nailing the coder up by his figgin* if I ever find him.

    * A small pastry with raisins.
    Are you sure it was the same programmer both times? I have seen some really weird bits of code come about because different programmers have worked on the same piece of code at different times. And usually not updated the header comments.

    ...Although you would think that an off-by-one error at the beginning of the array would show up when they tested the code. Oh yes... assumption there...

    (And the Pratchett references are always welcome...)
    Last edited by Manga Shoggoth; 2013-11-13 at 05:14 AM.
    Warning: This posting may contain wit, wisdom, pathos, irony, satire, sarcasm and puns. And traces of nut.

    "The main skill of a good ruler seems to be not preventing the conflagrations but rather keeping them contained enough they rate more as campfires." Rogar Demonblud

    "Hold on just a d*** second. UK has spam callers that try to get you to buy conservatories?!? Even y'alls spammers are higher class than ours!" Peelee

  14. - Top - End - #14
    Ettin in the Playground
     
    dehro's Avatar

    Join Date
    May 2007
    Gender
    Male

    Default Re: Raaaagggghhhh

    things can't be too bad if you can still quote Pratchett.
    All hail Smutmulch for crafting my avatar!
    Quote Originally Posted by kpenguin View Post
    Cursed zombies are more realistic.
    Spoiler: siggatar and previous avatars.
    Show

    the Badass Monkby Avi. Aktarus by Chd. Dehro by Wojiz


  15. - Top - End - #15
    Titan in the Playground
     
    nedz's Avatar

    Join Date
    Apr 2010
    Location
    London, EU
    Gender
    Male

    Default Re: Raaaagggghhhh

    I've seen far worse, at least the examples work.
    π = 4
    Consider a 5' radius blast: this affects 4 squares which have a circumference of 40' — Actually it's worse than that.


    Completely Dysfunctional Handbook
    Warped Druid Handbook

    Avatar by Caravaggio

  16. - Top - End - #16
    Titan in the Playground
     
    TuggyNE's Avatar

    Join Date
    Jun 2011
    Gender
    Male

    Default Re: Raaaagggghhhh

    Quote Originally Posted by shawnhcorey View Post
    And, of course, the documentation explains it all.
    You wish. No, it was mostly "here are the elements of this structure, just as you can see in Object Browser, with no additional information on how they're used or what they mean".

    Quote Originally Posted by nedz View Post
    I've seen far worse, at least the examples work.
    Most of the examples worked. Mostly. Except when they didn't. And they weren't good at showing all the possible cases, so it was hard to figure out whether you'd made a mistake in adapting, or whether the API was buggy, or whether the example would have handled it wrong too, or what.

    Protip: the API, which was on version 4, was not infrequently subtly buggy.

    Quote Originally Posted by pendell View Post
    Here is a truth of coding: Unless you are doing something like hard-realtime, where every microsecond counts, readability and consistency win over clever any day of the week and twice on Sunday.
    Because Sunday is both 0 and 7, of course.

    (Also, agreed wholeheartedly.)

    @TuggyNE: Totally agreed and commisseration shared. :)
    Heh, thanks.
    Quote Originally Posted by Water_Bear View Post
    That's RAW for you; 100% Rules-Legal, 110% silly.
    Quote Originally Posted by hamishspence View Post
    "Common sense" and "RAW" are not exactly on speaking terms
    Projects: Homebrew, Gentlemen's Agreement, DMPCs, Forbidden Knowledge safety, and Top Ten Worst. Also, Quotes and RACSD are good.

    Anyone knows blue is for sarcas'ing in · "Take 10 SAN damage from Dark Orchid" · Use of gray may indicate nitpicking · Green is sincerity

  17. - Top - End - #17
    Ogre in the Playground
     
    Krazzman's Avatar

    Join Date
    Jul 2011
    Location
    Aachen, Germany
    Gender
    Male

    Default Re: Raaaagggghhhh

    I would've recommended making it consistent. But the I=1 or I=0 is not the only indicator for what sort of array you have there.

    But now imagine this: COBOL. In a big company. Where multiple Programs are pieced together from different developers. And you have some grown progams that were written some 15 or more years ago (oldest one I saw was from 1995 here). And were handled by different people for every change.
    and switching between formats and how they write and how long you can make a section (for the ones not knowing COBOL basically a method without parameters) before you can't read it anymore. Arbitrary Variable names and as if that isn't enough limited space. you have room for only ~60 characters and some variables have a namelength of 20 characters... or more.

    Then additionally I can now program in SAS and have already seen a program where everything was bound to the left and the formatting was terrible.
    Have a nice Day,
    Krazzman

  18. - Top - End - #18
    Titan in the Playground
     
    ElfRangerGuy

    Join Date
    Aug 2007
    Location
    Imagination Land
    Gender
    Male

    Default Re: Raaaagggghhhh

    Quote Originally Posted by pendell View Post
    Imagine, if you will, that this is in a language which can either be zero-based or one-based. That is, the first index can be either 0 or 1, depending on how the array is constructed.
    I'm not sure which language that is, but it sounds like a HUGE MISTAKE. I'm thankful that I mostly stick to C-family languages.
    "Nothing you can't spell will ever work." - Will Rogers

    Watch me draw and swear at video games.

  19. - Top - End - #19
    Bugbear in the Playground
     
    shawnhcorey's Avatar

    Join Date
    Dec 2010
    Location
    The Great White North
    Gender
    Male

    Default Re: Raaaagggghhhh

    Quote Originally Posted by KillianHawkeye View Post
    I'm not sure which language that is, but it sounds like a HUGE MISTAKE. I'm thankful that I mostly stick to C-family languages.
    Actually, in Perl, you can change the base of all arrays to any integer. Not recommended though.
    How do you keep a fool busy? Turn upside down for answer.
    ˙ɹǝʍsuɐ ɹoɟ uʍop ǝpısdn uɹnʇ ¿ʎsnq ןooɟ ɐ dǝǝʞ noʎ op ʍoɥ

  20. - Top - End - #20
    Titan in the Playground
    Join Date
    May 2007
    Location
    Tail of the Bellcurve
    Gender
    Male

    Default Re: Raaaagggghhhh

    Quote Originally Posted by Krazzman View Post
    Then additionally I can now program in SAS and have already seen a program where everything was bound to the left and the formatting was terrible.
    You poor bastard. SAS is just such a misery to use, at least for statistics. Except for ANOVA models, which it does approximately 1000% better than anything else. R needs to change their lm() function to just run SAS.
    Blood-red were his spurs i' the golden noon; wine-red was his velvet coat,
    When they shot him down on the highway,
    Down like a dog on the highway,
    And he lay in his blood on the highway, with the bunch of lace at his throat.


    Alfred Noyes, The Highwayman, 1906.

  21. - Top - End - #21
    Ettin in the Playground
     
    Kobold

    Join Date
    May 2005
    Location
    Somerville, MA
    Gender
    Male

    Default Re: Raaaagggghhhh

    Quote Originally Posted by Grinner View Post
    Could that even be an option? If you can start an array at zero, couldn't you also just start it at one just as easily?
    I know lua starts at 1 instead of 0. But as far as I'm aware, that's always the case. Using an inconsistent start point sounds awful, unless you have foreach/for in/some other way of iterating over all the things without knowing the index.

    Here's my comisery. Today I was splitting up a function that had grown into 1000 lines into a set of classes. There was one point where a set of IDs was gathered and passed to the database as a condition to limit what you could query for.

    Someone felt it necessary to check the size of the array of IDs. When it was 1, they set the value to the only item in the array and the comparison to =. When it was more than one, they kept the array as the value and set the comparison to IN. They could have just left it alone and asserted that the id was in the array that only had one value, but instead introduced two extra vars.

    In retrospect this doesn't sound that bad. Except that `git blame` told me our team lead wrote that code and now I'm not sure if I should trust him anymore.
    If you like what I have to say, please check out my GMing Blog where I discuss writing and roleplaying in greater depth.

  22. - Top - End - #22
    Colossus in the Playground
     
    Flickerdart's Avatar

    Join Date
    Mar 2008
    Location
    NYC
    Gender
    Male

    Default Re: Raaaagggghhhh

    Quote Originally Posted by factotum View Post
    But if you actually *want* your array to start at 1, and your language only allows zero base, you end up allocating an array element that you'll never use. It's actually possible in some languages (VB.NET, for example) to declare an array whose starting bound is any arbitrary number you choose, and that can sometimes be darned useful!
    Is having an empty cell in an array such a sin that programmers must suffer for it?
    Quote Originally Posted by Inevitability View Post
    Greater
    \ˈgrā-tər \
    comparative adjective
    1. Describing basically the exact same monster but with twice the RHD.
    Quote Originally Posted by Artanis View Post
    I'm going to be honest, "the Welsh became a Great Power and conquered Germany" is almost exactly the opposite of the explanation I was expecting

  23. - Top - End - #23
    Ogre in the Playground
    Join Date
    Oct 2011
    Location
    The last place you look
    Gender
    Male

    Default Re: Raaaagggghhhh

    At least the only times I start a for loop at 1 is when I mean it. Cases where I really don't need to iterate over the 0th element.

    for (int i = 1; i <= n; i++) is just ugly. I even use for (int i = 0; i < n; i++) when I just need to repeat something n times.

    The ONLY time recently I've done something slightly bizarre was when I had a slew of stats functions to perform on an array (min, max, mean, variance) and wanted to get them all done in one loop.

    Speaking of which, programming challenge: Write a method to find the variance of an array of double... IN A SINGLE LOOP
    Avatar by Venetian Mask. It's of an NPC from a campaign I may yet run (possibly in PbP) who became a favorite of mine while planning.

    Quote Originally Posted by Razanir View Post
    Everyone knows frying pans are actually weapons that people repurpose for cooking
    I am a 10/14/11/15/12/14 LG Clr 2

  24. - Top - End - #24
    Colossus in the Playground
     
    BlackDragon

    Join Date
    Feb 2007
    Location
    Manchester, UK
    Gender
    Male

    Default Re: Raaaagggghhhh

    Quote Originally Posted by Flickerdart View Post
    Is having an empty cell in an array such a sin that programmers must suffer for it?
    It's this sort of attitude that's why a modern-day copy of Windows needs 2Gb of RAM before it even wants to get out of bed in the morning, you realise?

  25. - Top - End - #25
    Retired Mod in the Playground Retired Moderator
     
    Savannah's Avatar

    Join Date
    Feb 2010
    Location
    Texas. It's too hot here.
    Gender
    Female

    Default Re: Raaaagggghhhh

    Quote Originally Posted by pendell View Post
    To get some idea of the frustration level, try to imagine that someone handed you a 3.5 character sheet, and it had a bunch of leftover stuff like THAC0 from previous editions on it, and it was your job to make sense of it.
    I actually once had someone come to a 3.5 game I was running with minimal play experience, but they had done a fair bit of reading. Unfortunately, one of the books they'd read was the Player's Handbook II. The Fourth Edition PHBII. Took me aaaaages to figure out why they were saying totally random things and citing PHBII. Then once I'd figured it out, I couldn't make them understand the problem. So, yeah. I understand the pain, even if I'm not a programmer.
    Knowledge is power.
    Power corrupts.
    Study hard.
    Be evil.

  26. - Top - End - #26
    Titan in the Playground
     
    TuggyNE's Avatar

    Join Date
    Jun 2011
    Gender
    Male

    Default Re: Raaaagggghhhh

    Quote Originally Posted by Flickerdart View Post
    Is having an empty cell in an array such a sin that programmers must suffer for it?
    Sometimes, yes. Cases where starting at 1 is semantically desirable are fairly common (counting occurrences of values in some particular range, perhaps), and while rare, there are a few examples where starting at 2, or 5, or 7, or even much higher numbers, are useful (for example, total sales in a given year, starting with the year a company was founded).

    The same attitude could perhaps be held toward, say, variable names longer than 6 characters: "aw, come on, what do you really need that for?"
    Quote Originally Posted by Water_Bear View Post
    That's RAW for you; 100% Rules-Legal, 110% silly.
    Quote Originally Posted by hamishspence View Post
    "Common sense" and "RAW" are not exactly on speaking terms
    Projects: Homebrew, Gentlemen's Agreement, DMPCs, Forbidden Knowledge safety, and Top Ten Worst. Also, Quotes and RACSD are good.

    Anyone knows blue is for sarcas'ing in · "Take 10 SAN damage from Dark Orchid" · Use of gray may indicate nitpicking · Green is sincerity

  27. - Top - End - #27
    Titan in the Playground
     
    Planetar

    Join Date
    Dec 2006
    Location
    Raleigh NC
    Gender
    Male

    Default Re: Raaaagggghhhh

    Quote Originally Posted by Flickerdart View Post
    Is having an empty cell in an array such a sin that programmers must suffer for it?
    Imagine that you have an array of sensors that someone else must call. Imagine that the caller sends you a request for sensor 3. Okay, so does that mean they want the third sensor in the array or the fourth?

    The only way to know this is to know whether the array starts with 0 or with 1.

    Get it wrong and you might, say, send them the output from the aneroid altimeter instead of the radar altimeter. A distinction so small as to be trivial , so small it will never be caught in testing against the canned data set you feed it ... until you get a small number of edge cases where 'minimal difference' becomes critical and then this happens .

    Most accidents and disasters that result from software or from engineering aren't from obvious errors that get caught in testing. Most problems and disasters happen because a train of errors occur in a sequence impossible to predict, so that each one error, trivial in itself, taken together turns into a catastrophe. As with the challenger .

    Then again, sometimes things like this are just from plain miscommunication. Case in point: The Mars Climate Orbiter . I suspect both the software on the spacecraft and the software on the ground passed rigorous quality control tests and someone signed off on all of it. But no one noticed that the ground unit was sending acceleration in pound-force, while the spacecraft was expecting Newtons. Result? One $125 million crater on the surface of Mars and years of wasted work.

    This is the same sort of thing. A small, seemingly insignificant error that works in 99.5% of cases but, because it does something a little bit different than you would expect, opens up a potential for misunderstanding. Even if the code does work absolutely perfectly without problem, the original coder wrote it that way presumably because he figured no one else would ever touch it . Even if it works right the potential for a maintenance programmer to mess it up is quite high.

    So, again, consistency and readability are critical in any program save low-level assembly or real-time coding.

    This is also, why, incidentally, KDSI is a terrible metric for measuring productivity. I'd rather have 10 well-written lines at the end of the day that work than 1000 lines that will require extensive debugging because the person was in a hurry. It's like measuring the creator of a jigsaw puzzle by the number of pieces in it -- a small rubik's cube which elegantly fits together is much preferable to a 1000 piece monstrosity, especially if 100 of those pieces don't fit.

    Respectfully,

    Brian P.
    Last edited by pendell; 2013-11-14 at 07:53 AM.
    "Every lie we tell incurs a debt to the truth. Sooner or later, that debt is paid."

    -Valery Legasov in Chernobyl

  28. - Top - End - #28
    Titan in the Playground
    Join Date
    May 2007
    Location
    Tail of the Bellcurve
    Gender
    Male

    Default Re: Raaaagggghhhh

    Quote Originally Posted by Razanir View Post
    Speaking of which, programming challenge: Write a method to find the variance of an array of double... IN A SINGLE LOOP
    Sufficient statistics baby. All you need is the sum of squared observations, the overall sum, and the number of observations. Though that's less a programming answer than it is knowing that the first and second sample moments are sufficient for the first and second population moments, and the variance, being the second central moment, is easily writable as a function of the non-central moments.
    Blood-red were his spurs i' the golden noon; wine-red was his velvet coat,
    When they shot him down on the highway,
    Down like a dog on the highway,
    And he lay in his blood on the highway, with the bunch of lace at his throat.


    Alfred Noyes, The Highwayman, 1906.

  29. - Top - End - #29
    Titan in the Playground
     
    Planetar

    Join Date
    Dec 2006
    Location
    Raleigh NC
    Gender
    Male

    Default Re: Raaaagggghhhh

    Quote Originally Posted by Razanir View Post

    Speaking of which, programming challenge: Write a method to find the variance of an array of double... IN A SINGLE LOOP
    Challenge accepted.

    Spoiler
    Show

    Code:
    /** Find variance by subtracting the square of the mean from the mean of      
      * the squares. See
      * http://www.mun.ca/biology/scarr/Simplified_calculation_of_variance.html
      * @param pSampleArray: array of sample data whose variance must be 
      * calculated.
      * @return  A Double representing the variance, or null in the case of 
      * an empty or non-existent array.
      */ 
    public Double calculateVariance (Double[] pSampleArray) { 
    
    	if (pSampleArray == null || pSampleArray.size() == 0) { 
    		return null;
    	} 
    
    	Double result = new Double(0); 
    	Double mean = new Double(0); 
    	Double meanOfSquares = new Double(0); 
    
    	for (Double currentValue : pSampleArray) { 
    		mean += currentValue;
    		meanOfSquares += currentValue * currentValue;					
    		}
    
    	mean /= pSampleArray.size(); 
    	meanOfSquares /= pSampleArray.size(); 
    	result = meanOfSquares - (mean * mean); 
    	return result; 
    }


    Comments, criticism, feedback welcome.

    ETA: You'll notice I have deliberately coded as clearly as possible. I believe this is in some ways more important than accuracy -- it is possible that I've goofed the algorithm, and the error is therefore easy to spot and correct.

    By contrast, 'clever', obfuscated code is a nightmare to comprehend even when it works as it should.

    I write my code to be read and maintained by people of moderate intelligence, not geniuses. Even if I have a genius working for me, I have better use for her
    brains than deciphering lousy code.

    Respectfully,

    Brian P.
    Last edited by pendell; 2013-11-14 at 02:21 PM.
    "Every lie we tell incurs a debt to the truth. Sooner or later, that debt is paid."

    -Valery Legasov in Chernobyl

  30. - Top - End - #30
    Ogre in the Playground
    Join Date
    Oct 2011
    Location
    The last place you look
    Gender
    Male

    Default Re: Raaaagggghhhh

    Quote Originally Posted by warty goblin View Post
    Sufficient statistics baby. All you need is the sum of squared observations, the overall sum, and the number of observations. Though that's less a programming answer than it is knowing that the first and second sample moments are sufficient for the first and second population moments, and the variance, being the second central moment, is easily writable as a function of the non-central moments.
    Yeah, it really isn't that difficult. I'd mainly mentioned it because I was helping someone on CS homework, and I don't think he was expecting that. So convenient being able to find the mean, variance, min and max in a single for loop...
    Avatar by Venetian Mask. It's of an NPC from a campaign I may yet run (possibly in PbP) who became a favorite of mine while planning.

    Quote Originally Posted by Razanir View Post
    Everyone knows frying pans are actually weapons that people repurpose for cooking
    I am a 10/14/11/15/12/14 LG Clr 2

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •