-
Notifications
You must be signed in to change notification settings - Fork 1
Enums #47
Copy link
Copy link
Open
Labels
compilerAnything about the compilerAnything about the compilerenhancementNew feature or requestNew feature or requestquality-of-lifeAnything that focuses on making life easierAnything that focuses on making life easier
Description
Take a look at this piece of code:
macro KEYWORD-UNKNOWN 0 endmacro
macro KEYWORD-MACRO 1 endmacro
macro KEYWORD-ENDMACRO 2 endmacro
macro KEYWORD-PROC 3 endmacro
macro KEYWORD-RETURNS 4 endmacro
macro KEYWORD-IN 5 endmacro
macro KEYWORD-END 6 endmacro
macro KEYWORD-RETURN 7 endmacro
macro KEYWORD-MEMORY 8 endmacro
macro KEYWORD-AND 9 endmacro
macro KEYWORD-LET 10 endmacro
macro KEYWORD-PEEK 11 endmacro
macro KEYWORD-IF 12 endmacro
macro KEYWORD-ELSE 13 endmacro
macro KEYWORD-WHILE 14 endmacro
macro KEYWORD-DO 15 endmacro
macro KEYWORD-BREAK 16 endmacro
macro KEYWORD-INCLUDE 17 endmacro
macro KEYWORD-CAST 18 endmacro
macro KEYWORD-SIZEOF 19 endmacro
macro KEYWORD-NAMESPACE 20 endmacro
macro KEYWORD-ENDNAMESPACE 21 endmacro
This code could be rewritten using enums (and namespaces). For example:
namespace KEYWORD enum
MACRO
ENDMACRO
PROC
RETURNS
IN
...
end endnamespace
In this example, namespace keyword is used to prepend every name with KEYWORD: and enum is used to repeatedly and easily define macros that expend to a single integer that is different every time.
This new code is much easier to write and read. Adding the enum keyword will improve the readability of the code.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
compilerAnything about the compilerAnything about the compilerenhancementNew feature or requestNew feature or requestquality-of-lifeAnything that focuses on making life easierAnything that focuses on making life easier