I've been developing an app in Android Studio and today I happened to rest the mouse pointer on a suggestion box and read the suggestion.
This was the suggestion,
The for statement it suggested didn't need braces is this one (highlighted),
Now, the braces aren't needed as it's followed by a (fully braced) if section. However, I think this is dangerous as adding a statement after the if closing brace would (or could) appear to be part of the for loop. So, IMHO this is a bad piece of advice.
Any thought anyone?
Mike.
Edit, Am I right in thinking that Academia would frown at the above suggestion?
I will 5th that!
In this case it would be ok, but in general allowing the compiler to make those decisions could get stickey and its better just to maintain the habbit.
While we're at it, what's peoples opinion on Academai switching (at least in Australia) to Python as the language of choice? I recently saw a warning about Python on microcontrollers saying to use comments sparingly as they fill up the memory quickly. Seems like a huge step backwards to me.
While we're at it, what's peoples opinion on Academai switching (at least in Australia) to Python as the language of choice? I recently saw a warning about Python on microcontrollers saying to use comments sparingly as they fill up the memory quickly. Seems like a huge step backwards to me.
Python is a wonderfully powerful language, but if you're having a debate over when to use braces vs not then Python will drive you completely nuts!
In Python the block structure is defined purely by the source code indentation... no braces, no 'begin-end' block, etc. Make one mistake in formatting (ie tabs vs spaces) and you'll be tearing your hair out. The guy who came up with that should have been tarred, feathered, and shot, imho.