News for hackers. Stuff that matters.
Re:Writing a small ray tracer in Rust and Zig by dahart on Tuesday July 02, 2019 @10:23AM (#20335442)
> I’m convinced that there’s a proper mathy / lighting-y word for each component in that expression.

Sometimes yes, but often no. Frequently this kind of expression is the result of solving an equation, so it’s just an expression.

Graphics people often use two approaches for sub-expressions:

- You can name them with the same letters that are in the expression, just with the punctuation & operators removed, for example:

    const uvMinusNTimesDt = uv.sub(n.mul(dt))
- Alternatively, just like with equations, math people often freely assign single letter names to variables without worrying about semantic meaning.

    const q = uv.sub(n.mul(dt))
Nothing really wrong with naming sub-expressions after fruits, or single letters, or spelling them out explicitly.

It might be worth reflecting on what the goals are with your naming, and whether it matters what they’re named. As software engineers, our biases lean toward making choices that improve readability and maintainability. But for a specific equation that will never change once it works correctly, our preconceived notions about good software design and best practices might not actually apply to this situation. It might be more important to document the source of the equation than to make the implementation readable.

Re:Writing a small ray tracer in Rust and Zig by fiddlerwoaroof on Tuesday July 02, 2019 @11:06AM (#20335826)
People say “the two hardest problems in computer science are cache invalidation, naming and off-by-one errors” and we often design systems so that we don’t have to think about cache invalidation and off by one errors (e.g. list.map rather than a for loop). I often wonder if we should think about minimizing how often we name things as well.
Re:Writing a small ray tracer in Rust and Zig by pgt on Tuesday July 02, 2019 @11:51AM (#20336261)
Excel is the most popular functional programming language in the world. Its killer feature is that you don’t have to name your values before you can use them.
Re:Writing a small ray tracer in Rust and Zig by tombert on Tuesday July 02, 2019 @12:23PM (#20336636)
I'd argue that its killer feature is that everything is inherently reactive.
Re:Writing a small ray tracer in Rust and Zig by superdimwit on Tuesday July 02, 2019 @12:22PM (#20336624)
Well, it just has a cartesian namespace
Re:Writing a small ray tracer in Rust and Zig by carapace on Tuesday July 02, 2019 @03:11PM (#20338387)
Point free form? Ditch your variable names.

> It is very common for functional programmers to write functions as a composition of other functions, never mentioning the actual arguments they will be applied to.

https://wiki.haskell.org/Pointfree

> We are going to use named variables to keep track of the arguments, then write a definition without them.

http://joypy.osdn.io/notebooks/Quadratic.html

Re:Writing a small ray tracer in Rust and Zig by dahart on Tuesday July 02, 2019 @11:14AM (#20335898)
> I often wonder if we should think about minimizing how often we name things as well.

Personally, I think that depends, so I like to challenge my own assumptions and examine things case by case. The implementation of a math equation, especially one that is the result of solving a different equation, and so went through a symbolic/algebraic transformation, that is one place where adding more names might not clarify the implementation.

In general, though, my personal experience has been one of not seeing things named enough. Specifically, feature creep in software tends to try to add code with a light touch without disturbing too much of the surrounding code, but with new concepts that deserve more naming than they get. This can and does lead to code that is difficult to maintain, and I think I’ve seen more of that mistake than of naming things too much, and I suspect it’s much easier to not just shoot yourself in the foot, but cut your leg off, by under-naming rather than by over-naming.

Re:Writing a small ray tracer in Rust and Zig by Skunkleton on Tuesday July 02, 2019 @11:13AM (#20335895)
Aren’t features like if-expressions just that?
Re:Writing a small ray tracer in Rust and Zig by Const-me on Tuesday July 02, 2019 @03:08PM (#20338356)
> Frequently this kind of expression is the result of solving an equation

Some time ago I’ve stopped solving equations, using software for that. Nowadays, when I need them solved, I sometimes don’t even write code, here’s an example: https://stackoverflow.com/questions/1351746/find-a-tangent-p...

Symbolic math software does more “optimizations” than even offline compilers. For example, I have never saw an optimizer which is aware that sin(x)^2 + cos(x)^2 = 1.