Hi all.
I don't know what kind of question here is.
met error occasionally when compiling: 'xxx' was not declared in this scope. and found the reason is just missing a brackets after a long time check.
Hi @shanren. In addition to madmark2150's suggestion of doing a Tools > Auto Format and then using the resulting indentation as a visual indicator of the bracket structure of your sketch, a couple of other useful tools are available for this use case:
The "Go to Bracket" keyboard shortcut (Ctrl+Shift+\ for Arduino IDE 2.x users, Ctrl+[ for IDE 1.x) will move the cursor to the opening or closing bracket of the block.
Fold the block by clicking the "˅" icon ("-" icon for IDE 1.x users) in the left margin of the editor panel at the opening of the block.
Along with the advices presented so far, I would ask you to start learning how to write code in such a manner that a closing brace is never really that far away from an opening brace.
Aim for most of the time being able to see both the open brace and the closing brace of whatever it is you are embracing.
Usually possible. If not possible, it may be a sign of something.
Agreed. A good programming style required writing a short functions and methods. As a rule, the every block of code won't be longer than one screen in used IDE.
What works for me is i copy the entire code, then open a new sketch. then paste it.
i then start in the middle identifying where blocks start and finish in the void setup
deleting the code from curly bracket to close, eventually getting to
many of today's editors can match things like braces or parenthesis and some will even starting warning when there's a mismatch.
the Arduino IDE supports the use of external editor (see preferences) to disable changing the file thru the IDE.
of course the use of editors is religious. i've continued to use vi/vim over my career and many of the tools i've used over the years (e.g. git) use it or its command. it's features have evolved over time (e.g. split screens, ctags, which evolved from cscope)
assumed this is referring to the braces or is it the loop*)
some companies (especially one that developed most of the software tools we take for granted today) had a policy that if the file couldn't fit within 2 screens (40x80), the code was split into separate files. one rational for doing such things is it reduces the chances of making an unintentional change in a different part of the code. (one reason for the development of diff).
with limitations on screen size, there are practices that help condense the code onto fewer lines so that more of it is visible on one screen, such as opening braces on a single line
a similar practice is to limit line lengths to 80 chars which would be a limit for code printed on sheets of paper, again with the goal of condensing the code into a smaller area
some might note that verbose variable names may make this difficult to achieve
but good practice is always to maintain whatever style an existing file has. many organizations used files from other organizations.
one further comment, i reformat all the code i get from this forum using a script which formats it in a style i'm comfortable with and which easily identifies missing braces because of improper indentations