Jump to content
  • Advertisement

Nitage

Member
  • Content Count

    1503
  • Joined

  • Last visited

Everything posted by Nitage

  1. Nitage

    Criticism of C++

      I couldn't disagree more with that line of argument. A very common weakness of GC'd languages is a lack of robust facilities for managing resources other than memory. In my opinion, RAII is the gold standard for resources management.
  2.   As a general principle: where the option exists to use functionality that's been written by domain experts and has been extensively tested in the real world, you should strongly prefer that over your own code.
  3. Nitage

    C++ dynamic_cast

      Am I missing something here? A pointer/reference to a derived class should implicitly convert to a pointer/reference to a base class, so a simple assignment should do and dynamic_cast isn't necessary.
  4.   You listed some requirements in your original post. The purpose of switching language is to satisfy those requirements, nothing more.   So the real question is why would you not switch to a language that meets your requirements only because that language offers other functionality that you don't intend on using?
  5. I like Ada's version, where the header contains only the interface. Not so much the C/C++ version where the decision of what goes into the header file isn't logical, but is instead a consequence of technical details regarding translation units.
  6.   I'm not going to say that you're crazy, but what you're doing is throwing out good solutions because they aren't perfect.   Almost everything you've asked for can be achieved by using C compiled as C++ with a few whitelisted C++ features. For example, your issue with member function pointers not being automatically tied to an object instance can be solved by using a template function that uses `std::bind` internally. You can then ban all other uses of template functions or std::bind, or any of the other C++ features you dislike. Basically, it seems you want C with a bit of extra syntactic sugar. You can get that from C++.   The same goes for Go, D and Rust - any one of them meets your basic requirements. It seems like you're just seeking out reasons not to use them rather than having genuine requirements that preclude their use.     If that's true - that this "flaw" kept you from even considering C++ - then you've made a mistake. Your statement that you "Cannot set a callback on a member function"and that it's "impossible in the base C++ language" is just false and you've thrown out a potential solution due to a misconception.
  7. Nitage

    D language enum question

    That's an anonymous enum with a single member which is an array of arrays of strings.   Its C++ equivalent is:   constexpr const char* logTypes[2][2] = {   {"red"       , "color"},   {"blue"       , "color2"}, };
  8. Nitage

    C++ compile times

    The dominating reason for slow times is the preprocessor, no question. The preprocessors #include directive can mean compiling a 100 line file requires processing several orders of magnitude more code, and #if... directives make it very hard to cache the results of processing a file. There are also other issues; C++ compilers do more than C# ones. Some parts of C# compilation are deferred until runtime (JIT) and the Microsoft C# compiler doesn't optimize nearly as aggressively as their C++ compiler or g++. For example, it doesn't ever perform tail call optimization (there's a IL 'tail' instruction which the F# compiler emits, but the C# one doesn't). This is minor in comparison to the preprocessor issue though.
  9. i = j * 5; … in C you know, at least, that j is being multiplied by five and the results stored in i. But if you see that same snippet of code in C++, you don’t know anything. Nothing.... [/quote] I've read the Joel article several times before and have never found it convincing. The alternative to operator overloading for 'j *5;' is 'multiply(j,5);'. Now, if you write a binary operator* that doesn't multiply you are an idiot, but no more of an idiot than if you'd written a function called 'multiply' that doesn't multiply.
  10. You don't need to use the ref keyword at all, seeing as you're not assigning to the bne parameter. Also, keep in mind that in C# parameters of a class type are automatically passed by reference and using the ref keyword creates a reference to a reference.
  11. Nitage

    c++: std::erase, std::unique

    Ok, so what's the solution? Iterate each element and do erase+unique?[/quote] [color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif]No, just use the two parameter version of erase.[/font] [color=#000000]myFullHair.erase(std::unique(myFullHair.begin(), myFullHair.end(), compareMat),myFullHair.end());
  12. Nitage

    comparing company names

    It's relatively simple to match a string against a predefined set of synonyms. If you are aiming to do this procedurally (i.e. by guessing which strings are synonymous) then you're on a fools' errand.
  13. High quality, clean, well tested and documented code can gain value very quickly. ... So in conclusion, yes I think that easy decompilation is a major concern with managed languages. There is no perfect solution to this problem as of yet (at least not as good as native compilation, which makes code reuse almost impossible). The minimum for any serious project should be obfuscation. [/quote] I agree that high quality code accompanied by good tests and documentation can be valuable - but as decompilation provides neither tests nor documentation, I don't view it as a problem.
  14. [color=#1C2837][size=2][/quote][color=#1C2837][size=2]Halving your productivity but preventing someone from taking your distribution verbatim, reverse engineering it (automated) and releasing their own modified version in 2 hours is a good trade-off.[/quote] [color=#1C2837][size=2] [color=#1C2837][size=2]That depends. If you're halving your productivity to prevent someone from ever reverse engineering your code then it may be a good trade off. [color=#1C2837][size=2]If you're halving your productivity to increase the time taken to reverse engineer your code from 2 hours to 8 hours, then it's likely not. [color=#1C2837][size=2] [color="#1c2837"]Like DRM, obfuscation merely increases the effort an attacker has to put in - and like DRM it's mathematically flawed and requires orders of magnitude more effort to implement than to break.
  15. Nitage

    Help with optimizations

    The best algorithmic complexity you can achieve is O(n) space, O(n) time (a counting sort). If you want O(1) space you'll have to settle for O(nlogn) time (an inplace O(nlogn) comparison sort). The fastest way depends on the size of your data set and the implementations of the contained types copy constructors, move constructors and swap functions.
  16. Nitage

    best c++ foreach macro?

    So... #if ... Visual Studio # define for_each for each #else # define for_each for # define in : #endif for_each(auto& val in container) { ... } I feel dirty even writing that.
  17. Nitage

    qsort array of pointers

    Your comparison function contains an integer truncation - is the PercentComplete variable always between 0.f and 1.0f?
  18. Nitage

    Dynamic casting in python

    No you can't. Using dynamic_cast to convert to void* is allowed, dynamic_casting of a void* is not - as is specifed in the section of the standard you cited.
  19. Nitage

    Dynamic casting in python

    You can't dynamic cast a void*.
  20. Nitage

    #pragma once vs #ifndef

    The idea is that the compiler can load the file into RAM and once it sees #pragma once it can stop there and go check if it has been included already. Whereas for the traditional way it has to parse the file looking for matching compiler directives until it finds the correct terminating #endif at the bottom.[/quote] That's wrong. The speed gain attained by the optimization is due to the fact that the file doesn't have to be opened a second time. It's the file access, not the parsing, that is the performance problem. Parsing takes a trivial amount of time compared to file I/O. The optimization works like this (pseduo code) [html] FOR EACH translation unit FOR EACH #include directive encountered IF the file is in the set of "#pragma once" files OR the file is in the set of files with include guards and the relevent preprocessor symbol is still defined: We're finished processing the include (no need to open the file at all) ELSE: Process the file If the file contained a pragma once, add it to the set of "#pragma once" files If the file contained an include guard add it to the set of files with include guards, along with the record of the relevent preprocessor symbol [/html] The important things to note are: * The optimization works just as well with #pragma once as it does with include guards - it's slightly easier to implement with #pragma once, which is why the #pragma once optimization precedes the optimization being applied to normal include guards. * An #include directive does not require the included file to be opened and read a second time, cutting down on file IO.
  21. Nitage

    #pragma once vs #ifndef

    IMO you should use "#pragma once" first (due to it being a compiler optimisation)[/quote] Is it an optimisation though? Last time I investigated, MSVC was just as fast with portable scope guards as it was with #pragma once. I presume they accomplish that by applying the same optimization to scope guards as they do to #pragma once (it's essentially the same, with the additional detail that you have to store a mapping of file paths to scope guard names rather than just file paths - but it isn't tricky).
  22. Calendario * cal = new Calendario(10, 5); ... Calendario * calsum = cal + 2; You're never invoking your overloaded operator - you're doing pointer aritmetic.
  23. * You could add the __cdecl keyword to the functions in the header. * You could wrap the library so that the header is only included in a single translation unit which doesn't use __fastcall as the default. I appreciate that neither option is especially practical, but I can't hink of any other way.
  24. Arbitrarily throwing simply doesn't make sense - you cannot write exception safe code without relying on no-throw code, and forcing an exception to jump threads means that no code is no-throw. For example... Quote:(Of course, the user probably should have used RAII for the lock, but in this case they got lazy for whatever reason). What if they'd used RAII and the exception occurs during the destructor?
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!