|
If you are trying to say that these requirements are a horror, I have to disagree. Those requirements are quite resonable for a homework assignment. Also this is a "coding horror" forum not a requirements horror forum.
Bill W
|
|
|
|
|
So, I'm sure this has happened to everyone but I'm pouring through a section of v1.0 of a program I am updating. There's a section where some decent algebra is involved and all of the variables used were num1, num2, num3 etc. down the line. This is in several pages of code and it goes up to num26, but at least they are all declared locally. There is no consistency between in-line if statements and general if statements; they are used intermittently and in no semblance of order whatsoever. In two separate places, the math that is used conflicts with the documentation that was provided so now I have to figure out which is correct so I can rewrite this correctly and accurately. They had code for a dropdown box that said
if (NumOfConveyors >= 3) && (NumOfConveyors <= 4)
...so...if your dropdown box only gives me the option of whole numbers, why even check to see if there will be a number in between 3 and 4? You are never going to have .25 of a conveyor.
And there's an if instead of an elseif in a block of code which sets one of the num variables to a totally wrong number. Good times finding that one out.
"The shortest distance between two points is under construction"
-Noelie ALtito
|
|
|
|
|
So basically, if the number is 3 or 4 do something.
|
|
|
|
|
Yeah, the check to see if something is between them is pointless. Although it's not such a big deal, it is a little annoying to look at.
"The shortest distance between two points is under construction"
-Noelie ALtito
|
|
|
|
|
I don't think that's bad at all. It's written in a general way so if the bounds change, the logic doesn't have to. Maybe the bounds used to be larger, but somewhere along the way they were changed so now it looks a bit funny.
I would write it that way myself because we deal with changing parameters all the time. In fact I'd make 3 and 4 constants.
|
|
|
|
|
I totally agree. I have had requirements change far more often than not. Even for things that I was originally told that it would never change. So I always write things in such a way as to allow for easy changes in the future.
Bill W
|
|
|
|
|
AeonBlue wrote: Yeah, the check to see if something is between them is pointless
That's not true. A switch is more elegant (I think) but such an if is reasonable.
BTW: on the other hand else if is a must, after the above statement.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Pete O'Hanlon wrote: if the number is 3 or 4 do something.
I believe the terminology used was "do stuff".
Regards,
--Perspx
"The Blue Screen of Death, also known as The Blue Screen of Doom, the "Blue Screen of Fun", "Phatul Exception: The WRECKening" and "Windows Vista", is a multi award-winning game first developed in 1995 by Microsoft" - Uncyclopedia
Introduction to Object-Oriented JavaScript
|
|
|
|
|
Perspx wrote: I believe the terminology used was "do stuff".
I'm sorry. I forget the technical stuff.
|
|
|
|
|
"all of the variables used were num1, num2, num3 etc. down the line. This is in several pages of code and it goes up to num26,"
They probably started off calling them a, b, c, ..., z, until learning that "you shouldn't use 1-letter variable names."
|
|
|
|
|
haha, It just occured to me that there are 26 variables and 26 letters in the alphabet. That's too ironic to ignor.
"The shortest distance between two points is under construction"
-Noelie ALtito
|
|
|
|
|
I am forced to solve a bug in our VB application, the original programmer has left the building a long time ago. Due to the long and complex function they have given the variable a simple name.
Dim nFoo() As Integer
Dim sfoo() As String
Dim sFoo1() As String So i went on looking what could be placed inside a nFoo,
and i stumbled on this gem.
j = 0
For i = 1 To lvwCardGrp.ListItems.Count
ReDim Preserve nFoo(j)
nFoo(j) = Mid$(lvwCardGrp.ListItems(i).Key, 3)
j = j + 1
Next And of course why change a winning strategy the same for the sfoo's.
Learn from the mistakes of others, you may not live long enough to make them all yourself.
|
|
|
|
|
Nice gem
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
"Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham
|
|
|
|
|
In the original coders defense, if there (previously) was a condition around the ReDim / nFoo = / j = lines, the logic makes perfect sense.
|
|
|
|
|
Graham Bradshaw wrote: In the original coders defense, if there (previously) was a condition around the ReDim / nFoo = / j = lines, the logic makes perfect sense.
Actually in one of the three cases this was true, but then one could do it like this (which is what i chose)
j = 0
ReDim nFoo(lvwCardGrp.ListItems.Count - 1)
For i = 1 To lvwCardGrp.ListItems.Count
if some_condition then
nFoo(j) = Mid$(lvwCardGrp.ListItems(i).Key, 3)
j = j + 1
endif
Next
ReDim nFoo(j - 1)
In this case only one allocation happens. And in the end free up the unnecessary space, without the preserve statement which needs to copy the data to a new location.
Learn from the mistakes of others, you may not live long enough to make them all yourself.
|
|
|
|
|
Shouldn't ReDim nFoo(j - 1) be ReDim Preserve nFoo(j - 1) ? As the code is, you reinitialise nFoo.
|
|
|
|
|
Graham Bradshaw wrote: Shouldn't ReDim nFoo(j - 1) be ReDim Preserve nFoo(j - 1)? As the code is, you reinitialise nFoo.
Yes, you are correct.
Thanks for pointing it out, must have slipped through my fingers while typing it over from the real code.
Note to myself: Learn to use Copy-Past
Learn from the mistakes of others, you may not live long enough to make them all yourself.
|
|
|
|
|
I don't see how. Unless I read it wrong, j is unnecessary, the array should be redim ed before the loop, we already know how many items it needs to hold.
|
|
|
|
|
PIEBALDconsult wrote: we already know how many items it needs to hold.
Not if you only add items to the array in some condition, which was the point I was trying to make. See the other reply to my post for an example.
|
|
|
|
|
Ah, I see, I did read it wrong.
|
|
|
|
|
That's just too bad. Way too bad.
|
|
|
|
|
Seen in a VBA app in lieu of commenting out/deleting 138 lines of junk code.
Yes, the VBA editor is a steaming pile of excrement, but any decent text editor will let you insert the ' via a global insert/replace.
Today's lesson is brought to you by the word "niggardly". Remember kids, don't attribute to racism what can be explained by Scandinavian language roots.
-- Robert Royall
|
|
|
|
|
dan neely wrote: any decent text editor
Like Notepad?
|
|
|
|
|
maybe, I'd've used a regex to match on the start of a line. I know notepad doesn't do that, can it match on the newline char itself?
Today's lesson is brought to you by the word "niggardly". Remember kids, don't attribute to racism what can be explained by Scandinavian language roots.
-- Robert Royall
|
|
|
|
|
dan neely wrote: can it match on the newline char itself
Not that I've found, I usually resort to opening the file in Word to do that.
|
|
|
|