Best choice for resource container? - language-agnostic

I'm curious which container is the best choice to store resource data [in (data_name, pointer)-form ] to use it for a game. Fast search speed is needed.

A HashMap of type String/Pointer?
Should be a good choice at least for C++ or Java.

Related

Does it considered as a good practice to write interfaces in a higher layer?

I was thinking that would be better to write on the "Application" layer (Business) the interfaces of the unit of work, and their implementations on the "Persistence" layer (DAL). The goal is to make the layers as much decoupled as possible.
Imagine the scenario where you decide to change DAL from EF core to Dapper. How this transition would be less painful? Isn' t better to have the interfaces pronouncing "I need this query, and this, and that, in order to work my business" and map it to the new Data Access Layer?
Your thoughts are correct and will put your business logic in focus and turn technical details into plug-ins to your business logic.
See also "Clean Architecture" by Robert C. Martin for even deeper thoughts into same direction.
https://blog.cleancoder.com/uncle-bob/2012/08/13/the-clean-architecture.html

Which innovations (like MVC, xunit, Hotspot) did Smalltalk bring?

I find more and more aspects where Smalltalk was the innovator, i.e. created the technique or at least the overall concept for the first time. I can think of the following:
xunit approach
IDE concepts
VM optimizations
fluent interfaces
several design patterns (e.g. model-view-controller)
the class-free prototype paradigm.
Are all of these correct? Which further innovations did Smalltalk bring?
I'm sure there are more (e.g. in the field of language design?)
The mouse
Unit Testing
Refactoring
Scavenging GC
image concept (snapshot)
It is the first language that was a clear improvement on a large majority of its successors (with the possible exceptions of self and newspeak). If you want to see the future of java and c#, look no further than smalltalk.
Also, Dan Ingalls is usually given credit for inventing BitBLT as part of Smalltalk 72.
I would also add "IDE" to the list, but I have no citation to back that up.
You forgot one BIG thing: object-oriented programming
I read somewhere that smalltalk implemented the first window based GUI. Hard to beat that ;)
Domain-Driven Design: Trygve Renskaug's papers on the MVC pattern discuss heavily the importance of representing the domain of the system in the object model and separating it from the conceptual view.

What design pattern is best for an RTS game in AS3?

I'm looking to get some good books on design patterns and I'm wondering what particular pattern you'd recommend for a Realtime Strategy Game (like Starcraft), MVC?.
I'd like to make a basic RTS in Flash at some point and I want to start studying the best pattern for this.
Cheers!
The problem with this kind of question is the answer is it completely depends on your design. RTS games are complicated even simple ones. They have many systems that have to work together and each of those systems has to be designed differently with a common goal.
But to talk about it a little here goes.
The AI system in an rts usually has a few different levels to it. There is the unit level AI which can be as simple as a switch based state machine all the way up to a full scale behavior tree (composite/decorators).
You also generally need some type of high level planning system for the strategic level AI. (the commander level and the AI player)
There are usually a few levels in between those also and some side things like resource managers etc.
You can also go with event based systems which tie in nicely with flash's event based model as well.
For the main game engine itself a basic state machine (anything from switch based to function based to class based) can easily be implemented to tie everything together and tie in the menu system with that.
For the individual players a Model-View-Controller is a very natural pattern to aim for because you want your AI players to be exposed to everything the human player has access to. Thus the only change would be the controller (the brain) without the need for a view obviously.
As I said this isn't something that can just be answered like the normal stackoverflow question it is completely dependent on the design and how you decide to implement it. (like most things) There are tons of resources out there about RTS game design and taking it all in is the only advice I can really give. Even simple RTS's are complex systems.
Good luck to you and I hope this post gives you an idea of how to think about it. (remember balance is everything in an RTS)
To support lots of units, you might employ Flyweight and Object Pool. Flyweight object can be stored entirely in a few bytes in a large ByteArray. To get usable object, read corresponding bytes, take empty object and fill it with data from those bytes. Object pool can hold those usable objects to prevent constant allocation/garbage collection. This way, you can hold thousands of units in ByteArray and manage them via dozen of pooled object shells.
It should be noted that this is more suitable to store tile properties that units, however — tile are more-or-less static, while units are created and destroyed on regular basis.
It would be good to be familiar with a number of design patterns and apply them to the architecture of your game where appropriate.
For example, you may employ an MVC architecture for your overall application, factory pattern for creating enemies, decorator pattern for shop items, etc. Point being, design patterns are simply methodologies for structuring your objects. How you define those object and how you decide how they fit together is non prescriptive.

Which type of database is a good fit for this work load?

