Programming thread

Does anyone else here hate Go's strictness on unused variables and imports, and the forced code style?
I love the language itself and the package ecosystem, I think it's one of the most productive and readable languages. But I hate the compiler. Every time I quickly want to change or comment out code to debug or whatever, some variables or imports become unused and it will refuse to compile. Which means I have to either 1. needlessly change other parts around or 2. forget about it.
It feels user hostile, they think the only way for people to write good code is to have bad code literally not compile (this is obviously not the case, you can still write buggy software in Go).
 
Here's a C++ question for any 400-pounders floating by:

Let's say you have a raw pointer to some data (from mmap or whatever) and you want to read some or all of it into a STL container like std::vector. Is there any better way to do it than just a plain old for loop where you just append the elements one after another? It feels like Current Year C++ would have some sort of constructor or initializer or helper for this, but apparently not.
Not that there's anything wrong with writing the for loop, it just strikes me as odd somehow.

(EDIT: I guess it probably doesn't generalize well past plain old data like ints or chars)
 
Here's a C++ question for any 400-pounders floating by:

Let's say you have a raw pointer to some data (from mmap or whatever) and you want to read some or all of it into a STL container like std::vector. Is there any better way to do it than just a plain old for loop where you just append the elements one after another? It feels like Current Year C++ would have some sort of constructor or initializer or helper for this, but apparently not.
Not that there's anything wrong with writing the for loop, it just strikes me as odd somehow.

(EDIT: I guess it probably doesn't generalize well past plain old data like ints or chars)
The problem with c++ is it doesn't often let you get clever with memory because of RAII, if you write your own array class this is trivial but otherwise you'll have to check the standard to see if it supports that or rely on non-standard behavior
 
  • Informative
Reactions: Belisarius Cawl
Here's a C++ question for any 400-pounders floating by:

Let's say you have a raw pointer to some data (from mmap or whatever) and you want to read some or all of it into a STL container like std::vector. Is there any better way to do it than just a plain old for loop where you just append the elements one after another? It feels like Current Year C++ would have some sort of constructor or initializer or helper for this, but apparently not.
Not that there's anything wrong with writing the for loop, it just strikes me as odd somehow.

(EDIT: I guess it probably doesn't generalize well past plain old data like ints or chars)
You could also potentially use a std::span and avoid having to do a copy.
 
Houston, we have a problem. I knew about the Recall ‘feature’ in Windows, but I didn’t realize that Mac OS and iOS basically have or will have (depending on the device) similar embedded spyware that defeats e2e encryption. And it’s believed that Google isn’t far behind with their own tracking solution.

How do we get these giant corporations to stop spying on us? Who will publicize to the masses what they are doing to eliminate privacy on our devices? Are de-Googled phones secure?

 
I never realized how based lua is, it's like the perfect scripting language to pair with C/C++. No bloat 5 seconds build, intuitive language, module system. I wish more languages would follow that example instead of languages having a massive runtime and organizational bloat that feeds off the community like a parasite.
 
I never realized how based lua is, it's like the perfect scripting language to pair with C/C++. No bloat 5 seconds build, intuitive language, module system. I wish more languages would follow that example instead of languages having a massive runtime and organizational bloat that feeds off the community like a parasite.
Welcome to the club.
I'm all in on RIIL (Rewrite It In Lua) instead of Rust. Get easy memory safety without all the downsides of Rust.
 
I never realized how based lua is, it's like the perfect scripting language to pair with C/C++. No bloat 5 seconds build, intuitive language, module system. I wish more languages would follow that example instead of languages having a massive runtime and organizational bloat that feeds off the community like a parasite.
Guile is similarly easy from what I've seen where I was playing around with it.
However, Lua has Sol2 which is amazing library for Lua bindings in modern C++. I don't think Guile has something like that.
 
Guile is similarly easy from what I've seen where I was playing around with it.
However, Lua has Sol2 which is amazing library for Lua bindings in modern C++. I don't think Guile has something like that.
Its GPL Affero license so you won't be able to embed it in a non-free application, unlike Lua which is MIT. Also I don't really like lisp but even so you could write a lisp in an afternoon if you needed it so I would either do that or find a permissive licensed one
 
Its GPL Affero license so you won't be able to embed it in a non-free application, unlike Lua which is MIT. Also I don't really like lisp but even so you could write a lisp in an afternoon if you needed it so I would either do that or find a permissive licensed one
From Guile website:
C code linking to the Guile library is subject to terms of that library. Basically such code may be published on any terms, provided users can re-link against a new or modified version of Guile.
So if I understand correctly, you are not forced to GPL your code. Since core is LGPL.
 
I never realized how based lua is, it's like the perfect scripting language to pair with C/C++. No bloat 5 seconds build, intuitive language, module system. I wish more languages would follow that example instead of languages having a massive runtime and organizational bloat that feeds off the community like a parasite.
This is next on my list already of languages to learn. What's a good resource for getting started with pairing with c++?
 
  • Like
Reactions: Belisarius Cawl
This is next on my list already of languages to learn. What's a good resource for getting started with pairing with c++?
There are many examples in the lua source code and external libraries of binding lua functions to C functions but for C++ specifically I'm not sure it's different for simple bindings
 
There are many examples in the lua source code and external libraries of binding lua functions to C functions but for C++ specifically I'm not sure it's different for simple bindings
If you want dynamic linking then you should use lua.hpp header, otherwise C++ is the same.

One thing I absolutely love in Lua is coroutines. It is such a comfy feature when you make something in game that's need to be sequential, but each part should be executed once per x ticks. With coroutines instead of using some kind of queue of commands, you just yield for x ticks. Thanks to it all logic is sequentially presented, instead of being spread out.

Now C++ has coroutines too, but it's a massive pain in ass to implement. I am still unsure if I had grasped it correctly.
 
If you want dynamic linking then you should use lua.hpp header, otherwise C++ is the same.

One thing I absolutely love in Lua is coroutines. It is such a comfy feature when you make something in game that's need to be sequential, but each part should be executed once per x ticks. With coroutines instead of using some kind of queue of commands, you just yield for x ticks. Thanks to it all logic is sequentially presented, instead of being spread out.

Now C++ has coroutines too, but it's a massive pain in ass to implement. I am still unsure if I had grasped it correctly.
I remember reading an implementation of coroutines in C using a state argument and switch case. I don't fully recall how it all worked, but I remember there being a dirty looking trick to keep it from being recursive and muddy up which coroutine was the "parent" and also buried some of the switching structure in macros. It was vaguely unholy but also strangely compelling. I'm glad coroutines have been properly implemented somewhere, it would be a shame if they were relegated to gnarly macro tricks.
 
It's possible to get coroutine-like behavior in C using `makecontext(3)` and `swapcontext(3)`, but it's not good practice. As of now coroutines don't work nicely outside of garbage collected runtimes. Awesome things like coroutines or Lua's debug hooks are greatly undervalued in the current day. The fact that many applications run fast enough in Javascript should be a wake up call that we can enjoy higher level features without troubling user-experience, yet many are still suffering from runtime-phobia.
 
Back