Live data from Hacker News

What do I think about Lua after shipping a project with 60k lines of code?

blog.luden.io

111–120 of 146 posts

Re: What do I think about Lua after shipping a project with 60k lines of code?

#111
post #72
post #5

With dynamically typed languages I feel it's better to wait until you've tried to maintain the code for a while before you consider the languages effectiveness. I had to maintain a very large Lua codebase that has been active for several years. One big problem with Lua was how it will happily take more or less parameters to functions and continue to execute compared to something like Python where it is an error to pa…

I saw someone describe python as “stressful” for this reason and I couldn’t agree more. It’s difficult to have confidence in any change I make or review. I need to sit down and manually exercise codepaths because I don’t get the guarantees I crave from the language or tooling. While with the small amount of Rust code I’ve written lately I could yolo changes into production with no stress.

If using python with type annotations, linters like ruff and mypy do a great job at identifying issues. It's no substitute for tests and nor will it give you the same guarantees that rust will at compile time. But I think it improves the base quality of the code.

Re: What do I think about Lua after shipping a project with 60k lines of code?

#112
post #72
post #5

With dynamically typed languages I feel it's better to wait until you've tried to maintain the code for a while before you consider the languages effectiveness. I had to maintain a very large Lua codebase that has been active for several years. One big problem with Lua was how it will happily take more or less parameters to functions and continue to execute compared to something like Python where it is an error to pa…

I saw someone describe python as “stressful” for this reason and I couldn’t agree more. It’s difficult to have confidence in any change I make or review. I need to sit down and manually exercise codepaths because I don’t get the guarantees I crave from the language or tooling. While with the small amount of Rust code I’ve written lately I could yolo changes into production with no stress.

Do you believe that Rust's type system is as flexible, powerful, and easy to maintain as unit tests in Python?

Re: What do I think about Lua after shipping a project with 60k lines of code?

#113
post #83
post #35

This is the second game I've found out recently that is written in Lua. The first one one being - Beyond All Reason.

Beyond All Reason is a SpringTA fork (hack? build?) like Zero-K ? So the underlying engine isn't Lua, but higher level scripting is. I'm pretty sure this is fairly common, or was once. Other games with Lua scripting: Roblox, Baldur's Gate, Civilization VI, Crysis, Factorio, World of Warcraft, Far Cry, Leadwerks, Friday Night Funkin', Foldit, Garry's Mod, Aquaria, Balanced Annihilation, Bitfighter, Bos Wars, Cataclysm…

Here they are:

https://github.com/beyond-all-reason/Beyond-All-Reason

https://github.com/ZeroK-RTS/Zero-K

Re: What do I think about Lua after shipping a project with 60k lines of code?

#114
post #112
post #72

Earlier quoted context omitted.

I saw someone describe python as “stressful” for this reason and I couldn’t agree more. It’s difficult to have confidence in any change I make or review. I need to sit down and manually exercise codepaths because I don’t get the guarantees I crave from the language or tooling. While with the small amount of Rust code I’ve written lately I could yolo changes into production with no stress.

Do you believe that Rust's type system is as flexible, powerful, and easy to maintain as unit tests in Python?

One of the big advantages of Rust's type system is that, if you decide you want to change something (add a parameter, give a type a lifetime, rewrite an entire module), you can just do that, and then follow the errors until they're all gone. Often, once the types have been fixed again, the result will work first time when you try and run it.

In this regard, Rust (and other languages where lots of data invariants can be encoded in the type system) is very flexible and easy to maintain indeed, because you can easily make changes, even in very old or poorly-maintained code, without having to worry about the consequences. Moreover, rather than writing all the unit tests yourself, it's as if the compiler is writing the unit tests for you.

In fairness, you can't encode everything in the type system, so you still need unit tests in top of that, but in my experience you can get away with far fewer. In general, I would say that Rust's type system, when combined with unit tests, is far more flexible, powerful, and easy to maintain than dynamic Python with only unit tests.

Re: What do I think about Lua after shipping a project with 60k lines of code?

#115

Earlier quoted context omitted.

Last 50 years? Have you studied Software Engineering? They discuss LOC in depth and many academic papers on KLOC are in SE literature.

I can write a program that is 1,000,000 lines of code, and a program that is 200 lines of code, and to the end user they would be doing the same thing. Now, if you start establishing some rules about the type of code I'm allowed to write, then your statement becomes truer. But by no means do people actually follow that in the real world all the time.

To an end user those programs may be the same, but to a software engineer working on the programs they are very different.

