[V2] #Warn for assignment in if statement condition

Propose new features and changes
geek
Posts: 1052
Joined: 02 Oct 2013, 22:13
Location: GeekDude
Contact:

[V2] #Warn for assignment in if statement condition

Post by geek » 27 Jan 2023, 06:19

In many languages, putting an assignment into the condition of an if statement is considered a bad practice. In Python, for example, it wasn't even possible until a late 3.X release and even then its addition was highly controversial.

Although V2 makes accidental assignment in an if statement's conditional much less likely thanks to no longer making single equals pull double duty, I've already seen this mistake made by a real person since the release of V2.

I'm not sure if this warning should be on by default--I've seen a lot of people use this technique intentionally, especially for processing dllcall return values--but for people who like #Warn to tell them when they go outside the realm of best practice I think it's a reasonable check along the likes of "local same as global".

Return to “Wish List”