SmartPOS Development Log - With a twist!

Get help on programming - C++, Java, Delphi, etc.
D3PART3D
Starbound's Dear
Posts: 16295
Joined: 01 Dec 2004, 02:00
Contact:

Post by D3PART3D »

I love this thread :!: I'll be lurking...
Ceterum autem censeo Samsung Mobile esse delendam.

When something is important enough, you do it even if the odds are not in your favor.
- Elon Musk
Hman
Registered User
Posts: 28520
Joined: 06 Oct 2003, 02:00
Processor: Intel i5 650
Motherboard: Asus P7H55-M LX
Graphics card: Gigabyte 7850 2GB OC
Memory: 8GB Kingston DDR3
Location: In my skin
Contact:

Post by Hman »

D3PART3D wrote:I love this thread :!: I'll be lurking...
As long as you keep your hand out your pants.
"Every thinking man is a drinking man."


Member of the Barberton Tigers
D3PART3D
Starbound's Dear
Posts: 16295
Joined: 01 Dec 2004, 02:00
Contact:

Post by D3PART3D »

:roll: :lol:
Ceterum autem censeo Samsung Mobile esse delendam.

When something is important enough, you do it even if the odds are not in your favor.
- Elon Musk
Judas
Registered User
Posts: 2118
Joined: 17 Oct 2006, 02:00
Location: Stellenbosch
Contact:

Post by Judas »

Slasher wrote:Judas
Im Guessing we will be using the Open Source Library version of QT? 44ish mb?

Ok, got Bloodshed, Druid, QT... Now I can start messing around and playing a bit... Modular seems to be the best idea.
Yup, that's right - Qt 4.3 Open Source Edition. It can be downloaded from here for anyone using Windows; Ubuntu users will just need to install the libqt4-dev package in Synaptic :D. There is also a very short tutorial here that would be worth checking out if you've never used Qt before.

The other little tool that we'll be using is CMake, a cross-platform build system. Compiling source code by hand is a tedious process, espcially when you've got hundreds of files that need to be compiled in the correct order. Build tools solve this problem by automating the process - so, instead using hundreds of 'g++' commands to compile the files, you can just type "make" once and it will build the whole system for you.

There are a number of reasons for using CMake rather than another system, such as QMake:
  • CMake has a very, very powerful scripting language for describing the builds that is also very easy to use.
  • CMake provides nice colourful feedback on the progress of the build, other systems just spew the compiler's output onto your screen.
  • CMake allows you to tweak install paths and other compile-time options much more easily than other systems.
  • CMake supports Linux and Windows compilers.
'One will rarely err if extreme actions be ascribed to vanity, ordinary actions to habit, and mean actions to fear.'
- Friedrich Nietzsche

'Do not argue with Judas, nube, that would be foolish!'
- D3PART3D
Kronos
Moderator Emeritus
Posts: 4280
Joined: 28 May 2003, 02:00
Location: Azeroth
Contact:

Post by Kronos »

Oh, hold on! Bloodshed is out like cookies in an orphanage!

I ain't using something writen in Delphi to code C++!!!???? :?

I've just seen something nifty though. Check out Code Blocks It seems nice enough, with cool features.
Image
Judas
Registered User
Posts: 2118
Joined: 17 Oct 2006, 02:00
Location: Stellenbosch
Contact:

Post by Judas »

Kronos wrote:Oh, hold on! Bloodshed is out like cookies in an orphanage!

I ain't using something writen in Delphi to code C++!!!???? :?

I've just seen something nifty though. Check out Code Blocks It seems nice enough, with cool features.
Nice find Kronos :).

Make sure that you download the version bundled with MinGW - that's the compiler that Qt requires us to use.
'One will rarely err if extreme actions be ascribed to vanity, ordinary actions to habit, and mean actions to fear.'
- Friedrich Nietzsche

'Do not argue with Judas, nube, that would be foolish!'
- D3PART3D
PypLaCe
Registered User
Posts: 214
Joined: 19 Apr 2005, 02:00
Location: Johannesburg
Contact:

Post by PypLaCe »

Kronos wrote:Oh, hold on! Bloodshed is out like cookies in an orphanage!
LOOOOL :lol:

Ive used Bloodshed before and its pretty good...

I still have to download all these tools and Qt and its gonna rape my cap for the month. :cry:
Judas
Registered User
Posts: 2118
Joined: 17 Oct 2006, 02:00
Location: Stellenbosch
Contact:

Post by Judas »

PypLaCe wrote:
Kronos wrote:Oh, hold on! Bloodshed is out like cookies in an orphanage!
LOOOOL :lol:

Ive used Bloodshed before and its pretty good...

