Golden Rule for Programmers

Golden Rule for Programmers

I came across a quote today that beautifully illustrates a very real idea in both programming and life:

“As to methods there may be a million and then some, but principles are few. The man who grasps principles can successfully select his own methods. The man who tries methods, ignoring principles, is sure to have trouble.” -Ralph Waldo Emerson

You must know HOW to program before you can build something amazing. Just as you wouldn’t try to build a car by welding together wreckage, you will be doomed for failure if you try to write software by piecing together other people’s code.  Code reuse is excellent, but this is not a substitute for real knowledge.

Is Python any good for GUI development?

*************I’ve made numerous UI’s in wxPython and would highly recommend it. I used to build in VisualC++/MFC then discovered wxWidgets/C++ and finally moved onto wxPython. I find I’m able to get working GUIs in no time at all with wxPython compared to the other methods and with almost no effort, the same source works works on Linux and the Mac* (sometimes you need some tweaks for visual anomolies). *I generally develop under Windows in case you hadn’t guessed. There’s a tool (wxDesigner) you can use to generate the layout for you or alternatively, you can play with it programmatically. Either way, layout under wxWidgets is done using Sizers. They’re quite a powerful way of laying out a GUI and once set up correctly, will automatically resize your controls appropriately for you. There’s a nice little tutorial on sourceforge with some good examples of what you can do with sizers. There’s another tool (wxGlade) I’ve just discovered which does what wxDesigner does, but for free from a quick trial, might actually be better as well.

****wxPython is the best and most mature cross-platform GUI toolkit, given a number of constraints. The only reason wxPython isn’t the standard Python GUI toolkit is that Tkinter was there first.

– Guido van Rossum

******While I respect his opinion greatly, he doesn’t strike me as the sort of person that does very much GUI programming. If I didn’t do much GUI programming I’d vote for wxPython too. It has more eye candy, but I’m not convinced it’s superior to Tkinter.

*******You could try PyQt This uses the Qt toolkit for the GUI but you write your program in python. Qt Designer can be used to create GUIs graphically for use with PyQt. Qt Designer is the GUI building application for Qt. The python bindings for Qt are fine. If you want to take a look at current Qt applications you may checkout Google Earth and Skype.

*******There are excellent GUI options for Python. wxPython is a great place to start, pyQT is good if you have spare money.

The biggest issue I’ve seen is having a tool that lets you layout a form with the ease of Visual Studio — but I think pyQT has that one resolved, and wxWindows has a version you can pay for.

******To asnwer your question directly:

Yes, Python is excellent for GUI development. Python is dynamic and extremely flexible, traits that are very important for GUI development where one often needs to write a lot of boilerplate code. The bindings for some popular cross-platform GUI libraries (wx, Qt, etc.) are mature, stable, actively developed and well supported.

I’ve found performance of Python GUI bindings to be good (I’m personally using wxPython and have already written a few functional GUIs both for work and personal use). But if you want to improve it even further, I’m sure it’s not too hard to combine the Python binding code with C++ code (using the wxWidgets C++ libarary itself, for instance). Anyhow, I suspect this won’t be a problem for you.

******************As others have said, wxPython is a good GUI library. One thing that isn’t mentioned much is that you can combine wxPython with wxGlade to create many “drag and drop” programs.

wxGlade lets you quickly create the framework of your program; you don’t have to worry about any of the working code at first. You can just create the visual look until you get it just right. Once that’s done, then you start working on the actual coding, but you already have the GUI framework laid out for you. All you have to provide is the programming logic to make your application work.

One benefit of using Python for applications in general is the interpreted environment. You don’t have to do the check/compile/run cycle everytime. You can quickly make changes and see them nearly instantaneously, which greatly speeds up development.

Additionally, if you need to speed up the program, you can always write certain parts in C/C++ and pre-compile them. The cPickle module is an example of this. But for many GUI programs, the application will be waiting on the user so speed is usually not an issue.

**********Another good wxPython tutorial:

http://zetcode.com/wxpython/

********wxPython is full of bugs on anything besides Windows. PyGTK2 is probably the best GUI toolkit but I don’t know on what platforms it is supported, probably everywhere gnome is.

********** I’ve actually done similar research lately as many of the artist I work with work on Macs. What I found is that wxPython seems pretty robust. My goals were for internal tools development, so I was looking for a more efficient development language than C# and Java.

I’m not an expert in wxPython, but if you are interested in GUI development in Python, I would give this API a try, or at least some research time.

******* Check out the Traits library from Enthought. It’s a way of describing different properties of objects, views of those properties, and dynamically updating views. I’m not really doing it justice, but it’s an extremely flexible, rapid-development library. Plus, it leads to reusable and extensible code. I’ve written a couple minor scientific applications in Traits, and I have found it to be an absolute dream, as it lets me focus on the data model rather than the UI.

***********Python is excellent for gui development
Speed of execution is less important than speed of development, GUIs change a lot. GUIs generally involve dealing with text and storing state – ideal pythonisms
If your app is in c++/c#, then having the gui written in a different langauge enforces gui/logic separation.

