|
I just spent a half hour tracking down a weird bug... I had left out an else ...
...
}
{
...
|
|
|
|
|
The compiler usually give you a warning about "Empty statement" (which in my case is usually intended and explained in a comment).
It shouldn't be much more difficult to give a warning: "Redundant braces". That would have caught errors like this.
Sure this comes in two levels: If there is no variable declarations or other scope-limited constructions within the block, the braces are truly redundant. With block local variables and the like, they may be intended even if the block is not associated with a control statement. I very rarely see code doing that; I think the number of "false positives" would be quite low. (And there could be an option to control it.)
|
|
|
|
|
Yeah, dunno, not a fan of warnings myself.
What would you expect for this?
# if EnableValidationOfX
if ( X > 0 )
# endif
{
... Do something potentially dangerous with X
}
|
|
|
|
|
For my preferred coding style, there would be no problem, as I put the opening brace at the line of the statement using the block, i.e. at the end of the if statement. That would be require the closing brace to be commented out as well - and the compiler would tell you, if you forgot to.
Assuming your bracing style with separate brace lines, you could of course do the same: Move the # endif down one line and add a # to the closing brace line. Whichever solution you choose, I dislike it: I assume that the block between the braces is indented. This is misleading when the 'if (X>0)' is not compiled.
However, I would never disable validation of X, and most certainly not by an #if directive. I would have made EnableValidationOfX a variable, so that it can be enabled without recompiling, in the binary environment where you experience a problem with invalid X values.
If you insist on the #if, and refuse to include the braces in the conditional compilation, I would prefer that the compiler gives a warning if you compile with EnableValidationOfX is false. If this coding style is common to you, you should probably disable the "Redundant braces" warning altogether.
There is another construct where I guess that lots of others disagree: In a switch(), I like to indent the statements in each case from the case label. I also frown when I see an indent/undent with no brace: Braces and indents go hand in hand. So I like to add braces around the lines of each case. But C class languages do not require case to be a block (also, a single statement is not defined to be a block), so the braces are redundant. If we got the compiler to warn about redundant braces, I would want it to have options to allow my coding style of making each case alternative a block. (But I guess a lot of you would scream at my use of redundant braces in switch() statements!)
One thing I like about lint is that you can insert a lint comment that disables a check for this line only. If you occasionally, but not very often, use constructs like the one above, a similar mechanism for suppressing the warning at this occasion as a special case, would be very nice. It would also serve as a documentation to other programmers to explain that the braces are indeed intended.
|
|
|
|
|
trønderen wrote: each case from the case label.
trønderen wrote: Braces and indents go hand in hand
Uh, huh, I agree...
switch ( foo )
{
case bar :
{
...
break ;
}
...
}
|
|
|
|
|
The suits just said ship it anyway.
>64
Some days the dragon wins. Suck it up.
|
|
|
|
|
I honestly don't understand the point of this post. Is it a joke?
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
|
|
|
|
|
No, it is not a joke.
My code was return(index--) and whyever in my brain it was equivalent with return(index - 1)
|
|
|
|
|
If you want index-1, you can use this
return (--index);
The way you did it, index was decremented after the return (a "postfix decrement"). You want it to be decremented before it's returned (a "prefix decrement .
Prefix Increment and Decrement Operators | Microsoft Docs[^]
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
|
|
|
|
|
Unbelievable!
That should be ‘calculateIndex’!
If you can't laugh at yourself - ask me and I will do it for you.
|
|
|
|
|
I can't say I've ever written a bug as that one however I've written a few zonkers which I often find by accident examining the code for other reasons. I consider myself fortunate to have found the bugs in such situations. Perhaps I was born under a lucky star.
|
|
|
|
|
I am considering switching from Windows10 to Windows11.
If you have already done that, please let me know:
Is it better enough than 10 to make the switch worthwhile?
Is it stable enough at this point?
Do you have any suggestions on the best way to make the switch?
Did you lose any of your data, programs, etc. when making the switch?
Are you happy that you did?
Any thoughts, suggestions would help.
Ed
|
|
|
|
|
I've not heard any horror stories (but I've not actively been listening for them)
The safest way to switch is to reformat and install from scratch.
Upgrading from a current OS usually work, I remember a long time ago that it created some instabilities, but that was a long time ago.
Also, before you do upgrade, make backups of all sensitive things.
Unfortunately, my hardware does not support Windows 11, I know I could probably order the TPM chip, but I intend to upgrade my hardware in the next few months anyway.
CI/CD = Continuous Impediment/Continuous Despair
|
|
|
|
|
The initial version of 11 had some issues that caused me to dump it. (Some of my apps, like Intellij Idea, refused to even start up on the first 11 version. I had to revert to 10 and waited for a more stable version of 11.
However, MS quickly fixed the isue and after installing the latest version of 11 I am totally happy! Regarding losing some data or apps: Not applicable in my case since I did a clean install of 11, which means I had to re-install everything. It took me the better part of a morning to do.
Note: I have a separate internal drive for my data, so that does not get lost in a clean install. I keep the C: drive just for the operating system and applications. This makes a clean install a lot easier. It also means that I can make a Macrium image of the C: drive that will not be bloated up by gigabytes of data.
Get me coffee and no one gets hurt!
|
|
|
|
|
Cp-Coder wrote: Note: I have a separate internal drive for my data, so that does not get lost in a clean install. I keep the C: drive just for the operating system and applications. This makes a clean install a lot easier. It also means that I can make a Macrium image of the C: drive that will not be bloated up by gigabytes of data. +1 on that procedure
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
Rating helpful answers is nice, but saying thanks can be even nicer.
|
|
|
|
|
I did the upgrade from 10 to 11 as opposed to a clean install.
I lost no data.
The upgrade went smoothly.
So far the system has been very stable.
I've been able to do everything on 11 that I could do on 10.
I don't see a huge difference in systems, but there are things that are better.
Would I recommend? YES
The most expensive tool is a cheap tool. Gareth Branwyn
JaxCoder.com
|
|
|
|
|
I had same experience as Mike. You also need to make sure you are using the latest video card drivers. I am using 64 bit version. No reinstall needed for my applications.
"A little time, a little trouble, your better day"
Badfinger
|
|
|
|
|
1) Erm ... from a user perspective no - the changes are mostly cosmetic and actually degrade the UI functionality in some cases, particularly the taskbar (You can't move it from the bottom of you main monitor and it takes up more space)
2) Yes. It seems solid.
3) I'd recommend a clear-and-reinstall, but I'm still running on the upgrade version because it wouldn't do a clean install when I switched. Doesn't seem to have caused any problems (But I suspect there are still bits of Wn 7 in there somewhere, because I think that was the last OS I clean installed).
4) No.
5) Yes and no. It's working ok, but I'd still like some of the old functionality back, and it takes longer to do some things: right click in Windows Explorer brings up a "UWP" menu - spaced out, bigger font, and truncated in what you can do. To rename a file, you right click for that menu, then select "Show more options" and a new old-style menu pops up with smaller font, and tighter spacing which includes the "Rename" option.
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Quote: To rename a file, you right click for that menu, then select "Show more options" and a new old-style menu pops up with smaller font, and tighter spacing which includes the "Rename" option.
Note when you right click a file or folder, there appears four or so small icons for the cut-copy-paste-rename functions. So it's not necessary to go to "Show more options".
Get me coffee and no one gets hurt!
|
|
|
|
|
Cp-Coder wrote: Quote:To rename a file, you right click for that menu, then select "Show more options" and a new old-style menu pops up with smaller font, and tighter spacing which includes the "Rename" option.
Note when you right click a file or folder, there appears four or so small icons for the cut-copy-paste-rename functions. So it's not necessary to go to "Show more options".
And (IIRC) F2 is still available for starting a rename of a selected file without having to negotiate any menus
|
|
|
|
|
Yes, it was added recently - and I don't use it (I use F2 for rename).
It still looks "clunky" to have the "more options" in a different font and spacing!
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Item 1 - amen. To think MS has teams of people coming up and just changing stuff to change it.
Charlie Gilley
“They who can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety.” BF, 1759
Has never been more appropriate.
|
|
|
|
|
My current h/w is not eligible for upgrade but honestly, I don't really care. I've used 11 briefly on a couple of laptops I configured for our consultants, and I really see nothing with Win11 that I can't live without. I'll get another year at least out of my current systems before I think about upgrading.
"Go forth into the source" - Neal Morse
"Hope is contagious"
|
|
|
|
|
I think it is at the "dot one" point. Works fine here. I have installed it both ways. Like most Windows releases, some stuff improved, some stuff changed for the sake of change, some stuff annoying. All intuitive once you know how to do it. Big issue is hardware support, mostly the TPM chip. VMware is working on a new version that fully supports a virtual TPM 2.0 chip, current version requires encrypting the VM. You could probably test with that, seems to me they have a 30 day trial, or just use the community edition (previously called player). To protect my Windows systems from me, I run them in VM's.
I wouldn't be in any hurry but if you are hesitating because of "stable", I think those worries are over.
I am currently running VS in 180 day trial version of Server 2022 (virtual machine).
>64
Some days the dragon wins. Suck it up.
|
|
|
|
|
If I'm a "developer", I tend to keep a couple of machines around with previous OS versions for testing client software. My move to Windows 11 will probably involve a new machine if it meant eliminating an OS from the mix otherwise.
"Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I
|
|
|
|
|