-1

there. So, I'm working on a project for school and it's a bet program (desktop, web and mobile) and I'd like to know your opinion in how I should access and insert the information. Whether it'd be better to insert into/select from/etc. sql database or if it'd better to work with lists and just unload all the info from them into sql when I close the program or click save.

On the one hand, I think it'd be safer dealing directly with the database, but on the other hand it'd probably be slower to be always accessing the database. You probably wouldn't even notice with few people accessing it, but with a lot of people doing so it'd probably take it's toll...

So, what do you think?

taiko
  • 458
  • 6
  • 22
  • "You probably wouldn't even notice with few people accessing it, but with a lot of people doing so it'd probably take it's toll..." how many people is a lot of people? You'd be surprised just how fast databases actually are. – Cameron Aavik Jun 12 '17 at 00:27
  • There are lot of things to consider here. What kind of data it is? How big the data is? How frequently the data changes? Do you want all the users of application see the updated data all the time or not? If you store the data in lists and the save it to database when application closes you are risking data consistency. One user deletes the data and saves to database but other user still can see the deleted data. Overall storing data offline is not recommended. – Chetan Jun 12 '17 at 00:28
  • @CameronAavik, true. I don't know how many simultaneous accesses to the database would take for it to slow down, honestly... – taiko Jun 12 '17 at 00:42
  • @ChetanRanpariya, well, it's a betting program so I'd say it's important (though it won'd involve money, just points hehe). You make a good point there, about data consistency. I'm asking this for comparison purposes, but also because I'm worried about another thing. If I work only on sql, I probably won't even need other classes and constructors (like clubs, bets, users...) and since it's the final project it'll be evaluated. – taiko Jun 12 '17 at 00:42

1 Answers1

1

Your question is very opinionated. But the general rule is this: How important is the information?

Important: then it should be 'saved' somehow/somewhere as soon as the information was new/changed/removed. This is usually for most data for a system, regardless of the system-type (eg. mobile/desktop/etc)

Not really Important: then you can keep this 'in memory'. This is usually cache data or temporary calculation data.

WHY should important data be saved as soon as possible? CRASHES. You cannot always expect a crash to occur (either by self-created bug or some environmental issue). So try and save data as soon as possible.


Side Note: There are issues like 'offline mode' or 'batching' which help you with saving data under specific circumstances .. but they are just tricks/patterns to help you still follow the general rule -> save early.

Pure.Krome
  • 84,693
  • 113
  • 396
  • 647
  • As I said on another anwser, you make a good point about data consistency and its importance. Now that you mention it, at some point, it'd probably make the program run slower because of the information stored in memory. So, I wouldn't need to have any classes and constructors for this, since it'd all be stored directly into the database, right? – taiko Jun 12 '17 at 00:48
  • You would still need an intermediate data structure to pass it between the UI (presumably) and the code that stores it in the database. Regarding it being "slower" because of all the information in memory, that won't cause it to be slower, what may cause it to be slowed is the time it takes to process/insert that data. Computers are powerful enough that it shouldn't really be an issue though. – Cameron Aavik Jun 12 '17 at 00:54
  • Memory is fast. I/O (saving to disk or sending data over a network) is the slow part. If you put tooooo much data in your memory (more than the memory can hold) then the computer starts saving this over-memory stuff to the hard-disk ... which then is slow (this is called 'paging'). So - you'll still need ctor's and poco's like @CameronAavik said -- that's the basis of coding. Good luck! – Pure.Krome Jun 12 '17 at 01:04
  • Thanks to both. I guess I'll go with sql then. Just so I understand, why do you say I'll need an intermediate data structure? The way I learnt I just receive the data and pass it, in a button click event or something, through a sql connection to the database. No classes/constructors involved (aside from the sqlconnection one, of course). I'm not rejecting your idea, but rather trying to understand your point of view. – taiko Jun 12 '17 at 14:59
  • It's how you structure your solution and where your _concerns_ are. Basically, you never put database code behind a click event. Click events are handling UI stuff. It is _given_ a viewmodel and then decides how to display it. Look up/learn about project structures and layering your project. This will enable better testing and easier maintenance. – Pure.Krome Jun 12 '17 at 23:29
  • So, are you saying I should have, for instance, a class 'user' and when I register a user call the consttructor and inside the class have the connection method, as opposed to having the connection in the click event directly? – taiko Jun 12 '17 at 23:40
  • https://stackoverflow.com/questions/312187/what-is-n-tier-architecture and https://msdn.microsoft.com/en-us/library/bb384398.aspx. Enjoy your reading :) – Pure.Krome Jun 13 '17 at 03:48