• 0 Posts
  • 216 Comments
Joined 1 year ago
cake
Cake day: June 21st, 2023

help-circle
  • I’m not going to say that C is unusable by any means (and I’m not saying you are saying that). It’s a perfectly usable language. I do think that more people would benefit from exploring other options though. Programming languages are tools, not sports teams. People should familiarize themselves with many tools so they always have a good tool to use for any job.

    I think a lot of people believe this because there is some truth to parts of it. I think we see languages like Rust and Zig (and others) popping up to try and solve specific problems better than others.

    As for OP’s post, there is no single “C successor” or anything like that. People will use the best tool they know of for the job whether that’s C, Rust, C++, Zig, Python, C#, etc. Many languages will “replace” C in some projects, and at the same time, C will replace other languages in some projects (likely to a lesser extent though).

    (Not /s this time)


  • Honestly C is the future. I don’t know why people would move from C to any other language. It does the job well enough that there’s no reason not to use it.

    Think about it. Every modern application depends on a piece of code written in C, not Rust or Zig or any other language (except assembly). It can be used to solve any problem, and works in more places than any other language.

    These arguments about “security” and “memory safety” are all pointless anyway in the face of modern code scanning tools. Cross-platform dev can be done trivially with preprocessors. If that’s not enough, I don’t know what to say. Get better at writing C obviously.

    Lifetimes and UB should all be kept in mind at all times. You can explicitly mark lifetimes in your C code if you want using comments. Any index-out-of-bounds bugs, use-after-free, etc are just signs that your team needs more training and better code scanning utils. Write more tests!

    Anything more complex than a simple typedef is just a sign that you’re over-engineering your solution. #include is both simple, and does exactly what you’d expect any reasonable language to do - paste your referenced code inline. It’s genius, and doesn’t require any complicated explanations on namespaces and classes and subclasses and so on.

    So which will be the future? C obviously.

    /s




  • Correct - Rust’s attribute grammar allows any parseable sequence of tokens enclosed in #[attr ...] basically. Serde specifically requires things to be in strings, but this is not a requirement of modern Rust or modern versions of syn (if you’re comfortable writing your own parser for the meta).

    The author is not a Rust expert though, so I’m not surprised to see this assumption. It doesn’t take away from the article though.

    Edit: for fun, syn has an example parsing an attribute in an attribute




  • I made the mistake of starting Frostpunk (1) since I saw that 2 released. It’s an incredibly well-made game. The art style is beautiful, the game is intense, there is a lot of emotion, and it does its one thing just so well. Unlike a lot of modern games these days, Frostpunk wants you to lose, which is fitting for its setting. It sees that you’re behind, then kicks you in the shins for good measure rather than lending a helping hand. I’ve lost so many hours of my time to this game in the past week.

    I’ve read that Frostpunk 2 is a completely different game. That one might be next on my list if I get to it before Factorio updates and the expansion for it comes out.



  • Adding a single unused function should no effect on runtime performance. The compiler removes dead code during compilation, and there’s no concept at runtime anyway of “creating a function” since it’s just a compile-time construct to group reusable code (generally speaking - yes the pedants will be right when they say functions appear in the compiled output, to some extent).

    Anyway, this can all be tested on Godbolt anyway if you want to verify yourself. Make a function with and without a nested unused function and check the output.




  • Pushing HTML even further, one could say it’s a declarative programming language that programs a UI in a mostly-stateless manner (inputs aren’t really stateless but you can argue the state is provided by the UI rather than managed by HTML).

    I’m not sure I’d make this leap myself though, I have a hard time classifying it (or any other markup language) as a PL. As far as I am aware, you can’t really program a state machine with pure HTML, though you can accept inputs and return outputs at least.


  • Two thoughts come to mind for me:

    1. I think people should feel free to use any language however they want for their own needs and projects, but it’s also important to understand what exactly “unsound” and “undefined behavior” mean if you’re going to dabble with them. If it’s a risk you’re willing to take, go for it, but don’t be surprised if things break in ways that make no sense at all. Realistically a compiler won’t delete your root directory if you trigger UB or anything, but subtle bugs can creep in and change behaviors in ways that still run but which make unrelated code break in difficult to debug ways.
    2. The borrow checker is one of Rust’s biggest features, so looking for ways around it feels a bit counterproductive. Feature-wise, Rust has a lot of cool constructs around traits and enums and such, but the language and its libraries are built around the assumption that the guarantees the compiler enforces in safe code will always be true. These guarantees extend beyond the borrow checker to things like string representation and thread safety as well. As an alternative, some other languages (like C++, which you mentioned, or maybe even Zig) might be better suited for this approach to “dirty-but-works” development, and especially with C++, there are some excellent tools and libraries available for game development.




  • I think it’s good to document why things are done, but extracting things out into another function is just documenting what is being done with extra steps. This also comes with a number of problems:

    1. Not all languages are readable. Documenting what is being done is important in some C, or when working with some libraries that have confusing usage syntax.
    2. Not all people reading the code know the language or libraries well. Those people need guidance to understand what the code is trying to do. Function names can of course do this, but…
    3. Not all types can be named in all languages. Some languages have a concept of “opaque types”, which explicitly have no name. If parameter and return types must be specified in that language, working around that restriction may result in unnecessarily complicated code.
    4. Longer files (the result of having dozens of single-use functions) are less readable. Related logic is now detached into pointers that go all over the file all because of an allergic reaction to code comments, where a simple // or # would have made the code just as readable.
    5. Function names can be just as outdated as code comments. Both require upkeep. Speaking from personal experience, I’ve seen some truly misleading/incorrect function names.