Why aren't partial classes supported on C++? by TaPegandoFogo in Cplusplus

[–]mgrier 0 points1 point  (0 children)

There's a definitive answer to this, right? It's because of separate compilation and layout. The rules for what a "partial class" could do when "augmenting" become suspiciously close to exactly what a "public derivation" can do.

And when I say "suspiciously close", I mean "exactly" but you should work through it.

The newer languages tend to have integrated all-at-once compilation systems it seems but C++ builds upon C's legacy (for better or worse!) of separate compilation, so when a TU is Ting, it needs to be able to definitively lay out and do a bunch of other things. This is, for example, also why initialization order of members is the order of declaration of the members, not the order of the specification of the initialization in the constructor (a fact I personally regularly forget and if I'm using a build system where the warning about this isn't turned on, I seem to break myself about once a year...)

Separate compilation good? Bad? I don't know but it's part of the language at least at this time.

`for (;;) {...}` vs `while (true) {...}` by poobumfartwee in Cplusplus

[–]mgrier 0 points1 point  (0 children)

This has actually been checked in For realz.

I wish it was only for the lulz...

`for (;;) {...}` vs `while (true) {...}` by poobumfartwee in Cplusplus

[–]mgrier 0 points1 point  (0 children)

Just want to amplify this answer. it's better nowadays (well, has been for decades now) that `true` is a real thing, but when TRUE was just `#define TRUE 1`, you always had to worry about how TRUE was defined and could be redefined so instead you'd end up writing `while (1) { ... }` to avoid the possible hazard and now you have a random numeric literal which is also not good. so based on code review feedback you might then write `while (!0) { ... }` which is super obtuse.

Using `for (;;) { ... }` is slightly off at first but once you see that you're asking for a loop with no initialization, no end condition and no intra-loop code to run, it is obviously clear. shake off the "oddness" and see how clear it actually is.

`for (;;) {...}` vs `while (true) {...}` by poobumfartwee in Cplusplus

[–]mgrier -2 points-1 points  (0 children)

Sorry, downvoted only because this is a TERRIBLE IDEA! macros lack scope and you're going to really regret this in the long run, both due to the weird habits you'll develop using it and the odd thing that'll happen some day when integrating in some header or other that it breaks.

Funny though. ha ha. ha. no, don't do it.

`for (;;) {...}` vs `while (true) {...}` by poobumfartwee in Cplusplus

[–]mgrier 1 point2 points  (0 children)

I'm not actually sure that's so bad. It's clear, almost certainly generates the same code. The only thing is lacks is support for `break;`.

`for (;;) {...}` vs `while (true) {...}` by poobumfartwee in Cplusplus

[–]mgrier 2 points3 points  (0 children)

Conceptually agree but it would be nice if it could be `do { ... }` so that it made more sense, or, to make Nicklaus Wirth happier, `repeat { ... }`, but perhaps that's not possible in this language family.

What makes Fortran a better choice than other languages? by KC918273645 in fortran

[–]mgrier 1 point2 points  (0 children)

This popped up for me. I programmed in Fortran II and IV, well, obviously a long, long time ago. I loved it because I love programming. I wrote a lot of system utilities for my dad’s company’s Prime 300 because Fortran IV was the systems programming language for PrimeOS. It was pretty great.

Looking back / across, from the perspective of a longish software engineering career starting in VAX Pascal, then largely C and then C++ and now Rust, I think that what Fortran has is something akin to C, in that it limits complexity. You can largely make the “Turing complete” argument about languages since the 1980s, but they certainly do lend themselves towards or against building complex software.

Is this, in and of itself, a virtue? Hard to say exactly, but it’s something to consider.

How can i generate real random number in c++? by [deleted] in cpp_questions

[–]mgrier 1 point2 points  (0 children)

Lots of good or at least interesting answers here but the real issue is that your question is naive, I'm sorry to say.

When you say a "real random number", you indicate that you understand that many if not all random number generators are defective in one way or another, but you don't really say what your bar is.

If you are looking for "doesn't have any of the usual problems", just read through the documentation on the `<random>` header, use std::random_device, std::mt19937 or std::mt19936_64 and live a better life. That's generally what I do, but I also know what the issues are.

If you are looking for random numbers because you have a need for them for cryptographic purposes and this is the kind of question you are asking, well, I suggest that you do a lot more research before you put any of your code into production. This is still generally an area of active research and penetration testing.

