just curious
-
How many people actually have had a bug in their code caused by an incorrect assignment; = instead of ==??? It was just a while back while reading a PHP article the author suggests ALWAYS using a fixed number/value (if you can) then the == operator then another variable or fixed value so instead of:
if(a==2)
you get:
if(2==a)
Remembering to always use this method when using == will prevent you from ever making and assignment error, becuz obviously the complier catches 2=a as an invalid assignment, whereas 2==a is cool. Personally I can honeslty say i've never made that mistake yet...it was one of the first things I read when I was learning how to program...becareful with assigment and equality operators...and I always have been since then...however I still want to try and get into the habit o fusing this technique...just becuz it's one less bug to ever have to worry about...which is great news, cuz I hate getting stuck for more then 10 mins on a bug. Anyways, just curious...how many of you actually have made that mistake before...??? How do I print my voice mail?
-
How many people actually have had a bug in their code caused by an incorrect assignment; = instead of ==??? It was just a while back while reading a PHP article the author suggests ALWAYS using a fixed number/value (if you can) then the == operator then another variable or fixed value so instead of:
if(a==2)
you get:
if(2==a)
Remembering to always use this method when using == will prevent you from ever making and assignment error, becuz obviously the complier catches 2=a as an invalid assignment, whereas 2==a is cool. Personally I can honeslty say i've never made that mistake yet...it was one of the first things I read when I was learning how to program...becareful with assigment and equality operators...and I always have been since then...however I still want to try and get into the habit o fusing this technique...just becuz it's one less bug to ever have to worry about...which is great news, cuz I hate getting stuck for more then 10 mins on a bug. Anyways, just curious...how many of you actually have made that mistake before...??? How do I print my voice mail?
Hockey wrote: if(2==a) I learned this when reading Newcomer's book "Win32 Programming". Hockey wrote: never made that mistake yet You would probably, when using a notebook PC with a touchpad mouse... Touchpad mouse is evil. X| Maxwell Chen
-
How many people actually have had a bug in their code caused by an incorrect assignment; = instead of ==??? It was just a while back while reading a PHP article the author suggests ALWAYS using a fixed number/value (if you can) then the == operator then another variable or fixed value so instead of:
if(a==2)
you get:
if(2==a)
Remembering to always use this method when using == will prevent you from ever making and assignment error, becuz obviously the complier catches 2=a as an invalid assignment, whereas 2==a is cool. Personally I can honeslty say i've never made that mistake yet...it was one of the first things I read when I was learning how to program...becareful with assigment and equality operators...and I always have been since then...however I still want to try and get into the habit o fusing this technique...just becuz it's one less bug to ever have to worry about...which is great news, cuz I hate getting stuck for more then 10 mins on a bug. Anyways, just curious...how many of you actually have made that mistake before...??? How do I print my voice mail?
I made it once or twice. I think it's always possible to commit this type of error just by not successfully hitting the key twice, through a random finger twitch or whatever, and not realizing that you didn't type the second equals sign. The idea is smart, but as for me I'm too much in the habit of reading my code almost as English in my head to adopt the practice; it's not as normal to say "if two equals my variable" as it is the reverse. Sort of a similar idea I've used in the past in Java and C#, when testing equality of strings, is to put the constant value first if the value I'm comparing can be null, just to avoid the possibility of throwing a null-pointer exception. When it doesn't cost anything, and even when it does, I usually try to code defensively; so I might have code like the below even if I assume that the non-null condition has already been checked by some code.
private const string WOMBAT = "wombat";
// ...
// ...string s;
// ...
if (WOMBAT.Equals(s))
{
}It's a similar idea, but I don't much like it either. Just a personal preference. I commit careless bugs pretty rarely, and when I do I always catch them during testing; it also keeps me humble to make mistakes once in a while. :) Regards, Jeff Varszegi EEEP! An Extensible Expression Evaluation Package
-
I made it once or twice. I think it's always possible to commit this type of error just by not successfully hitting the key twice, through a random finger twitch or whatever, and not realizing that you didn't type the second equals sign. The idea is smart, but as for me I'm too much in the habit of reading my code almost as English in my head to adopt the practice; it's not as normal to say "if two equals my variable" as it is the reverse. Sort of a similar idea I've used in the past in Java and C#, when testing equality of strings, is to put the constant value first if the value I'm comparing can be null, just to avoid the possibility of throwing a null-pointer exception. When it doesn't cost anything, and even when it does, I usually try to code defensively; so I might have code like the below even if I assume that the non-null condition has already been checked by some code.
private const string WOMBAT = "wombat";
// ...
// ...string s;
// ...
if (WOMBAT.Equals(s))
{
}It's a similar idea, but I don't much like it either. Just a personal preference. I commit careless bugs pretty rarely, and when I do I always catch them during testing; it also keeps me humble to make mistakes once in a while. :) Regards, Jeff Varszegi EEEP! An Extensible Expression Evaluation Package
Jeff Varszegi wrote: The idea is smart, but as for me I'm too much in the habit of reading my code almost as English in my head to adopt the practice Thats my problem too :) How do I print my voice mail?
-
Hockey wrote: if(2==a) I learned this when reading Newcomer's book "Win32 Programming". Hockey wrote: never made that mistake yet You would probably, when using a notebook PC with a touchpad mouse... Touchpad mouse is evil. X| Maxwell Chen
Maxwell Chen wrote: You would probably, when using a notebook PC with a touchpad mouse... Touchpad mouse is evil I hate anything but desktops for development :) How do I print my voice mail?
-
I made it once or twice. I think it's always possible to commit this type of error just by not successfully hitting the key twice, through a random finger twitch or whatever, and not realizing that you didn't type the second equals sign. The idea is smart, but as for me I'm too much in the habit of reading my code almost as English in my head to adopt the practice; it's not as normal to say "if two equals my variable" as it is the reverse. Sort of a similar idea I've used in the past in Java and C#, when testing equality of strings, is to put the constant value first if the value I'm comparing can be null, just to avoid the possibility of throwing a null-pointer exception. When it doesn't cost anything, and even when it does, I usually try to code defensively; so I might have code like the below even if I assume that the non-null condition has already been checked by some code.
private const string WOMBAT = "wombat";
// ...
// ...string s;
// ...
if (WOMBAT.Equals(s))
{
}It's a similar idea, but I don't much like it either. Just a personal preference. I commit careless bugs pretty rarely, and when I do I always catch them during testing; it also keeps me humble to make mistakes once in a while. :) Regards, Jeff Varszegi EEEP! An Extensible Expression Evaluation Package
Actually there is such feature in C++, see page 829 in Appendix C in the book "The C++ Programming Language, 3rd", except operator==. We can write our C++ code this way by turning on /Za.
bool bFlag = false;
if(not bFlag) { /* Do something... */ }Regarding to the *missing* alternative keyword, we may define this
#define equal ==
for
if(bFlag equal true) { }
Maxwell Chen
-
How many people actually have had a bug in their code caused by an incorrect assignment; = instead of ==??? It was just a while back while reading a PHP article the author suggests ALWAYS using a fixed number/value (if you can) then the == operator then another variable or fixed value so instead of:
if(a==2)
you get:
if(2==a)
Remembering to always use this method when using == will prevent you from ever making and assignment error, becuz obviously the complier catches 2=a as an invalid assignment, whereas 2==a is cool. Personally I can honeslty say i've never made that mistake yet...it was one of the first things I read when I was learning how to program...becareful with assigment and equality operators...and I always have been since then...however I still want to try and get into the habit o fusing this technique...just becuz it's one less bug to ever have to worry about...which is great news, cuz I hate getting stuck for more then 10 mins on a bug. Anyways, just curious...how many of you actually have made that mistake before...??? How do I print my voice mail?
A good compiler will issue a warning telling you that you may have used assignment instead of comparison. Therefore I think that the style you mentioned makes code unreadable and is not worth it. Drinking In The Sun Forgot Password?
-
A good compiler will issue a warning telling you that you may have used assignment instead of comparison. Therefore I think that the style you mentioned makes code unreadable and is not worth it. Drinking In The Sun Forgot Password?
Visual C++ .NET 2002 doesn't warn unless Warning Level-4 is set. Maxwell Chen
-
How many people actually have had a bug in their code caused by an incorrect assignment; = instead of ==??? It was just a while back while reading a PHP article the author suggests ALWAYS using a fixed number/value (if you can) then the == operator then another variable or fixed value so instead of:
if(a==2)
you get:
if(2==a)
Remembering to always use this method when using == will prevent you from ever making and assignment error, becuz obviously the complier catches 2=a as an invalid assignment, whereas 2==a is cool. Personally I can honeslty say i've never made that mistake yet...it was one of the first things I read when I was learning how to program...becareful with assigment and equality operators...and I always have been since then...however I still want to try and get into the habit o fusing this technique...just becuz it's one less bug to ever have to worry about...which is great news, cuz I hate getting stuck for more then 10 mins on a bug. Anyways, just curious...how many of you actually have made that mistake before...??? How do I print my voice mail?
Set the warning level to 4 and you will always get a warning.
-
A good compiler will issue a warning telling you that you may have used assignment instead of comparison. Therefore I think that the style you mentioned makes code unreadable and is not worth it. Drinking In The Sun Forgot Password?
[James Pullicino] wrote: Therefore I think that the style you mentioned makes code unreadable and is not worth it. Visual C++ 6 doesn't....or atleast mine... :) For interpreted languages like PHP it makes sense...i'm just not accustomed to reading code that way... How do I print my voice mail?
-
Set the warning level to 4 and you will always get a warning.
Ahhh...is that how you do it... :) Cooly i'll try that... How do I print my voice mail?
-
[James Pullicino] wrote: Therefore I think that the style you mentioned makes code unreadable and is not worth it. Visual C++ 6 doesn't....or atleast mine... :) For interpreted languages like PHP it makes sense...i'm just not accustomed to reading code that way... How do I print my voice mail?
Hockey wrote: Visual C++ 6 doesn't....or atleast mine... You need Warning Level-4 turned on in VC++6 project setting. Maxwell Chen
-
Actually there is such feature in C++, see page 829 in Appendix C in the book "The C++ Programming Language, 3rd", except operator==. We can write our C++ code this way by turning on /Za.
bool bFlag = false;
if(not bFlag) { /* Do something... */ }Regarding to the *missing* alternative keyword, we may define this
#define equal ==
for
if(bFlag equal true) { }
Maxwell Chen
This is the best solution, IMHO. Regards, Jeff Varszegi EEEP! An Extensible Expression Evaluation Package
-
How many people actually have had a bug in their code caused by an incorrect assignment; = instead of ==??? It was just a while back while reading a PHP article the author suggests ALWAYS using a fixed number/value (if you can) then the == operator then another variable or fixed value so instead of:
if(a==2)
you get:
if(2==a)
Remembering to always use this method when using == will prevent you from ever making and assignment error, becuz obviously the complier catches 2=a as an invalid assignment, whereas 2==a is cool. Personally I can honeslty say i've never made that mistake yet...it was one of the first things I read when I was learning how to program...becareful with assigment and equality operators...and I always have been since then...however I still want to try and get into the habit o fusing this technique...just becuz it's one less bug to ever have to worry about...which is great news, cuz I hate getting stuck for more then 10 mins on a bug. Anyways, just curious...how many of you actually have made that mistake before...??? How do I print my voice mail?
Very occasionally if I haven't had enough coke in the mornings I'll slip one of those in, but the compiler warns me about a possible mistake and lets me fix it before it gets anywhere. Like Jeff, my causing problem is not registering two key presses successfully - my brain works faster than my fingers!
David Wulff The Royal Woofle Museum
Putting the laughter back into slaughter
-
How many people actually have had a bug in their code caused by an incorrect assignment; = instead of ==??? It was just a while back while reading a PHP article the author suggests ALWAYS using a fixed number/value (if you can) then the == operator then another variable or fixed value so instead of:
if(a==2)
you get:
if(2==a)
Remembering to always use this method when using == will prevent you from ever making and assignment error, becuz obviously the complier catches 2=a as an invalid assignment, whereas 2==a is cool. Personally I can honeslty say i've never made that mistake yet...it was one of the first things I read when I was learning how to program...becareful with assigment and equality operators...and I always have been since then...however I still want to try and get into the habit o fusing this technique...just becuz it's one less bug to ever have to worry about...which is great news, cuz I hate getting stuck for more then 10 mins on a bug. Anyways, just curious...how many of you actually have made that mistake before...??? How do I print my voice mail?
Coming from a VB background, I have never made that mistake since my third year C++ COS module, but now I work in C#, and nearly always use the constant first format. The funny thing is, on Friday just after I explained its use to my colleague, I found one such error in a piece of my code which I had too hastily added. Fortunately I spotted in even before compiling, but it did make me slow down a bit. After all, this was code calling the RegistryKey.DeleteSubKeyTree method. My blog.
-
How many people actually have had a bug in their code caused by an incorrect assignment; = instead of ==??? It was just a while back while reading a PHP article the author suggests ALWAYS using a fixed number/value (if you can) then the == operator then another variable or fixed value so instead of:
if(a==2)
you get:
if(2==a)
Remembering to always use this method when using == will prevent you from ever making and assignment error, becuz obviously the complier catches 2=a as an invalid assignment, whereas 2==a is cool. Personally I can honeslty say i've never made that mistake yet...it was one of the first things I read when I was learning how to program...becareful with assigment and equality operators...and I always have been since then...however I still want to try and get into the habit o fusing this technique...just becuz it's one less bug to ever have to worry about...which is great news, cuz I hate getting stuck for more then 10 mins on a bug. Anyways, just curious...how many of you actually have made that mistake before...??? How do I print my voice mail?
Hockey wrote: How many people actually have had a bug in their code caused by an incorrect assignment; = instead of ==??? i have. and, i can't stand putting the const on the left because i sometimes like to use the old C-style trick of doing an assignment inside a conditional test:
if ((res = testSomething(foo)) == 100)
{
// alert the authorities
} -
How many people actually have had a bug in their code caused by an incorrect assignment; = instead of ==??? It was just a while back while reading a PHP article the author suggests ALWAYS using a fixed number/value (if you can) then the == operator then another variable or fixed value so instead of:
if(a==2)
you get:
if(2==a)
Remembering to always use this method when using == will prevent you from ever making and assignment error, becuz obviously the complier catches 2=a as an invalid assignment, whereas 2==a is cool. Personally I can honeslty say i've never made that mistake yet...it was one of the first things I read when I was learning how to program...becareful with assigment and equality operators...and I always have been since then...however I still want to try and get into the habit o fusing this technique...just becuz it's one less bug to ever have to worry about...which is great news, cuz I hate getting stuck for more then 10 mins on a bug. Anyways, just curious...how many of you actually have made that mistake before...??? How do I print my voice mail?
Hockey wrote: How many people actually have had a bug in their code caused by an incorrect assignment; = instead of ==??? Not once since I started working in C# :P (yeah, yeah - I know the new compiler will trap this potential error but I felt the need to spout some MS kool-aid this morning ;)) cheers, Chris Maunder
-
How many people actually have had a bug in their code caused by an incorrect assignment; = instead of ==??? It was just a while back while reading a PHP article the author suggests ALWAYS using a fixed number/value (if you can) then the == operator then another variable or fixed value so instead of:
if(a==2)
you get:
if(2==a)
Remembering to always use this method when using == will prevent you from ever making and assignment error, becuz obviously the complier catches 2=a as an invalid assignment, whereas 2==a is cool. Personally I can honeslty say i've never made that mistake yet...it was one of the first things I read when I was learning how to program...becareful with assigment and equality operators...and I always have been since then...however I still want to try and get into the habit o fusing this technique...just becuz it's one less bug to ever have to worry about...which is great news, cuz I hate getting stuck for more then 10 mins on a bug. Anyways, just curious...how many of you actually have made that mistake before...??? How do I print my voice mail?
-
How many people actually have had a bug in their code caused by an incorrect assignment; = instead of ==??? It was just a while back while reading a PHP article the author suggests ALWAYS using a fixed number/value (if you can) then the == operator then another variable or fixed value so instead of:
if(a==2)
you get:
if(2==a)
Remembering to always use this method when using == will prevent you from ever making and assignment error, becuz obviously the complier catches 2=a as an invalid assignment, whereas 2==a is cool. Personally I can honeslty say i've never made that mistake yet...it was one of the first things I read when I was learning how to program...becareful with assigment and equality operators...and I always have been since then...however I still want to try and get into the habit o fusing this technique...just becuz it's one less bug to ever have to worry about...which is great news, cuz I hate getting stuck for more then 10 mins on a bug. Anyways, just curious...how many of you actually have made that mistake before...??? How do I print my voice mail?
I do it very very often but I almost always catch myself when im closing the braces ) :) I read about 2==a in Deitel a few years back but don't like it since I like to execute something inside my condition and then check if it's equal ot something. " Why oh why didn't I take the blue pill ? "
-
How many people actually have had a bug in their code caused by an incorrect assignment; = instead of ==??? It was just a while back while reading a PHP article the author suggests ALWAYS using a fixed number/value (if you can) then the == operator then another variable or fixed value so instead of:
if(a==2)
you get:
if(2==a)
Remembering to always use this method when using == will prevent you from ever making and assignment error, becuz obviously the complier catches 2=a as an invalid assignment, whereas 2==a is cool. Personally I can honeslty say i've never made that mistake yet...it was one of the first things I read when I was learning how to program...becareful with assigment and equality operators...and I always have been since then...however I still want to try and get into the habit o fusing this technique...just becuz it's one less bug to ever have to worry about...which is great news, cuz I hate getting stuck for more then 10 mins on a bug. Anyways, just curious...how many of you actually have made that mistake before...??? How do I print my voice mail?
That sounds so simple! It just feels so weird to write it like that. I guess my ingrained habits are going to cost me time spent debugging (because yes - I have had these bugs).
Glano perictu com sahni delorin!