Klip icon indicating copy to clipboard operation
Klip copied to clipboard

Use enum intead of strings

Open arBmind opened this issue 7 years ago • 3 comments

Hey, nice project.

I want to suggest to use the enum values in the Parser instead of comparing strings. You have everything in place, but you .toString() and compare it to string.

See Parser.cs line 34:

if (tok.TokenName.ToString() == "Import")

This is slow and fragile. If you have a typo in the string the compiler will not cover your back. You will only see the parser failing. As you want to place this project as a learning experience, I suggest to promote good practices.

if (tok.TokenName == Lexer.Token.Import)

It is not even longer, has less brackets and all around a bit better 😎

arBmind avatar Jun 01 '17 14:06 arBmind

Thanks for the tip, I've just updated my parser to use enums instead of strings :)

TimeLoad00 avatar Jun 02 '17 05:06 TimeLoad00

It looks much better now. 👍

arBmind avatar Jun 02 '17 18:06 arBmind

Left a comment in the commit, but RightBrace got turned into RightParan and broke compilation of functions.

DarkLotus avatar Jun 07 '17 08:06 DarkLotus