Options are: wxpython/pyQT – equally good, all the functionality of wx/qt from python, both the designers can spit out native python implementations.

IronPython – .net implmentation of python so all winforms and wpf directly from python. You get all the .net libs but only a subset of the native python ones, but it is very easy to mix python gui with other parts of the app writen in c# etc.

************You should take a look at IronPython. With it you can use the .NET Framework and I’m pretty sure somehow Mono too!

http://www.google.de/search?hl=en&pwst=1&sa=X&oi=spell&resnum=0&ct=result&cd=1&q=ironpython&spell=1

*********I personally find wxPython to be very clumsy. I’ve encountered many bugs while trying to use it and the backwards compatibility issue is quite bothersome. I guess that’s a complaint about python in general though.

Edit: More specifically, you have to actually uninstall a current version of python and install an old version to get some programs to work properly. I believe it was one of the programs I was using with Z/Eves. It’s been a few years.

**********With jython you could use Java Swing. 100% cross platform and everybody loves swing – right ;-)

Ramblings on C language

*****************other users advice on learning  C***********************

******A lot of people try to tackle C programming without first understanding what a processor is or how it operates (at a detailed level), and they’ve certainly never written any machine code or assembly language. Once you’ve done that a couple of times, pointers instantly make sense. But its just not necessary in a lot of new languages, so its just not taught.

******It seems to me that before learning any programming language you should learn the basics of CPU design. Things like registers, memory, stack, I/O etc. Having a grasp of those would certainly help in understanding all language concepts.

*****The thing with pointers is that they are literally the metal of the computer; you can’t get much lower, without getting into assembly and dealing with registers, etc. It might be confusing for people who learn pointers just dealing with simple objects, e.g.:

int x1 = 10;

int *x2 = (int *)malloc(sizeof(int));
*x2 = 10; free(x2);

Why go through the trouble of dealing with pointers, de/allocation, casting, and dereferencing here, especially if you learned some higher level language first? If your first language is C or assembly, then yes, your mental model of how memory works is probably much clearer than that of most freshmen in their intro C.S. class, whether they did any programming in HS or not.

With respect to python, it really is touted as a batteries included language; the smtp libraries are obviously not part of the language spec or something, but you would have to really go out of your way to get a python version without the required libraries. In the worst case, you then would use easy_install to get them.

Regardless, I think it would be difficult to make the case that C has a lower barrier of entry or easier learning curve than Python (or most newer languages). Yes, if you are CS student you need to understand memory, etc, at some point. For whatever reason, pointers ARE hard for most people when they are first encountered. The first exposure to programming is almost always “hello world” and you don’t really need a deep understanding of C to start expanding this concept. Even allocating strings can be done without too much thinking. It is when you start writing functions that alter the arguments, or using arrays, that you can’t really fake it any longer. After working with pointers daily for years, I think we take for granted what they are and how they are used; it just takes time to “click” for most people, I guess.

************Can someone please tell me, what exactly is so “difficult” about C?

Let me see… String manipulation? Manual memory management? The cryptic compiler messages?

Note that these things are not difficult for YOU, they are difficult for the novice programmer. After doing something for 20 years, of course it will be easy!

**********C programming is not significantly “harder” than other programming languages. It’s just more tedious. That is, there are a lot more manual steps you have to perform. I suppose if you have trouble keeping all those details straight without getting stuff wrong, then that tedium does translate into added difficulty.

And FWIW, I’m not trying to defend C as being just as useful/powerful/etc as other languages. I myself have grown really tired of writing everything in C, and have actively sought out other languages that free me from writing all that repetitive code. This is especially true when it comes to writing user interfaces. I spent the first 8 years of my career creating Windows GUI apps, almost entirely in straight C, writing directly to the Win32 API. Pure Petzold style. And not surprisingly, I grew really tired of doing all that repetitive code, even when all I needed was a simple GUI with maybe a main window and a couple dialog boxes. I’m actually a strong proponent of languages like Python that free programmers from having to spend so much time on such mundane things as allocating memory, handling scrollbar event messages, etc.

But, I still believe that any professional programmer worth his/her salt ought to not shy away from learning things like pointers, etc. For people in other fields that only use programming as a tool, and need to be able to focus on their core work, I think choosing a language that lets them avoid stuff like that entirely is a good decision. I don’t have any problem, for example, with a scientist not wanting to have to learn about pointers just to be able to do some matrix multiplication, as is the case with another commenter who replied to me.

***Video game development requires the highest level of math ability. You will need to take Calc 1, Calc 2, & Calc 3. Physics with Calculus, & Differential Equations. I’m sure there are other scary courses that I’m overlooking.

*******C Language and GUI Development**************

*hello everyone. Can somebody tell me the GUI development library that people would usually use to develop ubuntu applications?

*There are quite a few GUI frameworks available for Linux. There is WXwidgets, GTK, QT, fltk, and a few others. Google “GUI frameworks for linux” to start.