I still have to download all these tools and Qt and its gonna rape my cap for the month. :cry:
Well, Qt is about 45 megs... The IDE shouldn't be more than about 60MB, and CMake is only a couple of megs. Total, +- 120MB ;).
'One will rarely err if extreme actions be ascribed to vanity, ordinary actions to habit, and mean actions to fear.'
- Friedrich Nietzsche

'Do not argue with Judas, nube, that would be foolish!'
- D3PART3D
Kronos
Moderator Emeritus
Posts: 4280
Joined: 28 May 2003, 02:00
Location: Azeroth
Contact:

Post by Kronos »

Sweet! Code::Blocks have BUILT IN SUPPORT for Qt, and many other APIs. Win32, OpenGL, Ogre, SDL, wxWidgets, etc.

Very cool! Yes, I got the MinGW version. I'll just DL Qt at home tonight, get the version control going, and I'm up an running.

I'll start by checking out whatever design docs you have, and give my input on that.
Image
Judas
Registered User
Posts: 2118
Joined: 17 Oct 2006, 02:00
Location: Stellenbosch
Contact:

Post by Judas »

Kronos wrote:Sweet! Code::Blocks have BUILT IN SUPPORT for Qt, and many other APIs. Win32, OpenGL, Ogre, SDL, wxWidgets, etc.
Nice! I'll try to get it running under WINE later and check it out.
Kronos wrote:I'll start by checking out whatever design docs you have, and give my input on that.
Thanks a lot - if you need write access to the repository, just create an account at SourceForge, PM your account name, and I'll add you to the project :).
'One will rarely err if extreme actions be ascribed to vanity, ordinary actions to habit, and mean actions to fear.'
- Friedrich Nietzsche

'Do not argue with Judas, nube, that would be foolish!'
- D3PART3D
Judas
Registered User
Posts: 2118
Joined: 17 Oct 2006, 02:00
Location: Stellenbosch
Contact:

Post by Judas »

Database Design:
Before doing the rest of the system's architecture, we should work on a design for the database. Just in case you don't know what a database is, it's a collection tables consisting of many rows that you can use to store data. Take this table for example:

Table name: Staff

Code: Select all

StaffID    Name          Department
----------------------------------------------
1          jamin_za      Quality Control
2          Tribble       Photography
3          KillerByte    Flame-resistant goods testing
4          D3PART3D      Quality Control
(It is assumed that each staff member can only work in one department.)

The StaffID would be a primark key (PK). Primary keys uniquely identify a record (row), and are usually stored as numbers so that they can be searched for more quickly. Strings of characters could also be used, but integer searching is many, many times faster.

Database Normalisation:
Database Normalisation is a technique for desigining the database in such a way that there is no duplication of information and the integrity of the data is protected. Normalisation is broken up into a series of levels:

First Normal Form (1NF):
A table is in 1NF if it allows no duplicate records, and does not allow blank fields. Our Staff table is therefore 1NF, because the use of a unique PK ensures that there are no duplicates, and we have no missing information (eg. no rows without names or departments).

Second Normal Form (2NF):
To be considered second normal, the table must be in 1NF. Furthermore, we mustn't duplicate information for the same staff member - for example, if it was possible to state twice that jamin is in Quality Control, the table wouldn't be 2NF. Because we can't do that, the table is 2NF.

Third Normal Form (3NF):
In order to be considered 3NF, the table must already be in 2NF. Furthermore, you mustn't have any data stored in the table that isn't directly related to the candidate key, which is the staff member in this case. As a rule of thumb, this means that you should have absolutely no data duplication in the table. We fail this rule, because we have "Quality Control" listed twice - once for jamin, once for D3PART3D. In order to make the table 3NF, we would need to split deparment information into its own table, like this:

Code: Select all

DepartmentID  DepartmentName
------------------------------------------
1             Quality Control
2             Photography
3             Flame-Resistant Goods Testing
We would then need to update the Staff table to look like this:

Code: Select all

StaffID    Name          Department
----------------------------------------------
1          jamin_za      1
2          Tribble       2
3          KillerByte    3
4          D3PART3D      1
The Department column in Staff is now a Foreign Key (FK), because it references the PK of the Department table. Now we only have each department listed once, so both tables Staff and Department are third normal.

These are very simplified versions of the normalisation rules, for more details see the Wikipedia article on database normalisation.

Our Database
With all of that out of the way, you shouldn't have any trouble understanding our current database design:
Image

The dashed lines between tables represent FK references between the tables.
Last edited by Judas on 12 Dec 2007, 14:03, edited 2 times in total.
'One will rarely err if extreme actions be ascribed to vanity, ordinary actions to habit, and mean actions to fear.'
- Friedrich Nietzsche

'Do not argue with Judas, nube, that would be foolish!'
- D3PART3D
Kronos
Moderator Emeritus
Posts: 4280
Joined: 28 May 2003, 02:00
Location: Azeroth
Contact:

Post by Kronos »

