New answers tagged

2

Perhaps a list of possible ways a program can hang itself and/or the system would help: CPU overload -- but usually the OS gives other things time slices too, unless you have grabbed real time priority memory overload -- swap can make this better or worse (usually worse); mitigation is to tune your OOM killer or restrict memory use with ulimits or cgroups ...


3

Theoretically, it is the responsibility of the OS to stop any single application from impacting the rest of the system through resource starvation. However, this is a complicated problem and as you have discovered, there are numerous failure cases. The OS should at least be able to minimize the chance of any permanent damage. As such most modern OSes in a ...


0

Already some very good answers here, in particular Helena's. I'd nevertheless would like to add a couple of ideas missing in the other answers. Member function or not? The C++ Core guidelines, recommend: Make a function a member only if it needs direct access to the representation of a class In your specific case, IHittable are shapes, and you need to ...


4

Just write the version that inspires you most. You can always refactor afterwards. The first version has the advantage that it fits the immediate needs. The inconvenience is that it hardwires Application by coupling it to some global objects (hidden dependencies). This reduces the reusability and requires to know about the internals of that class. The ...


4

It depends on your design intention: If ApplicationState and Dimension address different concerns and may evolve due to different reasons, then it is fine. Likewise, if ApplicationState is just there for using a Dimension with another interface/protocol, then it is an adapter and is also fine. If ApplicationState is nothing else than a specialized ...


1

A variant on @gnasher729's suggestion: Insist on signdness of the result type, to allow x.count() - y.count() to not produce junk. ... and thus std::size_t goes out the window. ... and perhaps idx_t too, unless you can rely on its sigendness. Stick to being size_t-like And consequently: using ssize_t = std::make_signed_t<std::size_t>; the signed ...


1

You'll want to consider how the size() function is used. It's likely that template functions (such as those in std::views objects) may call size() and expect it to return an unsigned type. So returning a possibly-signed type could cause compilation to emit warnings you don't want. If it's reasonable for your class to act as a standard container, then it's ...


-1

I’ll just take a signed 64 bit integer. It’s large enough to count the bits on 10,000 large hard drives. Being signed means the difference of two counts is valid, avoiding stupid bugs with unsigned numbers. I haven’t written 32 but code in years, so I don’t worry about some wasted bits.


5

If idx_t is an alias for a standard unsigned integral type, consider using it. But size_t is a perfectly fine default choice that you shouldn't avoid without reason. That collections generally define sizes in terms of size_t is important for generality: by definition, a memory space can contain no more than SIZE_MAX contiguous objects/addresses. This means ...


0

The existing answers already cover the point that the facade contains the minimum of logic, delegating that to other objects; whereas a god object contains that logic itself. However, it's still possible for a facade to be somewhat god-like. A system may have so many methods available that, even with that minimum of logic, the facade is large and has poor ...


4

Based on your post, you completely misunderstand the concept of a facade. There is no compromise to be made so that a facade doesn't become a "God class." To answer your question, you need to understand first what is a facade, or more specifically, what is the purpose of the Facade Pattern. Provide a unified interface to a set of interfaces in a ...


7

A facade contains the absolute minimum amount of business logic necessary to translate from the outer layer to the inner layer(s); if it contains a significant amount of business logic itself, I'd say it's not a facade but something else - but that doesn't necessarily mean it's a "god object" either. With all due respect to your example, I think it'...


0

What you want is not a viable method for protecting anything, even if you could get a particular P2P program to work this way. If you're dealing with a file format that you don't control (images, video files, etc), then your metadata ID would have to be part of that format. Which means it would be trivial to edit it. If you establish a file format (along ...


0

I feel like this is a case of barking up the wrong tree. How about a single function to make everyone happy: Route PlanRoute(Origin, Destination, FuelRange); The people who don't care about fuel simply pass in a maximum integer. If you can't touch the method signature give this version a new name and make the original name just call this one with a maximum ...


Top 50 recent answers are included