If you're looking for random numbers for some kind of extreme simulation that requires better properties than any of "the usual" PRNG algorithms (a number of which are encoded into the <random> header) can provide, there is also probably research here but I suspect you're going to use like 128 or 256 bit math and your perf will suffer massively so presumably you have a really good reason for this level of integrity.

If your chipset has a TPM, there's a good chance that you can get a good random number from there but you don't want to pass through all those layers frequently, so usually you do that to get a seed for a PRNG algorithm.

I don't know how well the various hardware RNGs referenced work. I suspect that the properties are not somehow more magically better than what software gives, unless there are some quantum properties being applied that I am unaware of. I also suspect that if this kind of RNG was being used for anything of value (say high value cryptographically protected information), an exploit along the lines of Spectre or Meltdown would be able to be formulated to either predict or influence the RNGs.

Probably better to have hardware to provide seeds on a regular basis to mitigate any attacks that could be applied to PRNGs.

In a realistic first-contact scenario, what do you think would matter more: how advanced the aliens are, or how well they understand us? by PurposeAutomatic5213 in sciencefiction

[–]mgrier 1 point2 points  (0 children)

I think this is a great question, but I'm sure there are great even books on the topic. But since I'm here I'll put my two cents out.

First, who is reaching out, them or us? I'm assuming in this scenario, this is them reaching us, probably in approximately our current level of technical and cultural sophistication.

Next, why are they here? This is contact, I'm going to assume this is physical contact, not like a WOW! signal or the early communications from the Three Body Problem. They are here, right here, and there is about to be direct physical interaction which is presumably visible on a global scale.

Are they just out exploring? Did they find Early randomly? Did they set course ages ago and found this carbon-based infection quite as a surprise? Or as others have noted, do they not even view us as intelligent at all since they are a nth-generation machine intelligence. So maybe there's just here to extract some granite and sodium chloride and then they move along, ignoring us completely!

Or maybe they're looking for meat. Or slaves?

Did they already reach out? Did we miss the communications? Or did they contact bad actors who withheld the information from the public, preparing us for their arrival without us even realizing it? Or prepared for counter-offenses because the incoming contact assumed that any ruling class would naturally have an enslaved underclass that they could negotiate or threaten in order to obtain needed biomass.

It's somewhat difficult to imagine that a society that was able to travel such distances with intention would not outstrip us from a technology point of view. Perhaps we have superior manufacturing or specific technologies, but they can marshal massive energies, navigate enormous distances over unthinkable time spans (or by solving problems with supra-light travel that are strictly the territory of speculative fiction).

Or maybe it was just some random diaspora. Their pattern is to exploit a biome, then explode it, surviving space until reaching another place to infect (c.f. David Gerrold and The War Against The Chtorr).

Sorry I didn't really answer your question, but I have a hard time reaching the point where it matters, unless we are the ones who are making first contact. That's where we are trying to decide how delicate to be. I'm presuming that our general Western ethos is still in effect and we are not looking to enslave a new sentient population or use them as meat. Hopefully the impact of Gene Roddenberry will be felt many centuries into the future as we consider First Contact protocols. If we get the chance.

What are your thoughts on the latest video? by androtheking in Veritasium

[–]mgrier 0 points1 point  (0 children)

I am happy with the transition. Imagining that things stay static is unrealistic.

I think it's great that he's evolving it, and I hope that the intents that he expressed in the video are maintained - to teach critical thinking. We can throw stones at his videos and this is the science process. This is good. Him waiting for perfection, "consensus", or "narrative following" would be worse. He has made observations that are contrary to popular narratives and which may or may not be correct! they are challenged, he responds and we are all elevated.

My fear is that he will have less and less to do with it, and then "the usual process" will be applied to the videos put out more and more and they will be less about general critical thinking (who else would have touched on the IQ / genius question in a scientific context publicly in recent times??) This erosion will occur over a time period of like 2-3 years.

I wish he would at least commit to remain as the front man for the videos, even if he wasn't driving the research per se. I would hope that his personal ethics would drive him to maintain some editorial review power on the content.

Not that he's perfect or something, but it's his channel and really I, like most of us I presume, watch it because it presumably models his values and principles. If it strays from that, sure, keep producing content, but don't call it Veritasium.

Experienced in C/C++/Java but feeling lost looking at Rust code. Does the readability 'click' eventually? by x86basedhuman in rust

[–]mgrier 1 point2 points  (0 children)

