Page 2 of 2

Re: [Just for fun] Roast my code.

Posted: Sun Dec 31, 2023 1:06 pm
by Bobble68
pgimeno wrote: Sun Dec 31, 2023 12:14 pm Also, namespace pollution is a thing, and one may inadvertently use the same name for two different things, and have one overwrite the other, causing a bug.
I did this myself at one point - for some unknown reason, I have one module that uses a local variable named, and a global for the rest of the program also called mouse. For a while it wasn't an issue, but when I eventually wanted to make use of the functionality of the global version, I found that I was stuck without fixing the whole module :death:. The way I got around it is by making another local variable at the start called gmouse, that was just a reference to the global version - not the most elegant solution, but it works. I now know not to do that.

Re: [Just for fun] Roast my code.

Posted: Mon Jan 01, 2024 3:13 pm
by pgimeno
Bobble68 wrote: Sun Dec 31, 2023 1:06 pm I did this myself at one point - for some unknown reason, I have one module that uses a local variable named, and a global for the rest of the program also called mouse. For a while it wasn't an issue, but when I eventually wanted to make use of the functionality of the global version, I found that I was stuck without fixing the whole module :death:. The way I got around it is by making another local variable at the start called gmouse, that was just a reference to the global version - not the most elegant solution, but it works. I now know not to do that.
Remember that you can also use _G.mouse. Some style guides even mandate all globals to be referenced through _G.

Re: [Just for fun] Roast my code.

Posted: Mon Jan 01, 2024 3:31 pm
by Bobble68
pgimeno wrote: Mon Jan 01, 2024 3:13 pm Remember that you can also use _G.mouse. Some style guides even mandate all globals to be referenced through _G.
Had not occured to me that this was possible, but I suppose it would be (at the time I did the fix I didn't know about _G).

Re: [Just for fun] Roast my code.

Posted: Sun Jan 07, 2024 10:27 am
by zalander
milon wrote: Thu Dec 28, 2023 4:14 pm Why is 'tmp' a global??? Local variables have far better performance!

Also, try to structure your game to not need love.load() at all - it'll help you improve your code structure.
This code was for a challenge "Create the worst text editor"(Given by a friend). Sooo the performance has to be.
Image

Re: [Just for fun] Roast my code.

Posted: Sun Jan 07, 2024 10:36 am
by zalander
Bobble68 wrote: Fri Dec 29, 2023 12:22 pm mr global.png
Azzla wrote: Sun Dec 24, 2023 7:07 am You have no window wrapping so you can type on a line forever, but that's more of a "incompleteness" thing than a code thing.
Also, love.graphics.printf has text wrapping built in, you might want to consider using it instead.
Printf kinda breaks the line number system. Soo ill need to fix that before i add printf.