• Content count

  • Joined

  • Last visited

Community Reputation

504 Good

About SabreMan

  • Rank
  1. [quote name='joey201' timestamp='1340655665' post='4952781'] Hello I'm following this tutorial about arrays and I understand how they are declared and the several ways to initialize them, what confuses me is when I can't do ... [/quote] Arrays in C++ are a degenerate data structure which you should avoid, at least if working code is a priority. You might consider finding a tutorial which teaches a more modern approach to C++ (Accelerated C++ for instance).
  2. [quote name='smr' timestamp='1340656857' post='4952786'] I will just say that any performance considerations aside, it IS very difficult to manage a large python application. With Java or any other compiled language the compiler will find many of your errors for you. With python you will loath to change any interface or the signature of any function. Those changes will affect many different source files and you'll be debugging those changes instead of just fixing them before you can build it. [/quote] This is a case for automated unit testing, which should be carried out in any "large" application. Not that it always is, of course. The point is that process and procedure is just as significant to project success as is choice of technology. [quote name='6677' timestamp='1340661690' post='4952808'] Oh yeah, its horrific. IDLE is a real poor IDE, and there aren't really any better ones. [/quote] Eclipse + pydev is better.
  3. As usual, it depends. There's several factors you may want to think about, such as whether you want to pass arguments with an event, if you want your observer framework to be fully typesafe, whether it needs to be threadsafe, etc. If you're using Boost and you're not so bothered about your own implementation of observer, then boost::signals2 is worth a look.
  4. It's unclear from your explanation what the precise problem is, but you may find it easier to get your code working correctly if you avoid working with bare pointers as much as possible. It's also not entirely obvious that you need your town objects to be heap-allocated. Consider storing the town objects by value. If you are convinced you need them to be heap-allocated, then prefer to use a suitable smart pointer. Boost's shared_ptr or weak_ptr should be a good option. Also consider using std::vector rather than std::list, which is a general recommendation: Always prefer std::vector as the default choice for a sequence container, unless there's a clear overriding reason to use something else. Finally, don't hold onto iterators, or use them to identify an object. If you want to remove a town from a container, then do so using the identifier of the town, for example the town name (assuming the name is a unique identifier). So the signature of your deleteTown function could be: [CODE] void deleteTown( const std::string & townName ); [/CODE] Any iterators which are acquired to carry out the delete should not live beyond the scope of deleteTown.
  5. This is likely because you are defining objects in header files, and then including those header files in multiple places, leading to the same code being input to the linker from more than one object file. In order to correct this, you need to ensure that you have only declarations (not definitions) in your header files, and the corresponding definitions need to be in just one place. Any good C++ text will explain how to do this.
  6. Quote:Original post by Kest For example, I had a situation where an attacker, like a character with a gun, would launch an attack. The attack information was stored in a structure. But the defense information for the object being hit was stored in exactly the same way. So I had two object-like entities that needed to clash and interact with each other. But which do I upgrade to an object and give the interaction functions? The attack data, or the defense data? The example you've described sounds like an application of multimethods, where the actual implementation of the function that gets executed depends on the dynamic types of more than just the first parameter value passed to the function. The trouble with some popular languages purporting to be "OO" is that they only allow single dynamic despatch, which means that many users lack the design vocabulary to understand alternative approaches. Don't be fooled into thinking that such languages provide the right way of doing things, even if you must use them. If you're familiar with Design Patterns, you can try using the Visitor Pattern, which is a poor simulation of multimethods for languages that do not provide direct support.
  7. Quote:Original post by Extrarius Quote:Original post by SabreMan [...]Why are you biased against it?Because I don't use indentation as the main way to identify blocks, the fact that indentation is the ONLY way to identify blocks (in other people's code, at least - I could use comments or the like to mark my own) makes it very difficult for me to read. I agree that indentation as a scope delimiter isn't ideal, but I'm surprised you don't use indentation to layout your source-code. If you use indentation to begin with, then having to do so in Python is not much of a problem. It still can be a problem when copying code between editors with different formatting rules, but IME this doesn't bite very often. Quote: The reason I don't use indentation as the main way to identify blocks is due to my C++ coding style: I use semi-verbose identifiers, and when lines get too long, I break them and indent the following lines. That would be considered normal in Python.
  8. Quote:Original post by JohnBSmall I was under the impression that std::hash_map<> wasn't standard (hence being moved to stdext::hash_map<> in MSVC)... is there some other form of hashtable in the standard library that I should know about? Because I'd really like to be able to use it if there is... John B So either use std::map or use a non-standard hash table implementation. I don't see why you'd be writing your own data structures, or that this in itself is a driver to move language & platform.
  9. Quote:Original post by Rob Loach You might like to try out C#. The .NET Framework comes with a throng of tools that you can work with in your projects (lists, hashtables, etc). It eliminates all that time you spend working on making the correct data manipulation tools in C++. You seem to be implying that C++ does not have lists, hashtables, etc?
  10. Quote:Original post by Extrarius Also, IME, this is one of the main reasons beginners (not that you are one) hate C++ and love languages like python is that they were never exposed to the STL and might not even know it exists, whereas with languages like python, the data structures are 'shoved in your face' so to speak I'm not sure your figure of speech is really appropriate. Part of the appeal of, say, the dictionary structure in Python is that it is intrinsic to the language rather than `shoved in your face'. For example, a class definition is itself held in a dictionary. This means that metaprogramming can be achieved by accessing dictionaries of language elements in the same way that you would access any dictionary. Quote: I'll be learning python for a class this semester, but I'm biased against it Why are you biased against it?
  11. Quote:Original post by haro The 'restrictiveness' of a language is directly related to the incompetence of the user of said language. The 'elegance' of a language is directly related to the competence of the user of said language. Which language is better suited to mental masturbation is entirely irrelevant. The restrictiveness of a language is directly related to the expressive power of a language - independently of any users. The competence of a user of said language dictates how well they can harness the expressive power. If a language is restrictive, then competent users may hit the ceiling. The lower that ceiling, the lower the required competence to hit the ceiling. Restrictive languages can act as a great leveller!
  12. Quote:Original post by Peter Conn I was wondering, if you had created a game, how would you work out the requirements for the users computer to run that game? Surely it will work on your computers specifications, but would you just say those and anything better? Would you make estimations on the specifications needed? If it is something you've done on your home PC, then the only statement you can make is "tested on my configuration". If other people play your game, you can invite feedback and begin to build a picture of which configurations work well.
  13. Quote:Original post by King of Men Perhaps I phrased it awkwardly, but the point I was actually trying to make is the same one as yours : It depends on context. But I think I disagree with you on the 'executable syntax' bit : Any random set of numbers is code as far as I'm concerned. Well, I couldn't disagree with that statement even if I wanted to, as you expressed it as your personal opinion! ;) Quote: What makes it code is the context of being supplied to the CPU as instructions. That's not so clear, although I do agree. For example, C++ source code is not a direct set of instructions to a CPU, but indirectly it is, via the compiler. It's the C++ Standard (and the rules of the compiler) which give the C++ the executable semantics.
  14. Quote:Original post by King of Men Either or both, depending on its location in computer memory. Location in computer memory has nothing to do with it. The question is whether or not it has executable semantics, and you only know that when you consider a platform of execution. That is whether it's code, whether it's data or whether it's just some garbage resulting from a cat walking across my keyboard is context-dependent. You can't correctly answer the question without the context. Suppose I wrote a program which reads the byte-stream and performs some computations based on it. That would provide the byte-stream with executable semantics, hence from that point of view it would be code. This is how code can be contained in relational databases, XML documents, and source code files. The distinction between code and data is not as clear as many people would like to believe, which is one good reason why languages which provide a strong distinction might be considered to be overly-constraining. Quote: When converted to afac842630acfdacfa932134, it produces the following assembly code (from DEBUG): What do the idiosyncracies of a particular processor family have to do with the question?
  15. Quote:Original post by Alpha_ProgDes OK. This is code: Is it? What's it do when you run it? How about something more abstract. Is the following code or data? afas842630asfdasfa932134