I know this is a somewhat subjective question but I want to throw it out there anyway because if there is some insight that I've missed, asking this question will save me (and hopefully others) a great deal of searching :-)
Basically, what is the best type of database for when you have a number of items interlinked. For example:
A->B->C->D->E->F->G->H->I
And you want to be able to quickly find the shortest path (or the number of paths ideally) between A and I?
I would normally just use a relational database for this, but I'm not sure a MapReduce style database is any better and then I wondered if there was a type of database I hadn't considered altogether...
As always, all help gratefully received :)
This is exactly the sort of thing neo4j is designed for. It's a graph database that provides operations for doing graph traversal and other common operations.
I would suggest looking into MongoDB - It's NOT a relational database, and all your data gets saved and passed as JSON, it's easy scale-able and build for performance, and comes with a couple of tricks up its sleeve as well, like MapReduce build into mongoDB and way way more.
Since the data is saved as JSON you can save objects within objects and arrays well:
{
foo:"bar",
animals: ['cat','dog','fish'],
blog:{
post:"Hello World!",
comments:["this is cool","Hello back"]
}
}
Checkout - http://www.mongodb.org/
or http://www.mongodb.org/display/DOCS/MapReduce/
for more info

How often do you need to create a real class hierarchy in your day to day programming?

I create business applications with heavy database use. Most of the programming work is just to connect components to the database and modifying components to adapt to general interface behaviour. I mostly use Delphi with its rich VCL library, and generally buy components needed. I keep most of the business logic in the database. I rarely get the chance to build a nice class hierarchy from the bottom up as there really is no need. Anyone else have this experience?
For me, occasionally a problem is clearer or easier with subclassing, but not often.
This also changes quite a bit in a given design as it's refactored.
My biggest problem is that programming courses and texts give so much weight to inheritance, hierarchies, and polymorphism through base classes (vs. interfaces or dynamic typing). This helps create legions of programmers that subclass everything and their mother.
The answer to this question is not totally language-agnostic;
Some languages like Java have a fairly limited set of language features available, meaning that subclassing is fairly often used because it's a convenient method for re-use, technical inheritance.
Closures and lambdas of C# make inheritance for technical reasons much less relevant. So normally inheritance is used for semantic reasons (like cat extends animal).
The last C# project I worked on, we more or less made all of the class hierarchies within a few weeks. After that it was more or less over.
On my current java project we create new class hierarchies all of the time.
Other languages will have other features that similarly affect this composition (mixins come to mind)
I put on my architecting/class design hat probably once or twice a month. It's probably the best hat I have and is the most fun to wear.
Depends what stage of the lifecycle your project is in though.
When your tackling problem domains you are well familiar with and already have a common code base to work from, you often have no need to create a new class hierarchy. It's when you stumble upon problems you have no ready solutions for, that you start building your own.
It's also very dependant on the type of applications you develop. If your domain already has well accepted conventions and libraries to work from, there probably isn't any need to reinvent the wheel (other than personal / academic interests). Some areas have inherently less available resources to work with, and in those you'll find yourself building everything from scratch most of the time.
A majority of applications, especially business applications, contains at least some kind of business logic in it. I would contend that business should not be in the database, but should rather be in the application. You can put referential integrity in the database as I think this is a good choice, but business logic should be only in the application.
By class hierarchy, I suppose you mean do you always have to end up with some inheritance in your object model, then the answer is no. But chances are you can often find some common code, factor it out and create a base class to contain the common code.
If you agree with me on the point that business logic should not be in the database, but should be in the application, then I recommend you look into the MVC Design Pattern to guide your design. You will find your design contain classes or objects. Your VCLs will represent your View, and you can have your Model classes map directly to the database table, i.e. each member in the class in the model corresponds to a field in a database table (again, this is the norm but there will be exception, where this simplicity fails to apply). Then you'll need a layer to handle the CRUD (Create, Read, Update, Delete) of the Model classes to the database tables. You will end up with an "layered" application that is easier to maintain and enhance.
It depends on what you mean by hierarchy - inheritance or layering?
When object oriented languages first came out, inheritance was overused. Complicated hierarchies were common. Now, interfaces (as in Java and C#) provide a simpler way to get the benefit of polymorphism without the complications of inheritance. I rarely use inheritance anymore.
Layering, however, is vital when creating a large application. Layering prevents general low-level classes (like lists) from directly referencing specific high-level classes (like web browser windows). As far as I know, there isn't a formal way to describe layering, but there are general guidelines (model-view-controller (MVC), separate GUI logic from business logic, separate data from presentation, etc.).
It really depends on the types/phases of the projects you're working on. I happen to do that everyday because I'm working on database internals for a new database, creating related libraries/frameworks. I'd imagine doing that a lot less if I'm working within a mature framework using other people's libraries.
I'm doing Infrastructure for our companys' product, so I'm writing a lot of code that will be used later by guys in other teams. So I end up writing lots of abstract classes, interfaces, hierarchies and so on. Mostly it's just a pattern of "default behaviour in an abstract/virtual class, which other programmers may override".
Very challenging, I must say.
The time that I find class hierarchies most beneficial is when the relationship between objects actually does match a true "is-a" relationship in the domain.
However if I can avoid large hierarchies I will due to the fact that they are often a little more tricky to map to relational databases and can really complicate your database designs. Since you say most of your applications make heavy use of databases this would be something to take into consideration.