New answers tagged

0

First off, keep in mind that GUI structure (e.g., for rendering) generally doesn't match the logical structure of what the program itself does. For example, if you have a list of items in your GUI, you presumably also have some logical component in your program that gives that list some sort of semantics within the program. The reason that the user adds an ...


0

The cleanest approach is to use the signal handler to alter the path that execution takes. It doesn't necessarily need to be a termination point. (Although it probably should be for things like SIGSEGV.) Graceful termination requires that you account for when exactly it's safe to redirect execution, and that requires knowing what the process is doing at the ...


2

Unless you're using a really old compiler, or working really hard at turning off all possible optimization, returning the value will normally be at least as efficient, and sometimes (often?) more efficient. C++ has allowed what are called Return Value Optimization (RVO) and Named Return Value Optimization (NRVO) since it was first standardized in 1998 (and ...


1

Both templates and the factory pattern are not suited for that purpose. If you only have two different types of data structures in your program and don't plan on adding more soon, you shouldn't worry about generalizing because the simplest solution is best.


1

As you discovered, you'll have to have some degree of code duplication with respect to the class definitions. Once you start getting logic involved, though, I recommend that you write that logic in the C++ part of your codebase and compile it into a native DLL (not a managed DLL). Native DLLs have the advantage of being accessible from almost every language ...


0

Can't comment yet because I don't have 50 Rep yet, so I have also included some questions in my response. Restating main task : Problem is, if we wish to lift some logic into the API libraries like validation, the parse and generate method complexity increases exponentially, especially through diverse languages like c++, c# and js. First solution : Write ...


3

Because having serialize_int and serialize_float and serialize_user and an almost infinite number of variants that only add uniqueness noise because the language won’t let programmers express what they really want to is its own source of errors. The days of Java School OO hammers is much diminished. Even in functional style programming, overloading (and ...


2

The signal doesn't terminate your program. It would be nice though if your program took the hint and shutdown. You have a done variable controlling your run loop. Perhaps you could elevate it to global scope, or introduce a special global flag just for monitoring if you've received a terminate signal. When your next loop happens it will exit naturally.


0

You shouldn't have a set of ConcreteClass, you should use a set of AbstractClass and use the heap (new/delete).


1

There is still a cost to having precomputed bitmasks in that it fills up cache. Memory is SSSSOOOOOOO SSSSSSSLLLLLOOOOOOOOOWWWWWWWWWWWW by comparison, so it might just turn out to be faster to compute these bitmaps on the fly. But lets say you've done the due diligence. How about compile-time functions. This allows you to be specific about the logic, and ...


4

Is it important? It is good to have those details in mind but is it really important right now in your development to know if a string will be allocated or not and if it will be a bottleneck for your application? If yes, try both and measure. Chance are the difference is either minimal (compare to other algorithm issues) or null. If there really is a ...


2

Am I missing something here? The as-if rule means that an implementation may treat both cases the same. In the cases where you don't need to enlarge encoded in the second case, the allocator can easily re-use the same bytes. Otherwise both cases have to allocate a larger block. I believe that performance won't be an issue Is there some other way to get the ...


3

An ADT has an interface, but they are not the same thing. For example, Objects are fundamentally different from ADTs (see for example On Understanding Data Abstraction, Revisited by William R. Cook for a simple explanation), but they also have interfaces. Also, a single ADT (or a single Object) can have multiple interfaces, for example, a List ADT can be ...


1

An abstract data type is just that, abstract. It supports some operations and might give an idea of their complexity, but that's it already. The exact details are not at this level, they would obscure the important things. All those details, namely how the operations are accessed and what they do (arguments, their ranges and types, name, preconditions, ...


0

In C or C++, the Standard defines the behavior of something like: int read_int(int *p) { return *p; } as "If p is a pointer to an object whose effective type (for C) or dynamic type (for C++) is int, then return the value of that int object. Otherwise behave in any fashion the implementation sees fit. Many implementations however, at least if suitably ...


0

You are abstracting at the wrong level of detail. All code that renders or needs to manage drawings of some kind is by its very nature Graphical. It will have a graphical language of some sort be that this library, or that library etc... When you change graphics libraries you will doubtlessly need to change these graphical classes too. Unless of course the ...


4

Mostly it's not the language itself but the implementations. For embedded programming where the ultimate control is required, there is absolutely nothing that requires processors to have registers mapped to memory addresses, and C++ standard is pretty explicit that memory space does not need to be flat and while pointers can be converted to integers and back,...


67

Can you give an example of things you can do with C++ but not with python. Sure. For instance, C++ gives you control over where objects are placed in memory. The programmer decides whether an object is stored on the stack or the heap - and can even control where on the heap by using a custom allocator. This can be helpful when exploiting memory locality ...


51

It is clear that C++ is much more efficient and that the C++ code compiles directly to machine code whereas in Python it is interpreted. This is wrong. C++ and Python are programming languages. A programming language is an abstract set of mathematical rules and restrictions. It is neither compiled nor interpreted. It just is. Any language can be implemented ...


8

Language comparisons are always source of heated discussion and painful confusions. Giving "more control" does not mean anything by itself: Both languages have very similar control flows. Python being a dynamic language, it allows to change control at runtime and even trick the inheritance tree: is it more control because C++ doesn't allow it? Or ...


1

Most C++ compilers have an option that can be used to enable a warning every time a returned value is ignored. For instance, in g++ you can use -Wunused-result to get these warnings. The [[nodiscard]] attribute has been added to allow a middle ground between always producing a warning and never producing one, which is why most descriptions of how to use it ...


Top 50 recent answers are included