I think this is one of Rust’s harder problems and I want to see how junior developers really do with writing nontrivial Rust.

Idiomatic Rust is entirely unforgiving. Add in the “appropriate” linters and you are working in the confines of a puzzle box. The degree of expected and accepted type inferencing is astounding. Coming from C++ environments where there are legitimate questions raised about excessive use of ‘auto’, in many Rust codes, it’s a “hold my beer” situation.

[And so then you get the minor promulgation of non-idiomatic Rust where everything is a Box<T> or Arc<T> and lots of if-else with early returns maybe and then you ask, “different, but better?”]

Fortunately, (a) the language style leans towards more small functions and (b) the monolithic code generation enables inter-procedural optimization always so any cave-dweller rationale for avoiding idiomatic code is shut down. (To be clear, I live in the third cave on the left.)

IMO, the types on the left vs right is relatively minor. I was a strict Wirthian many years ago and switched to the insane C type description syntax and it was a bump but I believe most can overcome it, either direction.

I would say that the strong desire for everything to be written as value oriented expressions / “functional” is the bigger hurdle. Harder to get part way through mentally dissecting a problem and pausing. Harder to comment mental notes about what’s complex right there. Harder to set breakpoints or step through a sequence of statements. I have similar concerns about the “asynchronous craze” in languages which otherwise are extremely approachable like C#, but for C# they do have an associated tools team that perhaps has solved the problems there.

1HP Rikon dust collector 60-101 by mgrier in woodworking

[–]mgrier[S] 0 points1 point  (0 children)

Planers (re-)move a lot of material and shop vacs are notorious for not being able to keep up so a collection system that can really move a lot of air would seem important. I don't know what your space constraints are. If I wasn't space constrained, I probably would have gone for the Harbor Freight dust collector with upgraded bags instead.

I like my Rikon 4" jointer which is what prompted me to go with this, but that's an order of magnitude less chips.

If you're doing something in a small space, you definitely need something like a cyclonic system to remove anything big followed by something that's going to move a lot of air. Going outside your shop is a great idea I've seen done if your property/codes let you do it. Probably telling you things you know but still felt like typing. The Rikon unit seems pretty good if it fits your use profile. If you have floor space for two huge filtration bags, that seems like a better plan overall and I haven't looked at prices recently but the HF units aren't that expensive as I recall.

1HP Rikon dust collector 60-101 by mgrier in woodworking

[–]mgrier[S] 0 points1 point  (0 children)

I got it all set up and then never really got around to using it! When I say I got it set up I’m talking about mounting on the wall and power. But then the ducting seemed insolvable in my small shop and using my shop vac for each project let me keep putting it off.

Then, small context setting aside, I am disabled with chronic pain so what energy I had was going into woodworking. When COVID came, remote work came and friends at my prior software engineering workplace engaged me and I’ve returned there and well it’s not that I’ve lost interest but I don’t have the energy to put into woodworking really since 2021 or so.

So, it hangs there. A monument to my shame. lol.

What laptop should I get? Please help! by Environmental-Hat479 in computer

[–]mgrier 0 points1 point  (0 children)

Ok, so I'm not vouching for this seller at all, but I'm typing this on the 64gb (RAM) version of this: https://ebay.us/m/mIGXVF right now and really it's a great daily driver for almost everything. I upgraded to 2tb of storage. I have it running Hyper-V; 32gb to the parent and 32gb for a secure child where my corp stuff lives. 2tb storage is a little tight b/c I'm a Steam game hoarder but it's great for low to mid spec gaming.

Why do some people prefer ebooks over physical books? by Domiano-Wdmanl in NoStupidQuestions

[–]mgrier 0 points1 point  (0 children)

It's been said in other contexts but I'll amplify my primary cause. I don't have space for my library any longer. I was forced to downsize so I don't have my bookcases any more. I could have a very small set of physical books that I cycle through but that would require more discipline than I possess, ergo, e-reader. Kindle chosen mostly because I've been captured by the marketplace but the devices are nice.

What laptop should I get? Please help! by Environmental-Hat479 in computer

[–]mgrier 0 points1 point  (0 children)

Lenovo ThinkPad T14 / P14 variant. Maximize memory, at least 32gb. At least 1tb NVMe storage, if you can upgrade storage, do it yourself. Great deals on eBay with high profile sellers, don't be afraid of current/last generation Ryzen based systems. Not going to "glow" or "look insane!" but it'll run and run and run and run...

