Slavik81

Member
  • Content count

    153
  • Joined

  • Last visited

Community Reputation

360 Neutral

About Slavik81

  • Rank
    Member
  1. Why is it difficult to create a completely new, independent class in Java? Personally, I think you'd be better off making it simpler to create new classes than developing techniques to work around how troublesome it is.
  2. [quote name='Servant of the Lord' timestamp='1350576009' post='4991459'] I [i]think[/i] it mentions it (and gives pros and cons) in CodeComplete where it's not really arguing for it's use but just presenting it as something that's sometimes done. I've tried it a little, and then decided to dismiss it from my own coding - I also don't often mistype = for ==, but maybe if I was switching between multiple languages and had a compiler that doesn't issue a good warning for that mistake, it might be worth doing. [/quote] Yoda conditionals are a particular annoyance to me. They're less readable, and are not very useful if you write good tests. More dangerous is accidentally forgetting to break at the end of a case in a switch. It's rare to test for things that you don't do, so a case that falls through and does something extra might not be caught.
  3. [quote name='mrbastard' timestamp='1349374702' post='4986828'] [quote name='Bregma' timestamp='1349356831' post='4986749'] If there is a compiler that does not issue a warning when you put initializers out of order, you should switch to one that does. [/quote] FYI Visual c++ 2012 does not issue a warning about this with /wall (and 'language extensions' disabled fwiw). I know gcc does, and I agree that it's a useful warning. [/quote] Yeah, msvc is the only compiler I know of that doesn't support that warning. For gcc, clang and intel, the flag is -Wreorder. [url="http://visualstudio.uservoice.com/forums/121579-visual-studio/suggestions/2553854-c-compiler-should-warn-about-wrong-member-initia"]You could vote for it if you want Microsoft to add it.[/url]
  4. SFINAE equivalent in C#?

    [quote name='krippy2k8' timestamp='1348996241' post='4985300']It seems it would be a pretty silly tradeoff to disallow template specializations in order to allow implicit template type conversions, particularly when the solution to your original problem is so simple: [CODE] template<typename ContainerT> void function(const ContainerT&){} [/CODE] [/quote] That would be a reasonable solution if it did not have such a dramatic impact on compilation time, and if it did not require major workarounds to apply to virtual functions. There are definite advantages to the restrictions C# imposes on its generics.
  5. SFINAE equivalent in C#?

    [quote name='BenMatlock' timestamp='1348879548' post='4984913'] There is no such thing as "const" in C#, so that's a non issue. However, it's normal that it doesn't work in c++. An array of const objects is not all all the same type as an array of non const objects. You can't expect implicit conversion of those two types.[/quote] I could expect it, given that the two objects should have both identical code and data, and one has an interface that is a subset of the other. The fact that it's so difficult to use one in place of the other is just a limitation imposed by poor design choices in the C++ template system. If it C++ disallowed atrocities like this, the types would be compatible: [code]struct MyObject{}; template<class T> struct MyTemplateClass { T x; }; template<> struct MyTemplateClass<const MyObject*>{}; int main() { MyObject obj; MyTemplateClass<MyObject*> i1; i1.x= &obj; MyTemplateClass<const MyObject*> i2; i2.x= &obj; // compile error }[/code] Reading through stuff about C# generics, it seems that they maintain restrictions to prevent that sort of thing.
  6. I was typing a response that involved C++ template syntax in a code block, and discovered when I posted that the &lt; and &gt; symbols (and everything between them) had all been removed. I discovered that you could use escape codes to cause the characters to appear correctly and edited those into my post. Unfortunately, hitting 'preview post' replaces escaped characters with unescaped characters. Thus, hitting 'preview post' twice in a row will result in two different-looking previews, as the second time the now-unescaped characters will be removed. 'preview post' changing what your post will look like upon submit is most certainly a bug. Could you just automatically replace symbols like &lt; with their escape sequences upon submit? I think the entire rest of your system would work well enough with just that. And it doesn't do anything a user couldn't do themselves, so it could not possibly be a security issue.
  7. SFINAE equivalent in C#?

    [quote name='swiftcoder' timestamp='1348869994' post='4984880'] Ja, I'm quickly starting to miss C++ templates. I'm going to have to unlearn my template-centric coding style for C#. [/quote] There's a number of aspects of C++ templates that bug me. Stuff like this in particular: [source lang="cpp"]void function(const std::vector&lt;Objects*&gt;&){} void constFunction(const std::vector&lt;const Objects*&gt;&){} std::vector&lt;Objects*&gt; objectList; function(objectList); constFunction(objectList); // compile error[/source] Do C# generics let you do that sort of stuff easily?
  8. #pragma once

    I would use #pragma once because it's simpler and leaves less room for programmer error. It is supported across all major compilers (gcc, msvc, clang, intel...). In the event that you discover that you need to support an old compiler, you can run a script [url="http://www.tt-solutions.com/en/portfolio/unpragma_once"]such as this one[/url] to replace #pragma once with include guards. I've only once encountered a header file in which I wouldn't want to include #pragma once. By default, you should be doing it for every header file.
  9. [quote name='Cornstalks' timestamp='1340346736' post='4951627'] mutlimap and priority_queue are totally different... one uses a mapped [i]key[/i] and [i]value[/i], and the other uses a single [i]value[/i]. Pick the one that fits most naturally with your problem. Don't abuse your toolbox. [/quote] That's not really all that fundamentally different. The difference between sorting by key and sorting by value is simply that in the latter case, your key is a part of your value. The former is a more general case of the latter. Hence why you see things like [url="http://doc.qt.nokia.com/latest/qset.html"]QSet[/url] (value only) being implemented using a [url="http://doc.qt.nokia.com/latest/qhash.html"]QHash[/url] (key value pair). The source is literally: [code]template <class T> class QSet { typedef QHash<T, QHashDummyValue> Hash; ///... private: Hash q_hash; }; [/code] QHash then relies on some specializations in choosing the node type to save memory, but even if it didn't the worst that could happen is that you'd use a little more memory to store each object. If that saved the developer the time of building and maintaining a completely new data structure with the desired performance characteristics, and if you had memory to spare, then nothing of value was lost. There are other differences between multimap and priority_queue, but the fact that one is key/value and the other is value-only is not enough to say that one would be a natural fit and that the other would not. I think the expected read and write patterns are far more important.
  10. Overusing smart pointers?

    Assuming the pointer must not be null, is there any reason to use pointer.get() over &*pointer? I've been using the latter as it works for pretty much any pointer-like type (raw pointers, boost smart pointers, qt smart pointers).
  11. Streaming Development Buy or Write

    On the "buy" vs. "build" evaluation, this would sound like a no-brainer "buy" to me. You have no special requirements whatsoever. Heck, you could use something like livestream and get everything for free.
  12. [quote name='Servant of the Lord' timestamp='1339173718' post='4947410']I don't think there's much risk of accidentally using signals and slots... But even if so, the code is still standard C++ (afaik, it's not an extension to the C++ language itself, they just have another pre-compile step that converts the signals and slots to valid C++). I think you can even compile code using signals and slots using another IDE (or another compiler), as long as you run it through the QMake build step first, but I'm not certain. [/quote] To use other build systems, all you need to do is run the moc over each class that declares signals or slots. Compile and link each of the moc's output files into the same library as the input file. There is no requirement even to use qmake.
  13. That depends on how you acquire the data and what you're going to use it for. Whatever the case, the velocity will need to be adjusted each time the position changes (assuming you're travelling around a sphere). What sort of game is it? It's much harder to do things like line-of-sight or shortest path checks with spherical coordinates. The poles in particular are very annoying.
  14. [C++] suddenly shutdown on some computers

    What's workingState initialized to? Make sure it's either NULL or a valid state if you're going to be deleting it on the first state change.
  15. Why use scripting languages? And which one to use?

    I've only begun to use scripting, but the biggest thing it seems to be useful for (to me) is tweaking user-interface elements. By defining user interactions functions in a script, I can quickly evaluate the impact of UI changes on the fly without leaving my program. An example of this would be controlling the zoom levels of a map. You're never going to figure out the ideal parameters without using it, and you might not even know what the basic structure of the function should look like (polynomial, exponential, bounded?).