Do you prefer spaces surrounding equals signs in code?

Le sondage est CLÔTURÉ
var = yes;
86%
var=no;
6%
I don't mind either way
8%
765 votes

Matt J
Matt J le 8 Juin 2026 (modifié(e) le 8 Juin 2026)
With this File Exchange submission,
you can install a Quick Access Toolbar favorite (favoriteAlignEquals.m) to reformat mouse-selected code so that they align at equals signs, and with spaces around them.
I've also attached a modification that omits the alignment and just keeps the space insertions, if that is your preference.
=====>
goc3
goc3 le 8 Juin 2026
Thanks for pointing this out.
I am surprised that MathWorks have not incorporated more such tools in the settings and editor features.
Dan Dolan
Dan Dolan le 3 Juin 2026
I think spaces get out of control and only use them to separate logical operations (==, &, etc.). I don't generally use spaces around equal sign but can tolerate them unless someone is using them between every operator, variable, and parenthesis/brace/bracket.
c=sqrt(a^2+b^2) % my preference
c = sqrt(a^2+b^2) % I will allow it
c = sqrt( a^2 + b^2) % too much
c = sqrt( a ^ 2 + b ^ 2) % you are killing me
Rik
Rik le 3 Juin 2026
For code I want to look neat and tidy I prefer spaces, but for quick&dirty code I mix the two (I know, I know).
For == however, I have a much stronger preference for spaces, especially if the full expression is longer than a dozen characters.
Steve Eddins
Steve Eddins le 2 Juin 2026
Without spaces, it appears way too cramped to my eye. I dislike it as much as many of my former MathWorks coworkers dislike underscores. 🙂
var=no;
dpb
dpb le 7 Juin 2026
No hard and fast rule; like @Rik, I'll find I've used either although a far higher fraction will be without. Related, but not spaces is is to add grouping parentheses between logical operators for clarity though not strictly needed.

Tags

Aucun tag saisi pour le moment.