What are the advantages and disadvantages of building a gui app with python and with C++?
The Big Programming Thread - Page 300
Forum Index > General Forum |
Thread Rules 1. This is not a "do my homework for me" thread. If you have specific questions, ask, but don't post an assignment or homework problem and expect an exact solution. 2. No recruiting for your cockamamie projects (you won't replace facebook with 3 dudes you found on the internet and $20) 3. If you can't articulate why a language is bad, don't start slinging shit about it. Just remember that nothing is worse than making CSS IE6 compatible. 4. Use [code] tags to format code blocks. | ||
obesechicken13
United States10467 Posts
What are the advantages and disadvantages of building a gui app with python and with C++? | ||
uZr
20 Posts
On May 14 2013 04:11 mustache wrote: seeing as i didnt change anything from the parent class QPushButton shouldnt this work without a problem? It doesnt though. The Compiler complains "no matching fuction for call CoinButton::CoinButton[const char[10]] Two things are wrong there: - You defined a new constructor which does not take any arguments, hence your error when compiling; - You forgot to add the Q_OBJECT macro in your class, which will get you in troubles later when you will attempt to connect to its signals/connect its slots Should be something more like:
As a rule of thumb, you want to be able to chain all your QObject, hence the 'parent' in the constructor. This will ease up memory management as a parent automatically delete its child when it gets deleted in a destructor. (+ the Qt framework has done some nifty stuff when overloading the operator= in QObject such that it will automatically delete the previous lvalue if it wasn't NULL which is also another things making life easier with memory management, etc) You implement your constructor like this for example:
| ||
Kambing
United States1176 Posts
On May 14 2013 04:19 obesechicken13 wrote: Tagging along: What are the advantages and disadvantages of building a gui app with python and with C++? Frankly, there is little benefit to creating a gui app in C++ over Python. Python has the benefit of a cross-platform, standard gui library (tkinter). With C++, you are forced into platform-dependent solutions (Win32 or MFC on windows, Cocoa on OSX, GTK and others on Linux) although there are (non-standard) platform-independent solutions out there, i.e., QT. An app that requires a gui is also a sign (but not a necessary condition) that you do not need the low-level control that C++ affords you over a higher-level language like Python. | ||
uZr
20 Posts
On May 14 2013 00:20 darkness wrote: Well, there is memory manipulation in C as well such as malloc, realloc and free. Is this the hard part or do you refer to destructor and/or harder memory management? It's not that it is harder than C, it's just that it has gotten much more complex/featureful over the years which can result in complicated situations: toying with multiple inheritance, operator overloading, and templates can quickly result in getting yourself lost if you did it without following some common pattern (and render your code unusable for others as well). Throw in all the other more specific stuff not found in java (reference passing, pointers (on data or function), friend classes, lambda's, etc) and you add yet another layer of complexity. You're not doing anything hard, it's just that you quickly write things that are too complex to be easily understood (and debugged, and extended, …). Hell in the end you are manipulating a stack, some registers and a few hundreds instructions, nothing hard in that, you just have to do rigorous reasonings ![]() | ||
nunez
Norway4003 Posts
On May 14 2013 04:41 Kambing wrote: With C++, you are forced into platform-dependent solutions (Win32 or MFC on windows, Cocoa on OSX, GTK and others on Linux) although there are (non-standard) platform-independent solutions out there, i.e., QT. seems like a contradictory statement... | ||
mustache
Switzerland309 Posts
On May 14 2013 04:39 uZr wrote: Two things are wrong there: - You defined a new constructor which does not take any arguments, hence your error when compiling; - You forgot to add the Q_OBJECT macro in your class, which will get you in troubles later when you will attempt to connect to its signals/connect its slots Should be something more like:
As a rule of thumb, you want to be able to chain all your QObject, hence the 'parent' in the constructor. This will ease up memory management as a parent automatically delete its child when it gets deleted in a destructor. (+ the Qt framework has done some nifty stuff when overloading the operator= in QObject such that it will automatically delete the previous lvalue if it wasn't NULL which is also another things making life easier with memory management, etc) You implement your constructor like this for example:
Ok it worked now thank you. ![]() Bear in mind im learning C++ as im doing this project hence the following question: So if I'm inheriting from the class QPushButton, the constructor I define in CoinButton must contain a constructor which initialises the parent QPushButton. I was under the assumption that I inherit the constructor methods of the parent class. EDIT: Just read up a bit more on constructors of inherited classes, question answered! thanks a bunch already EDIT2: is there any reason to divide the definition and declaration of the constructor methods? i tried it directly implementing the constructor in the declaration(or rather combining declaration and definition) and it worked just fine. is this just a style thats common in c++? | ||
Kambing
United States1176 Posts
On May 13 2013 06:46 darkness wrote: What's so hard about the C++ syntax? It resembles Java a lot, sure cin/cout are a bit... weird, but that's ok Alternatively, why do people say C++ is hard? C++ is a deceptively difficult language because while it looks like Java, it requires far more in-depth knowledge of the language to "do right". Furthermore "doing it wrong" not only introduces inefficiencies but also unsafe code, security-vulnerable code, none of which is checked at compile-time. I'll give a concrete example shortly... | ||
Kambing
United States1176 Posts
On May 14 2013 05:13 Kambing wrote: C++ is a deceptively difficult language because while it looks like Java, it requires far more in-depth knowledge of the language to "do right". Furthermore "doing it wrong" not only introduces inefficiencies but also unsafe code, security vulnerable code, none of which is checked at compile-time. I'll give a concrete example shortly... Even though C++ looks a lot like Java, they are fundamentally different beasts. As a concrete example, consider the following implementation of a Linked List in Java.
Since C++ looks a lot like Java, it's tempting to naively translate the code as follows:
This is a straight-ahead translation. Of note, instead of generics, we use templates (which are also fundamentally different, but not germane to this discussion) and we must explicitly use pointers as necessary. However, this code is not memory safe. For example, if we have the following code snippet:
we leak the chunk of memory corresponding to the node allocated to hold 0. This is because we didn't specify how the LinkedList class ought to clean itself up when it is deleted. This is accomplished by the destructor:
Ignoring the potential difficulties in implementing other Linked List functions with this recursive implementation of destruction, this does the job. Another set of things wrong with the translation are the assignments in the constructors of Node and LinkedList. They introduce unnecessary copying as, depending on the instantiation of the template parameter T, we may call a (potentially) expensive constructor twice. To get around this, we need to use initializer lists to iniitalize the members of a class:
We seem to be in the clear, but there are still more problems with this code. In particular, one of the strengths of C++ is being able to explicit allocate anything on the stack or the heap. Java only allows us to instantiate objects on the heap. Here we stack-allocate a LinkedList and copy it to another local variable.
However, now we have a problem. l1 and l2 both share the same nodes internally! This is because, by default, C++ shallowly copies class members during parameter passing, value returning, and assignment. In particular if l1 is deleted before l2, then l2 will be pointing to already-freed memory. To alleviate this problem, we need to implement the copy constructor and copy assignment operators:
Because the copy constructor, copy assignment operator, and the destructor all manage the resources held by the LinkedList and Node class, they all must be implemented together coherently (the so-called rule of three). So in summary, to translate this simple Java code into C++ correctly, we needed to understand:
In most treatments of C++, especially in the context of intro classes coming from Java, you only talk about the first three. The problem is that you need to understand it all to create a class that is truely memory safe. This is especially problematic as many people go through their entire careers not knowing that these considerations are not only vital but even exist at all! The flipside is that this is precisely the power of C++. If you understand the language to this level, you can begin to appreciate what C++ affords you that no other language in existence currently does. It goes beyond mere the low-level performacne, lulz arguments that most people trumpet about the language. | ||
Shield
Bulgaria4824 Posts
| ||
Phunkapotamus
United States496 Posts
| ||
Kambing
United States1176 Posts
To clarify: the primary libraries of GUI development in C++ are platform dependent. There exists platform independent solutions. None of these are part of the standard library which adds additional complications to development and deployment. | ||
LightMind
Singapore11 Posts
Which language would you recommend to go in depth with for self-studying during this summer holiday? And are there any books to recommend? Thanks! | ||
![]()
tofucake
Hyrule18982 Posts
| ||
mustache
Switzerland309 Posts
| ||
Vorenius
Denmark1979 Posts
I have two relations. goods (good_id, good_name, supplier) recepycomponent (recepy_id, good_id, weight_netto) I want to select the names of the goods that are contained in x or more recepies. Now I've managed to do so by first creating a view and then doing a select on it, but whenever I try to combine it into a single request I get a syntax error. Here's what I got:
While this does work I wanted it as a single query, without creating a view first. | ||
Perscienter
957 Posts
On May 14 2013 04:41 Kambing wrote: Frankly, there is little benefit to creating a gui app in C++ over Python. Python has the benefit of a cross-platform, standard gui library (tkinter). With C++, you are forced into platform-dependent solutions (Win32 or MFC on windows, Cocoa on OSX, GTK and others on Linux) although there are (non-standard) platform-independent solutions out there, i.e., QT. An app that requires a gui is also a sign (but not a necessary condition) that you do not need the low-level control that C++ affords you over a higher-level language like Python. Is that your theory? Tkinter is really unpopular amongst the Python community. It's still being used, because it's bundled with Python, but most veterans seem to prefer QT or wx. | ||
Kambing
United States1176 Posts
On May 15 2013 04:38 Perscienter wrote: Is that your theory? Tkinter is really unpopular amongst the Python community. It's still being used, because it's bundled with Python, but most veterans seem to prefer QT or wx. Yeah, Tkinter is shit. But it's strictly better than the nothing that is in the C++ standard library. Another thing to point out is that the requirement of a GUI should not be a compelling reason to choose one language over the other. If it does end up being a compelling reason (for lack of better reasons out there), then you are likely working in a setting where the higher-level language is more appropriate. | ||
supereddie
Netherlands151 Posts
On May 15 2013 04:15 Vorenius wrote: I was hoping someone more experienced at MySQL syntax could help me with a query. I have two relations. goods (good_id, good_name, supplier) recepycomponent (recepy_id, good_id, weight_netto) I want to select the names of the goods that are contained in x or more recepies. Now I've managed to do so by first creating a view and then doing a select on it, but whenever I try to combine it into a single request I get a syntax error. Here's what I got:
While this does work I wanted it as a single query, without creating a view first. Check out the HAVING clause: http://www.mysqltutorial.org/mysql-having.aspx | ||
Vorenius
Denmark1979 Posts
On May 15 2013 04:45 supereddie wrote: Check out the HAVING clause: http://www.mysqltutorial.org/mysql-having.aspx Of course. Got it now, thanks ![]() | ||
obesechicken13
United States10467 Posts
On May 14 2013 04:41 Kambing wrote: Frankly, there is little benefit to creating a gui app in C++ over Python. Python has the benefit of a cross-platform, standard gui library (tkinter). With C++, you are forced into platform-dependent solutions (Win32 or MFC on windows, Cocoa on OSX, GTK and others on Linux) although there are (non-standard) platform-independent solutions out there, i.e., QT. An app that requires a gui is also a sign (but not a necessary condition) that you do not need the low-level control that C++ affords you over a higher-level language like Python. Thanks. I feel like most applications have to be written to be platform dependent regardless. But I didn't know if C++ was like some competing language for developing small Gui apps. | ||
| ||