Moderators: phlip, Moderators General, Prelates
roband wrote:Mav is a cow.
roband wrote:Mav is a cow.
if (index == 0 || Other1)
{
}
else if (index == 0 && Other2)
{
}Well, in visual studio I can run annotate which does the same thing. It doesn't help much when all the code is over 4 years old and all by the same person.Yakk wrote:In any case, this is why having things like Blame that gives you a per-line indication of the history of the file is very useful.
Xeio wrote:Er, all the code that would be in that second if statement is dead code, isn't it?
- Code: Select all
if (index == 0 || Other1)
{
}
else if (index == 0 && Other2)
{
}
I hate when I run into something like this and it seems so obvious that I must be missing something...
EDIT: Or more annoying, that while I know in its current form I could just delete that code, I wonder if the original author didn't intend it to be such, or if it was just something that didn't get cleaned up when the if logic was altered...
roband wrote:Mav is a cow.
And it's a pretty good argument against doing variable modification inside of an if statement.Yakk wrote:This is one of the many ways in which C++ contains some suck.
Xeio wrote:Actually, I think the only time assignment is generally ok in a conditional clause is for a while loop condition. Stuff like reading in the next line while doing a check to make sure it wasn't the end of the file. Anything more complex than that though and I'd be very hesitant to do so, if only for readability.
Yakk wrote:Roadie, that doesn't quite hold, because we aren't coding in a functional language.
If Other1 is an expression like IndexShouldBeCleared(&index), or if index is a member variable, or one of myriad of other reasons, it could easily change index in the first expression to zero (after the index==0 check), and then return false.
We then fall through into the second expression. Index is zero, and it isn't dead code.
This is one of the many ways in which C++ contains some suck.
roband wrote:Mav is a cow.
Xeio wrote:Actually, I think the only time assignment is generally ok in a conditional clause is for a while loop condition. Stuff like reading in the next line while doing a check to make sure it wasn't the end of the file. Anything more complex than that though and I'd be very hesitant to do so, if only for readability.
roband wrote:Mav is a cow.
/// <summary>
/// Adds a num to the list of used nums
/// </summary>
/// <param name="num"></param>
/// <param name="array"></param>
private static void AddNumToList(string num, ref ArrayList array)
{
//adds num to appropriate list
array.Add(num);
}*stab*Xeio wrote:
- Code: Select all
string num
Dason wrote:Whyyyyyy doesn't Debian support WPA for their net install. Grrrrrrrrrrrrrrrrrrrr.
headprogrammingczar wrote:Debian ships with the latest FF code. It's only the name and logo that conflict with Debian's copyright policy. The reason it ships with an old version of FF is their policy on testing vs stable.
You, sir, name? wrote:If you have over 26 levels of nesting, you've got bigger problems ... than variable naming.
suffer-cait wrote:it might also be interesting to note here that i don't like 5 fingers. they feel too bulky.
joshz wrote:I mean, so that's not necessarily a bad way to think of python variables. I'm not sure if that's how it's handled in practice for all types, but it does handle many types like that.
For many people, pointers are confusing, so the boxes analogy is popular (or I guess tags too, though I've never heard that before.)
roband wrote:Mav is a cow.
moiraemachy wrote:So... as somewhat of a noob at coding, I'm learning Python and everything was perfect. Except I stumbled in that "variables as tags, not boxes" thing, and it seems an unnecessary complication. I get it now, but still: why not pointers? The alleged complexity of handling pointers disappears when you have dynamic typing... just make the assignment operation mean "point to this data" when used in a pointer. Am I being stupid?
RoadieRich wrote:The only time it changes is for new style classes with appropriate magic methods defined, when o.a=x can call o.__setattr__('a', x) or a.__set__(o, x), and o[i]=x, which calls o.__setitem__(i,x), all of which can do just about anything. I don't think it's possible to override the straight a=b, though. The += operator et al, on the other hand...
moiraemachy wrote:So... as somewhat of a noob at coding, I'm learning Python and everything was perfect. Except I stumbled in that "variables as tags, not boxes" thing, and it seems an unnecessary complication. I get it now, but still: why not pointers? The alleged complexity of handling pointers disappears when you have dynamic typing... just make the assignment operation mean "point to this data" when used in a pointer. Am I being stupid?


TheChewanater wrote:Has anyone seen Rust yet?
Jplus wrote:Is there an online document that explains why this language exists? Because, I don't see any strong advantages over C++.
What is this project's goal, in one sentence?
To design and implement a safe, concurrent, practical, static systems language.
Users browsing this forum: Bakstoola and 5 guests