Hot answers tagged

10

In his book "The design and the evolution of C++", Bjarne Stroustrup explains it himself: The very first version of the language was called "C with classes". Stroustrup's intent was to introduce Simula-like classes into C (October 1979). (page 27 of the book) From the start he wanted public/private access control and derived classes (no virtual ...


4

This is hard to answer in isolation. A lot depends on the overall design of your language and the goals you want to reach. To quote Bjarne Stroustrup quoting Dennis Ritchie: “There are two kinds of programming languages: The ones that want to solve a problem and the ones that want to prove a point.” Which of the two is yours? What problem do your future ...


3

HAL Hardware Abstraction Layer. It is a big part of the Windows OS (with similar analogues in most OSes) which has to interface with many different CPUs, Motherboards, an other periphery devices. This layer augments the underlying hardware so that each of these things looks identical on the outside. Where the the hardware falls short of providing the ...


3

It's probably safe to assume that most platforms support IEEE floats. That implies that you don't care about the other platforms. It will be mainly embedded systems that won't have an IEEE-compliant floating point maths processor. Floats can suffer from endianness problems just like integers. Make sure that you define what endianness you are using (big ...


3

You can check std::numeric_limits<float>::is_iec559 and fail to compile for platforms that use other representation


3

If you declare the array as static within a function, that is not declaring memory "on the fly". When declaring a variable within a function or class as static, that means that you will have only one copy of that variable which will be shared between all calls to that function or all instances of that class. A dedicated memory location is reserved ...


3

I think you're well into YAGNI territory here. When you know what your second library looks like, then is the time to look at the abstractions it exposes, compare those with the abstractions from SFML and only then make some decisions as to what your wrapper should look like. Otherwise you are just guessing what you think the common abstractions are, and at ...


2

Like what are the best practices to deploy software with many bash scripts? Given you refer to /usr/local/lib and /usr/local/bin, I'm assuming you're on some kind of Unix-ish machine - there, the answer is simple: use the OS's package manager. Build a .deb/.rpm or whatever and use the infrastructure which already exists.


2

Equality is all about semantics: what does it mean that two C objects are equal? That all values of all its attributes are the same? Or can we ignore some mutable attributes in the comparison? What about references to other objects: must they be identical or is it sufficient that the value of the objects referred to is the same? Or do we just look at the ...


2

Usually in such complex situations you aren't looking for the object to have strictly not changed, just that it has behaviourly returned to the state prior to the call. Configuration is like a mini-language, controlling the function/object being used. Comparing the configuration prior/after a call is a good way to detect many state changes. Another useful ...


2

There are no shortage of complaints about throwing and catching both within the same method.  These are considered a form of goto, considered harmful. Throwing an exception when we don't want to proceed — e.g. with parsing — is different and is reasonable usage of exceptions. However, in your code you might abstract the exceptions a bit by ...


2

Avoiding Leakage To avoid leakage, wrap everything that is exposed. Create wrapper classes until you only expose basic types. This means you will have to come up with an abstraction not only for each class, but for all concepts of SFML. In your example you are wrapping 1:1, i. e. each class in SFML is wrapped to one class of your wrapper: sf::Drawable is ...


2

Is there a standard way to parse and implement these options? Yes, there is. Along the Posix Standard there's the getopts() function you can use to do the parsing. Regarding the c++ standard there aren't any libraries to support command line arguments parsing. Though there's boost::program_options you can use to make it easier to define and parse any kind ...


2

For creating the objects, you could make a factory object, but in the end that's still going to have the same switch statement you currently have, just in a different object. Swings and roundabouts. However, that's not going to fix this: i think you can imagine the ugly code in other section of code which depend of type of objects. I can imagine what ...


2

The problem is that const applied to the type of a variable means immutable (equivalent: readonly+no_mutable_references (C restrict pointers satisfy the latter)) in C++, but if you take a reference, it means readonly. If you add immutable to the type-system, you will no longer have to throw immutable and readonly together when passing it on, and knowing the ...


2

Two years later, I'll add an answer myself. This purely reflects my own experience, but might help others in the same situation. Due to cross-platform availability, I didn't move to C#/WPF but rather to JavaFX. I have approx. finished porting 40% of the whole the application and so far I heavily regret that I didn't port the whole thing way earlier. Or in ...


1

I am thinking to design as below, Create a class named Phone which contains 2 types of objects. one basic properties and other is advanced properties. BasicProperties class contains all the properties without which we can not call phone.(OS type, screen size, RAM size, battery level,sim card support). These will be common among all the phones and these ...


1

You already got a good answer, but let me focus on this question of yours: How should I design by following Open-close principle The answer is: you don't. The OCP is not an end in itself, it is a means to an end. It would make sense if you are a framework designer who wants to provide a generic library for other developers who buy this closed-source lib ...


1

From what I get, you are torn between 2 possible ways to implement the same idea. Separated classes for const and mutable wrappers over the same interface. Reader/Writer approach where you separate the ability to write on fields with different interface classes. From a performance perspective I expect similar results so the choice is purely aesthetical. ...


1

I would prefer the second option. It is similar to iterator and const_iterator types provided by containers. Your wariness about constness of the wrapper is equally applicable to iterators and pointers. You can have mutable_record_wrapper inherit const_record_wrapper, which removes some of the boilerplate. class const_record_wrapper : public ...


1

Because it would be C otherwise. That C++ evolved from the so called "C with Classes" is telling. As per Stroustrup motivation to add classes to C... Stroustrup was working in a distributed system simulator, for which he was interested in modularity and concurrency. According to Stroustrup, the initial version was developed in Simula, from where he took the ...


1

Exceptions should be used for exceptional cases. A parse error is not exceptional; an input that can be parsed correctly is probably more exceptional: -(


1

The following does not apply to jagged arrays: Any of the following C expressions can be l-value expressions: A subscript ([ ]) expression that does not evaluate to an array A jagged array is an approach to a two-dimensional data structure that allows for varying the 2nd dimension between positions of the 1st dimension.  ...


1

I, too, have a preference for regular types and value semantics. But I don't encode preferences into unit tests. Unit tests exist to enforce the requirements. Very occasionally, the best way to do something could be precluded by one of these preferences, so it's important that unit tests don't appear to create unnecessary implementation constraints. ...


1

The only way to guarantee that no DRAM gets used by your program is to make sure that the computer running your program uses some other kind of RAM modules. Unless you have a severely underpowered processor in your system, such that 100% CPU time is required to copy bytes between modules on the PCIe bus, your program will spend part of the time waiting for ...


Only top voted, non community-wiki answers of a minimum length are eligible