playMaker

Author Topic: Using Hash Tables and Databases effectively.  (Read 2038 times)

precisionclear

  • Playmaker Newbie
  • *
  • Posts: 21
    • View Profile
Using Hash Tables and Databases effectively.
« on: April 23, 2017, 05:39:01 PM »
Being able to use arrays effectively has been such a huge improvement, hard to imagine creating anything more than the most simple game without them. Hash Tables on the other hand... The key itself stores an additional value that can't really be sorted or organized, and duplicates will create an error and not be stored at all.
Can anyone give examples of how they use Hashes effectively?
Same with databases. It makes sense that they store large amounts of information that can be viewed and changed easily, but eventually the data have to be copied to variables anyways, and stored in an FSM. Maybe as I get further along, the utility will become more obvious.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 12351
  • Official Playmaker Support
    • View Profile
Re: Using Hash Tables and Databases effectively.
« Reply #1 on: April 23, 2017, 10:45:43 PM »
Hi,

Hashtables:

Hashtables is just as powerful as arrays, but serves a different purpose that's all, I think you are just missing the point of hashtable and dictionnaries in general.

 Imagine a set of preferences for your game or application, it's always a pair of key/value each representing a particular setting and it's value.

you don't need to sort them, you only need to access them by their keys at runtime to use and honour the user preferences wherever it matters.

 and, in the case where you want to have your keys ordered in a specific way, then you can use an Array with just the keys in the order you need, then when you want to list the preferences in the interface, you will show them in the order they are listed in the array, and for every preference, check the value in side the hashtable as you iterate over the array of keys.

 Does that make sense?

Database: the fact that data has to be copied in variables is true for EVERY application, apart from the most advanced programming language an databases, because very early on, engineers separated data and logic and it became pretty much the norm. There are some research and existing code structure that blend data and logic, like Object Oriented DataBase, where the database stores Object, not data, and the object contains the logic related to the data it contains: http://people.cs.pitt.edu/~chang/156/19oodb.html but that's not very common nor widely spread at our level.

so, it's fine, admitted and not debated that when using a database, you make a query and the result is returned in a smaller table, a list of variable or in a single variable depending on the query. This is fine and I can't see how it could be otherwise with the common programming languages and database we use.

I would simply find articles explaining where databases are useful, like:

http://www.softwaretestingclass.com/what-is-database-and-why-do-we-need-them/
https://softwareengineering.stackexchange.com/questions/190482/why-use-a-database-instead-of-just-saving-your-data-to-disk


Bye,

 Jean

precisionclear

  • Playmaker Newbie
  • *
  • Posts: 21
    • View Profile
Re: Using Hash Tables and Databases effectively.
« Reply #2 on: April 28, 2017, 10:55:53 PM »
Thanks Jean,

Your an oracle of knowledge, as always.
Using Arrays for static data, and hash tables as an extension to the arrays
makes a lot more sense.

It was the process of trying to get multiple system concepts to place nicely together
that for me was starting to get a little crazy, sending data all over the place while mistyping string names, forgetting to change a function - made up for the majority of problems, and (almost) was enough to force me to learn real coding.

After reading the articles about databases, I decided to start playing around with SQLite. Amazing how many of these problems it solves, while the syntax is surprisingly intuitive, almost like pseudo code.

Progress seems to come a lot faster when not trying to reinvent the wheel of problems that other people have already solved long before.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 12351
  • Official Playmaker Support
    • View Profile
Re: Using Hash Tables and Databases effectively.
« Reply #3 on: May 02, 2017, 01:56:46 AM »
Hi,

 yep, always spend a fair amount of time making sure you are not doing something already done and battle tested for you :)

 Bye,

 Jean