Proposal for the devs: PIXEL and VERTEX

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
grump
Party member
Posts: 947
Joined: Sat Jul 22, 2017 7:43 pm

Proposal for the devs: PIXEL and VERTEX

Post 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.
User avatar
raidho36
Party member
Posts: 2063
Joined: Mon Jun 17, 2013 12:00 pm

Re: Proposal for the devs: PIXEL and VERTEX

Post by raidho36 »

All caps names by convention reserved for macros, not constants. You can however redefine it at any point.
grump
Party member
Posts: 947
Joined: Sat Jul 22, 2017 7:43 pm

Re: Proposal for the devs: PIXEL and VERTEX

Post 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.
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 57 guests