| ▲ | exsf0859 2 hours ago | ||||||||||||||||||||||||||||||||||||||||
That particular code is idiomatic to anyone who worked with 2D bitmap graphics in that era. pt == point, r == rect, h, v == horizontal, vertical, BSR(...,1) is a fast integer divide by 2, ORD4 promotes an expression to an unsigned 4 byte integer The algorithms are extremely common for 2D graphics programming. The first is to find the center of a 2D rectangle, the second offsets a point by half the size, the third clips a point to be in the range of a rectangle, and so on. Converting the idiomatic math into non-idiomatic words would not be an improvement in clarity in this case. (Mac Pascal didn't have macros or inline expressions, so inline expressions like this were the way to go for performance.) It's like using i,j,k for loop indexes, or x,y,z for graphics axis. | |||||||||||||||||||||||||||||||||||||||||
| ▲ | crazygringo an hour ago | parent | next [-] | ||||||||||||||||||||||||||||||||||||||||
> Converting the idiomatic math into non-idiomatic words would not be an improvement in clarity in this case. You seem to be missing my point. It's not about improving "clarity" about the math each line is doing -- that's precisely the kind of misconception so many people have about comments. It's about, how long does it take me to understand the purpose of a block of code? If there was a simple comment at the top that said [1]:
then it would actually be helpful. You'd understand the purpose, and understand it immediately. You wouldn't have to decode the code -- you'd just read the brief remark and move on. That's what literate programming is about, in spirit -- writing code to be easily read at levels of the hierarchy. And very specifically not having to read every single line to figure out what it's doing.The original assertion that "This code is so literate, so easy to read" is demonstrably false. Naming something "pt" is the antithesis of literature programming. And if you insist on no comments, you'd at least need to name is something like "bbox_top_left". A generic variable name like "pt", that isn't even introduced in the context of a loop or anything, is a cardinal sin here. | |||||||||||||||||||||||||||||||||||||||||
| ▲ | DanHulton 2 hours ago | parent | prev [-] | ||||||||||||||||||||||||||||||||||||||||
Xyz makes sense because that is what those axes are literally labeled, but ijk I will rail against until I die. There's no context in those names to help you understand them, you have to look at the code surrounding it. And even the most well-intentioned, small loops with obvious context right next to it can over time grow and add additional index counters until your obvious little index counter is utterly opaque without reading a dozen extra lines to understand it. (And i and j? Which look so similar at a glance? Never. Never!) | |||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||