*Which of them is most popular ? Which of them do companies expect us to know ?

*Companies will expect you to know the framework they are using, even if they are the only ones using it.

As for which is most popular? I would suggest familiarize yourself with several of the frameworks. This way you increase your prospects.

***Define “popular”
- used by the most programmers
- used in the most applications
- ported to the most operating systems
- used by the most users.

A single programmer, using their own toolkit, who writes one killer app that everyone simply has to use it might score option 3. But does that make it the most popular?

> Which of them do companies expect us to know ?
The first thing companies want to know is if you can program.

Then have some basic understanding of the concepts behind GUI toolkits. Many of them share common themes.

The rest is bookwork.

Hell, I can barely recite about 10% of the ANSI-C API. But what I do know is what is there, and where to find out the detail (aka, the manual).

So memorising vast swathes of some GUI toolkit API will just make you a “manual on legs”, not necessarily a competent programmer.

**Also, the more frameworks you familiarise yourself with through actually developing with them, the easier it is to get to grips with a new one.

******************************************************************************************************************************
****How can I do GUI programming in C(Windows)?

A C compiler itself won’t provide you with GUI functionality, but there are plenty of libraries for that sort of thing. The most popular is probably GTK+, but it may be a little too complicated if you are just starting out and want to quickly get a GUI up and running. or try win32.

**************************************************How does a GUI Framework work?

**********I have been all over the web looking for an answer to this, and my question is this: How does a GUI framework work? for instance how does Qt work, is there any books or wibsites on the topic of writing a GUI framework from scratch? and also does the framework have to call methods from the operating systems GUI framework?

*********A GUI framework like Qt generally works by taking the existing OS’s primitive objects (windows, fonts, bitmaps, etc), wrapping them in more platform-neutral and less clunky classes/structures/handles, and giving you the functionality you’ll need to manipulate them. Yes, that almost always involves using the OS’s own functions, but it doesn’t HAVE to — if you’re designing an API to draw an OpenGL UI, for example, most of the underlying OS’s GUI stuff won’t even work, and you’ll be doing just about everything on your own.

Either way, it’s not for the faint of heart. If you have to ask how a GUI framework works, you’re not even close to ready to design one. You’re better off sticking with an existing framework and extending it to do the spiffy stuff it doesn’t do already.

****Building a GUI framework isn’t a 1,2,3 process.

All I can say is, take a look of some of those open source IDEs, like Netbeans source code for example.

Look inside the code, and then build the whole IDE.

***********I haven’t used NetBeans but I looked at a few screenshots and it appears to just use Swing – I don’t think this would give a good example of developing a UI framework since it simply uses an existing one, not implements its own. GTK+ (gtk.org) would be a good example.

Today

Down with C up With Python!

It has been decided C is simply too much for me as a beginner in the world of programming. I have the experience to say this because i have tried mutliple times using as much resources as possible to aid in my learning and still I did not get anywhere. asking somebody wont make any difference. i personally have the belief that C programming is not for beginners and whoever says otherwise is coming from an already experienced,advanced programming background. as for me i know definitely that programming is no bed of rose no matter which language i switch to. but based on the introduction that i have started today in Python. i am elated to say i feel more comfortable both mentally and visually learning python than c. it is more beginner-friendly than c. and they are saying that C is by nature more faster than python. but i don’t care. the point of my learning is to learn how to program(or script). i want to make stuff and see results. why should something be so complex? i tried very hard to understand the basic syntax of C and i dont have a clue what they mean. I tried videos, tutorials, books….still no luck in my progress. Now do not get me Wrong i Respect C! it is a foundational language(other languages were derived or developed from it).and i promise to return to it once i gather sufficient experience.certain operating systems like windows,unix and linux, drivers and applications are written partially or fully in C. It gives you more control over the computer system as experts declare but strict on syntax…and some other things that ive experienced with it. that makes my head and my eyes sting with pain,frustration and confusion. i cannot understand i am doing when i try to make programs in c. i see the myriads of tutorials on the web for c and they dont do jack shit to cure me of my bewilderment. it would seem as if i prefer scripting more than full blown programming. i am also informed that the difference between scripting and programming is so minimalized right now that php is now used to write complex software(the kind of work that only full blown programming languages would have been able to do in the old days). with faster, more powerful computers,calling it scripting or programming doesnt matter anymore because they both are now on an equal footing in getting the job done! If my efforts to master python to a certain degree succeeds, it can help boost my chances for career opportunities! and i want to explore web development next. i know that giving up may look like a sign of spinelessness or indolence. but i dont like the idea of struggling with something for so long and still  you have no idea where to start with in it. Call a spade a Spade. it makes no sense we struggle with something we just dont have what it takes to deal with or master. It is like a 6 year old child trying to learn calculus.mathematics(which i hate to this day) has not given me so much trouble and headache. in fact i would rather choose mathematics over c programming right now! at least i would have an idea of what i am trying to do when i approach complex problems and get better help solving them with the help of feedback and resources!


Follow

Get every new post delivered to your Inbox.