Catching all the typos ...

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
User avatar
Varkas
Citizen
Posts: 83
Joined: Mon Mar 09, 2020 2:26 pm

Catching all the typos ...

Post by Varkas »

First post here ... so, I've discovered Love2D just a few days ago and the first steps were very easy. Also, seeing that it is available on basically all major platforms looked very interesting to me. I had been thinking about starting a new game related project since a while, and being unsure which language and technology to use, the ease to get started in Love2D made me try it some more.

Basically all the time I have been using stroing typed and compiled languages. Particularly the compiling step gave me something that I am missing right now. Typos in variable names are not discovered until the function is actually executed.

In a way the ease to get started has been countered now by a loss of time in starting the program (very fast, yes) and then clicking some stuff and finally notice that I mistyped mainUi as mainUI in some place and just tried to call a function on nil instead of the mainUi table.

Is there something to do about this? I've mostly been using Java so far, but ocasionall also C and C++

At the moment the idea to change the name of a table member in one assignment and not being able to find all the places with references to rename them as well looks scary to me. A C or Java compiler would find them.
In soviet russia, code debugs you.
User avatar
ReFreezed
Party member
Posts: 612
Joined: Sun Oct 25, 2015 11:32 pm
Location: Sweden
Contact:

Re: Catching all the typos ...

Post by ReFreezed »

Welcome to the forums!

This is the curse of high-level languages like Lua. You can use a Lua linter to catch some errors (this is probably what you're looking for) but other errors can only be found when running and testing the program. You simply have to be more diligent when typing compared to other stricter languages. It is a good idea to make up you own rules to follow to make the code more consistent and make it harder to type the wrong thing (i.e. always use camel case or snake case). Even though Lua is a very dynamic language, you can still have your own rules that says e.g. "this variable may only contain strings" or "this name is a constant".

Anyway, look up linters for Lua to begin with.
Tools: Hot Particles, LuaPreprocess, InputField, (more) Games: Momento Temporis
"If each mistake being made is a new one, then progress is being made."
User avatar
zorg
Party member
Posts: 3465
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Catching all the typos ...

Post by zorg »

There's also strict.lua that you can include in your projects, which will catch all "undeclared" globals (probably need to make an exception for the love table itself) as to remind you of potential mistakes where you might have forgotten to write local before a variable.
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
User avatar
pgimeno
Party member
Posts: 3655
Joined: Sun Oct 18, 2015 2:58 pm

Re: Catching all the typos ...

Post by pgimeno »

+1 about the linter. If you don't want to install one, I offer an alternative solution using only POSIX tools and LuaJIT here: https://love2d.org/forums/viewtopic.php?f=5&t=86717

I don't advocate strict.lua, because it's run-time, and the hidden globals may be in a code path that is hard to trigger.

But yes, that's one of the reasons why globals are not recommended in Lua: if you declare your locals and don't use globals, you're more likely to catch typos by any of the methods outlined here.
User avatar
Varkas
Citizen
Posts: 83
Joined: Mon Mar 09, 2020 2:26 pm

Re: Catching all the typos ...

Post by Varkas »

Thanks for the replies. Yes, a linting tool is probably what I want.

For coding styles, I'm fairly strict, and I don't use globals if possible. It's mostly typos in field names of tables that bother me currently. So, I'll need a linter that checks for uninitialized table members rather than undefined globals. An additional problem showed up yesterday - at times the nil shows in a totally good part of code and the typo was somewhere back in data flow. That makes it kinda time consuming to find the typo cause one needs to trace back all assignments from that point and check them. I know it's totally vaild lua code to read from a table member that never had a value assigned, it's just a new type of coding error for me.

Overall I like the dynamic aspect of Lua. It makes many things easy.
In soviet russia, code debugs you.
User avatar
ReFreezed
Party member
Posts: 612
Joined: Sun Oct 25, 2015 11:32 pm
Location: Sweden
Contact:

Re: Catching all the typos ...

Post by ReFreezed »

I don't know if linters can help with misspelled table fields specifically, but it'd be easy to write a script that looks for similar identifiers that have different letter cases (i.e. mainUi vs. mainUI) across the files in the project.

You're saying you've used compiled languages. I would actually advice to incorporate a "build/preprocessing phase" into your workflow even when working with Lua (if you haven't already). That way you can have linters and whatnot run every time before the game starts for minimal manual effort and time wastage.

As for renaming table fields it's just good to have more descriptive and unique names to make it easier to search for, or just try to choose a good name to begin with to reduce the need for renaming later.
Tools: Hot Particles, LuaPreprocess, InputField, (more) Games: Momento Temporis
"If each mistake being made is a new one, then progress is being made."
User avatar
Varkas
Citizen
Posts: 83
Joined: Mon Mar 09, 2020 2:26 pm

Re: Catching all the typos ...

Post by Varkas »

No, I don't have a build step yet. I thought that's one of the benefits of interpreted languages that you just "type and run" the code. Establishing such a step would also allow to run unit tests, and with some good path coverage they should detect all those typos.

On the other hand this contradicts the idea that lua is aimed at small and medium projects, cause that it something typically found in larger and more serious projects.

At the moment love2d wins mostly on the ease of distribution. A java runtime is huge, and compiling C code for every target platform is a pain. My current project is client-server, and likely I'll do the server code in Java, and have the client based on love2d. That is, if the project actually gets somewhere. I have a habit to lose interest before any of my past projects had been finished. Learning some Lua surely doesn't hurt though.
In soviet russia, code debugs you.
monolifed
Party member
Posts: 188
Joined: Sat Feb 06, 2016 9:42 pm

Re: Catching all the typos ...

Post by monolifed »

User avatar
pgimeno
Party member
Posts: 3655
Joined: Sun Oct 18, 2015 2:58 pm

Re: Catching all the typos ...

Post by pgimeno »

Oh yes, and luacov for coverage analysis.
https://github.com/keplerproject/luacov

Edit: But that's not easy to use with Löve.
User avatar
Varkas
Citizen
Posts: 83
Joined: Mon Mar 09, 2020 2:26 pm

Re: Catching all the typos ...

Post by Varkas »

Thanks, ingsoc451 and pgimeno. Those two tools look quite helpful to me!
In soviet russia, code debugs you.
Post Reply

Who is online

Users browsing this forum: No registered users and 13 guests