Page 1 of 1

Proposal for the devs: PIXEL and VERTEX

Posted: Tue Oct 03, 2017 5:11 pm
by grump
I recently tried to declare a constant named PIXEL in a fragment shader, and it failed with a syntax error. It took me a while to figure out what was the problem: in wrap_Graphics.lua, there's

Code: Select all

#define PIXEL
I understand its purpose, but I'd like to propose that you change it to

Code: Select all

#define PIXEL PIXEL
When defined this way, it still serves its purpose, but it can also still be used as an identfier in shader code without getting syntax errors. Same for VERTEX.

Reasoning is, it is convention to write constants in UPPER CASE, and PIXEL and VERTEX are somewhat likely candidates to be used in shaders. The syntax error is confusing at first. This minor redefinition would solve this, and it doesn't seem to have any downsides.

Re: Proposal for the devs: PIXEL and VERTEX

Posted: Tue Oct 03, 2017 5:42 pm
by raidho36
All caps names by convention reserved for macros, not constants. You can however redefine it at any point.

Re: Proposal for the devs: PIXEL and VERTEX

Posted: Tue Oct 03, 2017 6:01 pm
by grump
I'm referring to the conventions published in K&R's The C Programming Language, which are widely accepted for basically all C-like languages for many, many years. What convention do you mean?
Another accepted convention is to prefix your implementation defined stuff with underscores instead of polluting the global namespace with common identifiers.

Defining the PIXEL and VERTEX macros the way I have proposed has no downsides and it prevents syntax errors that can't be explained by reading the language specifications. The principle of least surprise applies.