It’s not a great metric. But it does communicate something about the scale and complexity of a codebase.

Re: What do I think about Lua after shipping a project with 60k lines of code?

#116
post #5

With dynamically typed languages I feel it's better to wait until you've tried to maintain the code for a while before you consider the languages effectiveness. I had to maintain a very large Lua codebase that has been active for several years. One big problem with Lua was how it will happily take more or less parameters to functions and continue to execute compared to something like Python where it is an error to pa…

I think that much of game development is unlike a lot of other kinds of programming, where there's often more ad hoc game mechanic prototyping than maintenance. This is where dynamic programming excels. But of course, that consideration needs to be balanced against others.

Re: What do I think about Lua after shipping a project with 60k lines of code?

#117
post #106

Earlier quoted context omitted.

Static typing is a replacement for unit tests aimed to catch type bugs. Also, no one has 100% code coverage so might as we get some guarantees for granted. I understand that statically typed code doesn't mean bug-less code, but I always find it odd that dynamic language enthusiasts feel like they need to stretch the benefits. Dynamic languages are great for many things. Strictness is not one of them and that's fine.

It's obviously not a replacement. You can get the types right but the values wrong due to faulty logic.

Sure, but only some of the unit tests are about values. Others, at least in my experience, are any handing various aspects of the implied types of values, and those can largely be removed.

Moreover, a good type system can also force the values to be right by enforcing certain invariants directly in the type system. For example, let's say I have a function `deleteProjectAs(user, project)` that deletes a project, but it only works if the user is an admin, otherwise it throws an error. I can write a bunch of tests that validate that this function checks that the user is an admin in all sorts of different cases, but with a type system I can write something like `deleteProjectAsUser(user: Admin, project: Project)`, and this guarantees at the type level that no non-Admin user can delete a project.

The point here is not that types can replace all tests, but that well-designed types can get rid of a lot of them.

Re: What do I think about Lua after shipping a project with 60k lines of code?

#118
post #112
post #72

Earlier quoted context omitted.

I saw someone describe python as “stressful” for this reason and I couldn’t agree more. It’s difficult to have confidence in any change I make or review. I need to sit down and manually exercise codepaths because I don’t get the guarantees I crave from the language or tooling. While with the small amount of Rust code I’ve written lately I could yolo changes into production with no stress.

Do you believe that Rust's type system is as flexible, powerful, and easy to maintain as unit tests in Python?

No, it's more flexible, more powerful, and easier to maintain than unit tests in Python.

Re: What do I think about Lua after shipping a project with 60k lines of code?

#119

Earlier quoted context omitted.

Same, though my trauma was Ruby. Those Rubyists who were apparently born with the language spec in their heads can do amazing things, but I am a mere mortal who needs to be told I wrote bad code right when I wrote it, not told at 2am on a production server.

do you not test your code?

In a large enough code base, there is no "your code". There is the code you wrote today, there is the code you wrote two years ago, there's all the code people are writing around you.

I change a function's arguments, I'm _pretty_ sure I caught every place it's called (spoiler alert: I didn't, because someone calls functions dynamically based on their names with call_user_func_array, maybe), and I ran the test suite - everything works, and I've fixed what doesn't.

Except some of that old code written 8 years ago didn't have good tests, or didn't have any tests at all, or didn't cover the specific code path.

And now it's 2am on the production server.

Now, you could tell me - Pavel, you're an engineer, you should be sufficiently dedicated to your craft to verify that the tests are testing those paths, you should find all those instances where that function is called (a few dozen times across the codebase), and check that those tests exist and are good. And you're not wrong! I should be doing cleanup in the codebase as I go, washing those dishes while I wait for pasta to boil or whatever...

... but now I've given myself two more actual engineer-weeks of work for a change that just needed to add a flag to a function to make sure only premium users get emails when something happens. My manager will be thrilled to hear it. Do you think I'll get a raise?

Re: What do I think about Lua after shipping a project with 60k lines of code?

#120
post #117
post #106

Earlier quoted context omitted.

It's obviously not a replacement. You can get the types right but the values wrong due to faulty logic.

Sure, but only some of the unit tests are about values. Others, at least in my experience, are any handing various aspects of the implied types of values, and those can largely be removed. Moreover, a good type system can also force the values to be right by enforcing certain invariants directly in the type system. For example, let's say I have a function `deleteProjectAs(user, project)` that deletes a project, but i…

I agree. My post was unnecessary; I did not realize the response was talking specifically about type bugs.
Post reply on HN