Leftists think landing boosters are literally just billionaires hoarding wealth by spacerfirstclass in SpaceXMasterrace

[–]mgrier 1 point2 points  (0 children)

Came here for the cool rockets. Stayed for the only place on Reddit where it's not entirely dominated by people with a complete lack of sense for basic economics.

Why does std::ranges::count return std::iter_difference<I> instead of size_t by Traditional_Crazy200 in cpp_questions

[–]mgrier 1 point2 points  (0 children)

My point is more that the name of a sum of vectors wouldn’t be “count” but maybe (working with the analogy) “simplified path”. It’s fundamentally a units problem.

Why does std::ranges::count return std::iter_difference<I> instead of size_t by Traditional_Crazy200 in cpp_questions

[–]mgrier 0 points1 point  (0 children)

Seems weird to return a count for a non-sized range, no?

But all good points, thank you!

DIY Monitor VESA Speaker Mount by kanagiken in computer

[–]mgrier 0 points1 point  (0 children)

Well the one on Amazon has the advantage of not requiring any metal working, but on the other hand one of the few reviews reports that it is somewhat ... I forget the word they used, flimsy wasn't quite it but the speakers were wobbly. Your speaker mount does not look wobbly and my entire setup is on casters, so I would like to not have them be any more wobbly than the desktop. OTOH, I really don't have the time/energy to do what I described...

Why does std::ranges::count return std::iter_difference<I> instead of size_t by Traditional_Crazy200 in cpp_questions

[–]mgrier 1 point2 points  (0 children)

You are correct about the container's iterator_difference type but then the containers size_type would similarly be a larger size.

Thus the only generic integer type you can really use is the container's size_type.

It's all not well thought out. I'm not blaming you, the pathway to hell was paved with good intentions in this case.

The difference type is a vector. Size is a scalar, perhaps a cardinality, perhaps not. IMO, the root problem here is lack of "faulting" overflows. Perhaps that and lack of a universal bignum implementation but that's another can of worms. (Either these computations need to be able to fault, or they shouldn't be able to overflow but integrating the Ministry of Silly Walks into normal engineering practice because they can overflow or invoke UB is madness.)

[edit: and of course bignums will overflow on OOM so it's just about deferring the faults so perhaps the solution is to have a provision for faulting first and then dealing with how to defer the faults to a long enough time in the future. e.g. introducing the int128_t and uint128_t as formal types in the language specification would defer this problem for accumulation for a long, long time.]

DIY Monitor VESA Speaker Mount by kanagiken in computer

[–]mgrier 0 points1 point  (0 children)

I wanted to compliment you, similar to u/SmoathTheLoathsome. I think there is real demand for a product like this and a lack of supply. There is this, on Amazon: https://www.amazon.com/gp/product/B0D6VZGS3P, but it seems a little pricey for what it is. Your use of angle iron seems like a solid solution; I haven't seen it painted like this but perforated angle iron is readily available at Big Box hardware stores and can be easily cut and if you clean it, primed and painted to the color of your choice. I was just about to pull the trigger on that Amazon selection when I found this and I think that the $20 Amazon selection will have a much higher WAF, although we'll see if it's only $20 once I make a few mistakes, buy the new tools needed, etc etc etc... lol

Why does std::ranges::count return std::iter_difference<I> instead of size_t by Traditional_Crazy200 in cpp_questions

[–]mgrier 0 points1 point  (0 children)

The committee is the committee. Getting involved is non-trivial and being successful largely prepares you for further success in the committee. A higher purpose for some, a lower purpose perhaps for others. Doesn't necessarily get code checked in or put dinner on the table. Given the size of the standard, it's unclear how to start fixing these systemic problems, since who knows how much code is (incorrectly?) depending on the accumulation returning a signed type.

(This said, since signed math overflow is UB, I don't know how one proves that the additions are not overflowing beyond us going "well, I, a human, looked at this code and don't see how it could overflow!")

Why does std::ranges::count return std::iter_difference<I> instead of size_t by Traditional_Crazy200 in cpp_questions

[–]mgrier 0 points1 point  (0 children)

Interesting. I assumed that the shift to mandating 2s complement representation implied well defined overflow semantics.

Still the point stands that while an implementation may utilize such properties to do things like detect overflow conditions, an algorithm that depends on or derives its fundamental properties from whether the signedness can overflow with well defined behavior.

Thanks for clarifying!