Judas wrote:Nice! I'll try to get it running under WINE later and check it out.
You can also download the Linux Source files and RPM packages... ;)
Image
Judas
Registered User
Posts: 2118
Joined: 17 Oct 2006, 02:00
Location: Stellenbosch
Contact:

Post by Judas »

Coding Conventions:
Before code-level architecture and actual coding begin, it's important to specify coding conventions. Coding conventions are general standards with regards to class and variable naming, indentation, commenting, etc.

Every programmer has thier own preferred style, so it's important that the conventions aren't too restrictive. If you try to force everyone to code in the style that you like, no-one is going to be interested in helping out ;).

So, for this project these are the only conventions that must be adhered to:
  • Variable, class and function names must use camel case - ie. ClassName for class names and functionName for functions/variables. Java programmers will be used to this naming scheme already, because it's the suggested convention for Java programs. The main reason for picking this particular convention is that it is the one used by the Qt classes.

    A naming convention is important because you really want to be able to call functions without checking which convention they use. If everyone uses their preferred naming scheme, you'll end up with some functions named in Camel/Java convention (functionName), some named in C# convention (FunctionName), and some in C convention (function_name). Because C++ is case sensitive, functionName is not the same as FunctionName.
  • Global variables (data that is available to the whole system) should be avoided like the plague, but if you must gobal variables prefix their names with g_ - eg. g_globalVariable.
  • Member variables (data that is available to the entire class) should be prefixed with m_ to enable clear distinction between non-member and member variables, eg. m_memberVariable.
  • Doxygen comment blocks should be used to document classes and functions in the headers. Doxygen is a tool that can be used to extract comments to generate HTML or LaTeX documentation.

    Doxygen comments take this format:

    Code: Select all

    /** Find the user with the provided ID.
     *
     * @param userID The user's unique ID code.
     * @return A pointer to a User object describing the user. This object can be
     * safely deleted. If  the user cannot be found, a NULL pointer will be returned.
     */
    static User* findUser (const qint32 userID) const;
    
  • If a function parameter doesn't absolutely need to be changed during the execution of the function, mark it const.
  • If a function doesn't change any data, mark the entire function const.
More general coding conventions can be found in the docs/Coding Conventions.txt file under version control.

EDIT: Some notes...

Marking a parameter "const" means putting the const identifier in front of it, as with "const qint32 userID" in the code block above. Doing this prevents you from changing the value stored in userID during the running of the findUser function.

Marking an entire function const means putting the const identifier right at the end of the function definition, as in the example above. This tells the person using your function that the function isn't going to modify any files, data, or variables.
Last edited by Judas on 12 Dec 2007, 15:37, edited 1 time in total.
'One will rarely err if extreme actions be ascribed to vanity, ordinary actions to habit, and mean actions to fear.'
- Friedrich Nietzsche

'Do not argue with Judas, nube, that would be foolish!'
- D3PART3D
Kronos
Moderator Emeritus
Posts: 4280
Joined: 28 May 2003, 02:00
Location: Azeroth
Contact:

Post by Kronos »

The thread is now Sticky :)
Image
Judas
Registered User
Posts: 2118
Joined: 17 Oct 2006, 02:00
Location: Stellenbosch
Contact:

Post by Judas »

The Data Subsystem - Overview:
The data subsystem, as we discussed previously, is responsible for making the information from the database available at a high level of abstraction. It also needs to regulate how much data is available based on which user is currently logged in to increase the security of the system.

The most used classes from this subsystem will be the entity classes. Entity classes provide a natural way to work with information that is stored in the database. A prime example is the User class. In order to create a user, you would just need to call the User::createUser() function with the correct parameters, and the User class would handle all of the actual database transactions automatically. Similarly, to update a user's address you would just call jim.setAddress(), letting the User class handle all of the dirty SQL details internally.

All of the other entity classes (such as Bill, Order, Item, Terminal and Special) will work in much the same way.

The entity classes will make use of the DatabaseSingleton class behind the scenes. This class handles the very low-level database functions, such as connecting, disconnecting and executing queries.

To regulate the security, we use a class called Security. This class essentially just needs to keep track of which user is logged in to the system at the moment, as well as providing functions for authenticating user logins, logging users out and checking which user is currently logged in. The entity classes will use this information to decide just how much information they should expose.

=====

I'll set to work on writing a basic implementation of the data subsystem that we can use as example code to explain some C++ and common programming techniques. In the mean time, if any of the people who've been working through the C++ tutorials have any questions, fire away! By this point you should understand at least the concepts behind functions, pointers, and classes. If anyone is struggling with those parts (and they are a little tricky), just say so and I'll take a shot and explaining them :).


Kronos wrote:The thread is now Sticky :)
Thanks Kronos! :D
'One will rarely err if extreme actions be ascribed to vanity, ordinary actions to habit, and mean actions to fear.'
- Friedrich Nietzsche

