Results 1 to 30 of 42
Thread: Raaaagggghhhh
-
2013-11-12, 03:53 PM (ISO 8601)
- Join Date
- Dec 2006
- Location
- Raleigh NC
- Gender
Raaaagggghhhh
Dear fellow programmers.
This is me, your friendly neighborhood senior R&D guy and software engineer, just working through reverse engineering someone else'spile 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
-
2013-11-12, 04:00 PM (ISO 8601)
- Join Date
- Dec 2010
- Location
- right behind you
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."
"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."
-
2013-11-12, 04:14 PM (ISO 8601)
- Join Date
- Dec 2006
- Location
- Raleigh NC
- Gender
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
-
2013-11-12, 05:14 PM (ISO 8601)
- Join Date
- Dec 2005
- Location
- In the playground
Re: Raaaagggghhhh
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.
-
2013-11-12, 05:27 PM (ISO 8601)
- Join Date
- Jun 2011
- Gender
Re: Raaaagggghhhh
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 ownI 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*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
-
2013-11-12, 05:34 PM (ISO 8601)
- Join Date
- Dec 2010
- Location
- The Great White North
- Gender
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ɥ
-
2013-11-12, 05:54 PM (ISO 8601)
- Join Date
- Dec 2006
- Location
- Raleigh NC
- Gender
Re: Raaaagggghhhh
All I got out of your initial comment was 2 for loops.
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
-
2013-11-12, 07:46 PM (ISO 8601)
- Join Date
- Mar 2008
- Location
- NYC
- Gender
-
2013-11-12, 07:52 PM (ISO 8601)
- Join Date
- Jan 2012
-
2013-11-12, 09:47 PM (ISO 8601)
- Join Date
- Aug 2005
- Location
- Mountain View, CA
- Gender
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:
SpoilerSaberhagen'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)
-
2013-11-13, 02:22 AM (ISO 8601)
- Join Date
- Feb 2007
- Location
- Manchester, UK
- Gender
Re: Raaaagggghhhh
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!
-
2013-11-13, 04:17 AM (ISO 8601)
- Join Date
- May 2011
- Location
- France
- Gender
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.Originally Posted by on Dwarf Fortress succession gamesOriginally Posted by Dwarf Fortress 0.40.01 bugs
-
2013-11-13, 05:14 AM (ISO 8601)
- Join Date
- Nov 2006
- Location
- England. Ish.
- Gender
Re: Raaaagggghhhh
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
-
2013-11-13, 05:22 AM (ISO 8601)
- Join Date
- May 2007
- Gender
-
2013-11-13, 05:30 AM (ISO 8601)
- Join Date
- Apr 2010
- Location
- London, EU
- Gender
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
-
2013-11-13, 06:05 AM (ISO 8601)
- Join Date
- Jun 2011
- Gender
Re: Raaaagggghhhh
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".
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.
Because Sunday is both 0 and 7, of course.
(Also, agreed wholeheartedly.)
@TuggyNE: Totally agreed and commisseration shared. :)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
-
2013-11-13, 06:28 AM (ISO 8601)
- Join Date
- Jul 2011
- Location
- Aachen, Germany
- Gender
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
-
2013-11-13, 08:11 AM (ISO 8601)
- Join Date
- Aug 2007
- Location
- Imagination Land
- Gender
Re: Raaaagggghhhh
-
2013-11-13, 08:43 AM (ISO 8601)
- Join Date
- Dec 2010
- Location
- The Great White North
- Gender
-
2013-11-13, 05:07 PM (ISO 8601)
- Join Date
- May 2007
- Location
- Tail of the Bellcurve
- Gender
Re: Raaaagggghhhh
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.
-
2013-11-13, 11:05 PM (ISO 8601)
- Join Date
- May 2005
- Location
- Somerville, MA
- Gender
Re: Raaaagggghhhh
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.
-
2013-11-13, 11:42 PM (ISO 8601)
- Join Date
- Mar 2008
- Location
- NYC
- Gender
-
2013-11-14, 12:21 AM (ISO 8601)
- Join Date
- Oct 2011
- Location
- The last place you look
- Gender
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 LOOPAvatar 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.
I am a 10/14/11/15/12/14 LG Clr 2
-
2013-11-14, 01:59 AM (ISO 8601)
- Join Date
- Feb 2007
- Location
- Manchester, UK
- Gender
-
2013-11-14, 02:19 AM (ISO 8601)
- Join Date
- Feb 2010
- Location
- Texas. It's too hot here.
- Gender
Re: Raaaagggghhhh
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.
-
2013-11-14, 02:37 AM (ISO 8601)
- Join Date
- Jun 2011
- Gender
Re: Raaaagggghhhh
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?"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
-
2013-11-14, 07:53 AM (ISO 8601)
- Join Date
- Dec 2006
- Location
- Raleigh NC
- Gender
Re: Raaaagggghhhh
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
-
2013-11-14, 11:34 AM (ISO 8601)
- Join Date
- May 2007
- Location
- Tail of the Bellcurve
- Gender
Re: Raaaagggghhhh
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.
-
2013-11-14, 01:56 PM (ISO 8601)
- Join Date
- Dec 2006
- Location
- Raleigh NC
- Gender
Re: Raaaagggghhhh
Challenge accepted.
Spoiler
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
-
2013-11-16, 11:17 PM (ISO 8601)
- Join Date
- Oct 2011
- Location
- The last place you look
- Gender
Re: Raaaagggghhhh
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.
I am a 10/14/11/15/12/14 LG Clr 2