Code suggestion from Android Studio. Good?

Status
Not open for further replies.

Pommie

Well-Known Member
Most Helpful Member
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?
 
Last edited:
I would agree with the rest - use the braces - if it doesn't need them, then the compiler won't generate code for them, rather like comments.

It's not about functionality, working or not, speed, code size etc. - it's about readability.

Anyway, since Academia dropped Pascal for the 'free for all' of C (and others), they can't really complain about it either way
 
Seems unanimous - always use braces.

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.

Mike.
 

Isn't Python interpreted?, so it's slow, and (as you say) comments will waste space. Code wise it's fairly similar to C.

As far as I'm aware, Python tends to be an option on the larger microcontrollers, such as the ESP32 - you're unlikely to get it on a 16C84
 
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.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…