|
Is there a general stigma against using namespace std; or similar at global scope within a source file? None of the places I've worked have had an issue with it, but I've seen it mentioned as a bad thing and now I'm wondering. (Obviously header files are a different story, so I'm specifically asking about source files.)
|
# ¿ Aug 11, 2020 16:30 |
|
|
# ¿ Apr 28, 2024 20:52 |
|
If you're developing on Windows you're going to have a bad time.
|
# ¿ Aug 12, 2020 16:32 |
|
Do you actually care about the difference in performance?
|
# ¿ Aug 13, 2020 23:55 |
|
The more I see the more I'm convinced that multiple inheritance is almost always a mistake.
|
# ¿ Aug 31, 2020 17:30 |
|
Multiple implementation inheritance can maybe be OK if the class hierarchies involved are completely orthogonal. Early in my career I worked on a multiplatform graphics engine that allowed us to design forms for a desktop application. We had one set of classes that represented the abstract logic for various controls, and another that handled everything OS-specific. The only issues with that were related to the inheritance hierarchy being deep and C++ not having a mechanism to require every class deriving from a given parent to supply its own implementation of some pure virtual function (hello object slicing!). We probably still should've used composition, though.
|
# ¿ Sep 1, 2020 23:20 |
|
Ralith posted:They can be convenient sometimes, but you never need them. It's just a method of organizing your code inside a class. The upside is that if a class is declared private inside another class, there's absolutely no way for anything outside that class to access it without modifying the declaration of the outer class. I can't think of a situation off the top of my head where that's a really good design, but it's there if you want it.
|
# ¿ Sep 9, 2020 16:55 |
|
I guess that falls under the category of things you can do but why.
|
# ¿ Sep 9, 2020 17:10 |
|
C++20 approved
|
# ¿ Sep 11, 2020 15:37 |
|
The problem is that your approach only works for very small projects, and a build system that only supports small projects isn't all that useful. Everything's built to scale. CMake is probably as close as you're going to get. For a small project where the instructions are just "compile everything in this folder and make an executable out of it", it's pretty simple to come up with something that works.
|
# ¿ Sep 30, 2020 15:45 |
|
Just declare everything const and throw around a lot of mutable's until things compile.
|
# ¿ Oct 27, 2020 18:19 |
|
Look at disjoint sets.
|
# ¿ Oct 31, 2020 00:01 |
|
The fact that no one else uses CMake shouldn't prevent you from using it, unless it's not installed on your build machines. If it is, you can just provide a script that calls CMake and let the larger build system run that.
|
# ¿ Nov 20, 2020 14:50 |
|
OneEightHundred posted:What kind of situations does that happen in? I thought the assumption was that all unspecified digits were zero. 1 could be anything between 0.5 and 1.5, but 1.0 can only be between 0.95 and 1.05.
|
# ¿ Dec 3, 2020 00:39 |
|
fourwood posted:Nah. Don’t report 3+ sig figs on your uncertainties. Please give me reputable sources to change my mind/undo my years of “simplistic” learning. See propagation of uncertainty and references therein.
|
# ¿ Dec 7, 2020 21:24 |
|
IME make is easier for a small project but CMake is much better for large projects. I'm not sure exactly where the point of tradeoff is, but I've definitely run into it on projects that aren't all that large.
|
# ¿ Dec 17, 2020 18:54 |
|
#ifdef __cplusplus gives you a section that won't be seen by a C compiler. You can do a lot with that. It's really tough to write that without a closing #endif.
|
# ¿ Jan 28, 2021 04:46 |
|
matti posted:#undef __cplusplus I really want to hear the story behind this one.
|
# ¿ Jan 28, 2021 14:19 |
|
Zopotantor posted:That is a stupid article. Not only is there a cheap, clever and simple algorithm to detect cycles in a linked list (Floyd's cycle detection algorithm, which every programmer ought to know just because of the "tortoise and hare" technique it uses), but there are actually real world use cases for it (I had to implement it long ago as part of a consistency check in a CAD system). So you agree that it's a trivia question?
|
# ¿ Feb 19, 2021 21:40 |
|
Part of my job involves designing new algorithms. The only time I've ever heard of the cycle detection algorithm is in the context of interview questions, and I never knew the name until it came up in this thread. I can see it mattering in the late 60s back when every program could directly overwrite arbitrary parts of memory, but if you're writing anything at all modern, it's just not worth worrying about.
|
# ¿ Feb 20, 2021 19:12 |
|
The facilities that Rcpp provides to C++ code are just regular C++ libraries. You don't need to be using R at all to use them. The package build process through RStudio or similar does handle things like include/library paths, though, so you do have to set that up if you're not working with R.
|
# ¿ Feb 22, 2021 19:08 |
|
https://twitter.com/trap0xf/status/1364121979796643841
|
# ¿ Feb 23, 2021 17:13 |
|
ultrafilter posted:The facilities that Rcpp provides to C++ code are just regular C++ libraries. You don't need to be using R at all to use them. The package build process through RStudio or similar does handle things like include/library paths, though, so you do have to set that up if you're not working with R. Thinking about this some more, and I'm pretty sure it's true for the data structures that Rcpp provides. You'd probably run into some problems trying to use the random number generator library, though.
|
# ¿ Feb 25, 2021 05:09 |
|
What are you trying to do and why does that seem like a good solution?
|
# ¿ Feb 25, 2021 15:34 |
|
You get one copy constructor per class. If you want more, you need more classes. This is probably better solved by composition than inheritance.
|
# ¿ Feb 25, 2021 15:51 |
|
I wish I had a better alternative to C++, but that's not happening any time soon. Everything I do is either legacy code where we're just stuck with what we've got, or writing an R package where no other reasonably performant language is really supported.
ultrafilter fucked around with this message at 18:06 on Mar 5, 2021 |
# ¿ Mar 5, 2021 18:01 |
|
Insurrectum posted:Everything's fun and peachy in a compiled language until you have to touch a string Also, yeah, not having to worry about the performance of a loop is great. But having to write loops every time I want to loop over something is extremely tiring. My biggest complaint about C++ is that it forces me to spend a lot of time thinking about things that I don't care about. That's gotten better with the modern standard library but it's still not all the way there yet.
|
# ¿ Mar 5, 2021 21:14 |
|
code:
|
# ¿ Mar 6, 2021 05:14 |
|
Just enforce a rule that heaps are always stack-allocated and stacks are always heap-allocated. You'll never be confused again.
|
# ¿ Mar 7, 2021 23:41 |
|
Just out of curiosity, why do you need to know than an A2 is not an A3?
|
# ¿ Mar 12, 2021 03:31 |
|
I'm going to need to implement an algorithm to compute N(i, j, k) for some function N that I'm defining. The recurrence relation for N is currently written as N(i, j, k) = \sum_c N(i, j - c, k - 1), but I'm not attached to the order of the variables. A straightforward recursive implementation does a lot of duplicate calls, so I want to use dynamic programming. The ranges of i, j and k are constant. What's likely to be the most performant way to implement this?
|
# ¿ Apr 5, 2021 02:10 |
|
rjmccall posted:So i is constant across the recurrence? It looks like you can think of this as a two-dimensional table with j+1 rows and k+1 columns. Conveniently, computation of any particular cell depends directly on values from the immediately preceding column (k-1). That admits an efficient algorithm where you can logically sweep left to right across the table, remembering only the previous column while building up the next. And since each column needs every cell from the previous column, there’s no point in being lazy about any of the cells. i is constant across the recurrence but at the end I need to sum over it. You're right though that I don't need to remember more than the previous value of k, which makes this significantly easier. Xerophyte posted:I'm not entirely sure given how you've written the relation but am I correct in understanding that 0 ≤ c < j when summing? In that case you have something like a summed area table by default and can avoid actually iterating over the previous column, because N(i, j, k) = Σc N(i, j - c, k - 1) = N(i, j - 1, k) + N(i, j, k - 1). That's the correct range but there are some other functions of j and c that go into the sum. I left them out because that doesn't really affect the choice of data structure.
|
# ¿ Apr 5, 2021 19:06 |
|
rjmccall posted:Yeah, as long as the computation trees are totally independent for different values of i, you aren't going to see any benefit from dynamic programming there. No, everything's the same. There's an input of size n and the ranges for i, j and k are computed from that in complicated ways. The key, though, is that the ranges for any one variable only depend on the overall input.
|
# ¿ Apr 5, 2021 20:23 |
|
malloc(n) allocates n bytes of memory. There's no default value for that parameter, so you have to specify something. The sizeof operator is your friend here.
|
# ¿ Apr 9, 2021 20:12 |
|
I really like sequence diagrams for describing how the components of a system interact. We should use them more often.
|
# ¿ Apr 29, 2021 20:23 |
|
What would you pick?
|
# ¿ May 21, 2021 20:27 |
|
They might've just hosed up and set the timeout too low.
|
# ¿ Jul 28, 2021 22:00 |
|
Look into X macros.
|
# ¿ Aug 28, 2021 14:41 |
|
CMake is a high-level scripting language that's used to generate a makefile. On any platform where it's supported, it is absolutely going to be easier to use than an actual platform-specific makefile if you have a project of any real complexity. The learning curve is not entirely gentle, but I think it's worth it.
|
# ¿ Sep 17, 2021 03:59 |
|
CMake is fine and good as long as your script works, but god help you if you need to debug anything.
|
# ¿ Sep 28, 2021 13:44 |
|
|
# ¿ Apr 28, 2024 20:52 |
|
glmnet is probably as close as you're going to get. C++ isn't a terribly popular language for stats outside of the guts of R.
|
# ¿ Nov 16, 2021 04:52 |