'Do not argue with Judas, nube, that would be foolish!'
- D3PART3D
CountZero
Registered User
Posts: 307
Joined: 09 Nov 2005, 02:00
Location: Behind you!

Post by CountZero »

Judas this is a great idea!!

Now the programmers have their own "modding" thread.

I'll also like to participate and will start my downloads tonight.

Looking forward to put my theoretical knowledge into practical knowledge.
Judas
Registered User
Posts: 2118
Joined: 17 Oct 2006, 02:00
Location: Stellenbosch
Contact:

Post by Judas »

CountZero wrote:Judas this is a great idea!!
Thanks man!
CountZero wrote:I'll also like to participate and will start my downloads tonight.

Looking forward to put my theoretical knowledge into practical knowledge.
Excellent, the more the merrier :D.
'One will rarely err if extreme actions be ascribed to vanity, ordinary actions to habit, and mean actions to fear.'
- Friedrich Nietzsche

'Do not argue with Judas, nube, that would be foolish!'
- D3PART3D
Richard_
Registered User
Posts: 2295
Joined: 18 May 2003, 02:00
Location: Durban, South Africa

Post by Richard_ »

Brilliant. I love this thread :-)
Judas
Registered User
Posts: 2118
Joined: 17 Oct 2006, 02:00
Location: Stellenbosch
Contact:

Post by Judas »

A quick update:

I'm currently experimenting with some other toolikts that we might be able to use instead of Qt. Why not use Qt, you ask?
  • Qt extends the C++ language in non-standard ways. This creates even more stuff for people new to the language to learn, and it also means that otherwise exerienced C++ developers will have to learn quite a bit too.
  • In order to support these extra features, extra tools are required to process the code before compilation. This complicates the build process somewhat, and also requires that you have all of the extra tools in order to compile.
  • Qt-based software can only be compiled by the G++ and MinGW compilers.
  • The Qt library is rather heavy, at +- 40mb.
At the moment, wxWidgets is looking like the most promising alternative. It has more or less the same features of Qt, but it uses standard C++, compiles on almost any compiler with no extra tools required, supports more platforms, and only weighs 12MB.

Has anyone here ever worked with wxWidgets before? Or anyone else have any thoughts on the matter?
Last edited by Judas on 14 Dec 2007, 10:42, edited 1 time in total.
'One will rarely err if extreme actions be ascribed to vanity, ordinary actions to habit, and mean actions to fear.'
- Friedrich Nietzsche

'Do not argue with Judas, nube, that would be foolish!'
- D3PART3D
Slasher
Registered User
Posts: 7525
Joined: 23 Aug 2003, 02:00
Location: 5th rock from the sun.

Post by Slasher »

I havent worked with wxWidgets, but reading the reason for change, I say go different and drop Qt. The fact that it is another compiler etc to be used makes it a pain. Especially for new people.

I can program in C++ easily enough, but learning Qt is a whole new ball game.

Im all for simplicity and the fact it uses standard C++ makes me prefer it.

I have had SOME bit of work with Qt during our first year project and we had a lot of hassles with it and was hell to make certain required changes...
My BF2142 Stats:
Image


Slasher : Former member of www.PCFormat.co.za
I have reached the end of my near 5 year forum life. Farewell good days...

slasher (at) webmail (dot) co (dot) za
stewy_w
Registered User
Posts: 486
Joined: 25 Sep 2003, 02:00
Location: Citta Del Cappo
Contact:

Post by stewy_w »

:( i've been reading the Qt tutorials, and it was starting to be interesting
Running Vista is like being in a candy store that only sells black liquorice at exorbitant prices. Oh, and you\'re only allowed to eat the candy in the store.
Kronos
Moderator Emeritus
Posts: 4280
Joined: 28 May 2003, 02:00
Location: Azeroth
Contact:

Post by Kronos »

So, what's the status on this project Judas?
Image
Judas
Registered User
Posts: 2118
Joined: 17 Oct 2006, 02:00
Location: Stellenbosch
Contact:

Post by Judas »

Kronos wrote:So, what's the status on this project Judas?
Still going ahead, I've just been too busy lately what with the holidays and getting prepared for university (which starts later this week). I'll try to get things going again next week if I have time :).
'One will rarely err if extreme actions be ascribed to vanity, ordinary actions to habit, and mean actions to fear.'
- Friedrich Nietzsche

'Do not argue with Judas, nube, that would be foolish!'
- D3PART3D
D3PART3D
Starbound's Dear
Posts: 16295
Joined: 01 Dec 2004, 02:00
Contact:

Post by D3PART3D »

Judas wrote:

Code: Select all

3          KillerByte    Flame-resistant goods testing
ROFL! Now that had me in fits of laughter :lol:
Post Reply