8 ms·
In defense of mathematicians, having conventional single letter variable makes stuff a lot easier to read. For example in graph algorithms, I used to write des
by uyt 5y ago
In defense of mathematicians, having conventional single letter variable makes stuff a lot easier to read.
For example in graph algorithms, I used to write descriptive names like:
weight = adjacenyMatrix[node][neighbor]
Nowadays I write it as:
w = G[u][v]
Because in graph theory, an edge is usually (u, v), weight is usually w, graph is usually G, etc.
It's basically the same reason why people don't name their indices "index" and instead use "i", "j", "k". And instead of point.first and point.second, you use point.x and point.y.
Naming conventions are awesome when people can agree on them.
- patrick451 5y agoWhen writing code that is mathematical, I firmly believe "descriptive" names are an anti-pattern. To figure out what anything complex is doing, I'm going to have write the equations on paper anyway, and a matrix called G instead of adjecencyMatrix speeds that process along greatly. Even better, if the variable names are sufficient short and mathy, I may not need to translate back to paper, since the equations become more recognizable in place. This zealotry a lot of devs have over descriptive names needs boundaries.
- Asraelite 5y agoIn maths, you usually write "where x is ..., y is ... etc." after equations where what the symbols represent isn't abundantly obvious anyway. Likewise, when programming, if I reuse some variable very often in a short space, I will temporarily rename it to something single-lettered, e.g. "s = volumeScalingFactor; x = s; y = s; z *= s". I think maths style vs. programming style is only one factor here, with the other simply being this application of DRY: describe one-off things well, but shorten their names if they're oft-repeated within a given context. Maths tends to reuse the same variable for a lot of different operations in a single context whereas programming doesn't as much, which naturally leads to this single-letter name vs. long name difference in styles.