6 ms·
This is the first time I'm reading pseudocode of an algorithm before it is explained what the algorithm is supposed to do.
by amelius 10y ago
This is the first time I'm reading pseudocode of an algorithm before it is explained what the algorithm is supposed to do.
- vanderZwan 10y agoThen again, I feel you can kind of infer what will happen when the algorithm runs, just by looking at said pseudocode
- aljungberg 10y agoI'd like if this were the norm. I found the pseudocode much more readable than the mathematical description of what it was supposed to do. I'm (obviously) biased as a programmer rather than a mathematician but sometimes I think the study of mathematics would benefit tremendously from the same kind of "readability is more important than conciseness" thinking we have in software development. Here's my proposal for a "contributing style" for mathematics: Don't use short cryptic variable names like "wt". Do use informative full variable names like "weight" and "step". Don't use a subscript for something like "step": it's just tiny and hard to read, especially once you start doing math in it. You have a series and you want to talk about the nth element? Use programming like array indexing, "weight[step]". It has the added benefit of being writable in pure ASCII without a math formula editor. Don't omit your binary operators, e.g. "wt(1 + G)". Write it out: "weight[step] * (1 + reward)". You only write your formula once, but it will be read many times. Saving 1 character is not a win in total, especially not when it creates an ambiguous reading (are you using the function wt on 1 + G or are you multiplying? No way to know without resolving wt which can involve backtracking in the text for your reader.) Optimise for reading, not for writing. Don't use sigma for sums. Again readability trumps terseness. Instead of "S" with a little "t from 1 to T" and a formula like "Rt/B" on the right, just write it out: "sum(R[t] / B for t in range(1, T))". Actually it would be neat if there existed a Chrome or Safari extension that converted math notation to pseudo-Python. It wouldn't be able to assign sensible variable names automatically but at least it'd save me so much time and leaning in to stare at tiny subscripts. I might be exceptionally lazy but sometimes when I read a math paper and the dense piles of tiny script formulas begin to pile up my eyes just glaze over even that in theory I understand every component. It's just so much effort to mentally parse it. Like reading sample code in assembly. If readability was improved I'm certain me and others like me would finish reading many more papers and we'd all get a little smarter.
- j2kun 10y agoProblem is you can't efficiently do everything math needs to do if you write out everything like that. Notation is designed for the efficiency of reasoning after you've fully absorbed the ideas being expressed.
- aljungberg 10y agoRight. You could define functions. The function itself is stated in a readable form yet it is concise when later called upon. And just like you desire, this gives the reader a chance to first absorb the idea being expressed by the function (in clear pseudo-code), without making your expressions later overly verbose. The counterargument might be "but then it's harder to break it down again into components when doing algebra". But that's no different from substituting in identities as needed. Substitute in the function body whenever you need to. As long as you don't need to, don't and you both have concise writing and reduced cognitive overhead. Each time the user sees a function they have previously mentally absorbed and understood they don't need to re-read it in detail to confirm it's still the same idea.
- j2kun 10y ago> And just like you desire, this gives the reader a chance to first absorb the idea being expressed by the function (in clear pseudo-code), without making your expressions later overly verbose. This is already the case in math, just with a combination of English and algebraic notation and pictures, whatever is best to convey the idea. Either way, it seems orthogonal to your complaints about notation. I'm saying that pseudocode (as I think you mean it, pythonesque) is not nearly expressive enough to convey the ideas that mathematical notation conveys. It really does help reduce cognitive overload to distinguish two parameters, say one depending on time and one depending on position, by putting one in a subscript. (And that's still at the base of the ladder of abstraction) Sigma notation is one particularly helpful example, far more compact and easier to analyze than a for/while loop. (And, for what it's worth, list comprehensions come from mathematical set-builder notation) I'm not saying math is perfect, but having spent a lot of time doing both math and software, I like to think I understand the reasons for the pitfalls of both fields relatively well.