LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-10-2007, 08:05 AM   #1
rm_-rf_windows
Member
 
Registered: Jun 2007
Location: Europe
Distribution: Ubuntu
Posts: 292

Rep: Reputation: 27
Making beginner-level programming exercises more interesting and more motivating


I've learned a little C++ (very little), am starting to get familiar with the command line, but am getting tired of writing programs that are like math problems. What I'd really like is to have a look at some code and try to edit it and learn at the same time. Here's my question...

I've got several Linux boxes. Let's say I wanted to have a look at the source code of a very simple program, say, kwordquiz, which is a very simple flashcard program, part of the KDE edutainment or educational programs. I like kwordquiz, however, there are a few things that I'd like to change, for example, the default height of the lines of the editor, etc. Where, on a Linux system, is its source code? I'm on Fedora and Mandriva mainly, more on Mandriva. I can't find an /src directory. Where, for example, would the kwordquiz source code be? ... or the source code of any another program for that matter?

While I'm on the subject, does anybody know of a more interesting, more motivating way of learning programming skills (in general)? Bash scripts are interesting. It'd be cool to play around with them to customize the appearance and behaviour of my computer. I'm tired of programs which just launch a terminal and calculate the sum of numbers. How about something with colours and an interface or simple games? ... absolutely anything that makes it all interesting and motivating. I don't even care what programming language it is, however, knowing that I've gained some familiarity with C++ and bash, perhaps that might be a good place to start.

Can anyone send me a few links?

Many thanks.
 
Old 07-10-2007, 08:47 AM   #2
wjevans_7d1@yahoo.co
Member
 
Registered: Jun 2006
Location: Mariposa
Distribution: Slackware 9.1
Posts: 938

Rep: Reputation: 31
According to your profile, you've used Slackware. The source for everything built into a Slackware release is on their release CD's.

Maybe other distributions work the same way.
 
Old 07-10-2007, 08:50 AM   #3
[KIA]aze
Member
 
Registered: Jun 2006
Distribution: Debian, Ubuntu, Windows XP
Posts: 146

Rep: Reputation: 16
In Debian based systems, there's a great way of getting the source code:
Code:
apt-get source <package>
What's most motivating? Creating games I think.
Just try to create some simple games.

Otherwise it depends on you. Just try to program what you want to program (starting with not too complex projects of course) and learn along the way.

Last edited by [KIA]aze; 07-10-2007 at 08:52 AM.
 
Old 07-10-2007, 10:18 AM   #4
taylor_venable
Member
 
Registered: Jun 2005
Location: Indiana, USA
Distribution: OpenBSD, Ubuntu
Posts: 892

Rep: Reputation: 43
Quote:
Originally Posted by rm_-rf_windows
... getting tired of writing programs that are like math problems.
Oh, I was going to suggest Project Euler, that makes me interested in writing a bunch of code.

Quote:
Originally Posted by rm_-rf_windows
While I'm on the subject, does anybody know of a more interesting, more motivating way of learning programming skills (in general)? Bash scripts are interesting. It'd be cool to play around with them to customize the appearance and behaviour of my computer. I'm tired of programs which just launch a terminal and calculate the sum of numbers. How about something with colours and an interface or simple games? ... absolutely anything that makes it all interesting and motivating. I don't even care what programming language it is, however, knowing that I've gained some familiarity with C++ and bash, perhaps that might be a good place to start.
How about writing macros or functions for your text editor like Emacs or Vim. These are almost always immediately useful, and give you a little experience looking at source code.
 
Old 07-10-2007, 10:30 AM   #5
b0uncer
LQ Guru
 
Registered: Aug 2003
Distribution: CentOS, OS X
Posts: 5,131

Rep: Reputation: Disabled
Well if it's just that you want to learn programming, but don't care about which language it is (which means you have no idea what you're eventually going to program, at all), it probably isn't motivating. First you should come up with an idea (what to do, what to make better?), then sketch it to get the bones, then think about it more precisely and when you have an image of the complete thing, start writing it into the form of a program (oh, and after you know what you're doing you may think what's the best tool to make it).

Programming is basically more or less mathematics, with or without numbers. Computers work with numbers, after all, not colours nor interfaces. Interface programming (unless you use IDE, and maybe even then) can be tricky if you start off there, wanting to program Doom again. First it would be good to know some mathematics, how to deal with things - and how to represent them. Reading ready source code which is often sanitized, thick, sparsely commented, not meant for learning can be exhaustive for a beginner. It was for me, at least. Maybe you should start off with something easier than a ready KDE graphical app? As boring as it sounds, the easiest programs that teach you the beginning are "merely" command-line math apps. Knowing how lists work, how to deal with numbers and variables is the stone you build the rest on.

I agree that games are a good way to learn programming. But don't jump to 3d games right away, start off with something extremely easy - like a number game for example. Then gradually try to do more complex things. Eventually you'll notice you've done quite a lot of "math"
 
Old 07-10-2007, 10:33 AM   #6
95se
Member
 
Registered: Apr 2002
Location: Windsor, ON, CA
Distribution: Ubuntu
Posts: 740

Rep: Reputation: 32
If you want to stick w/ C++ I would try following some 2D SDL tutorials. While SDL is very powerful, it is fairly easy to graps the basics if you are a beginner. You should be able to create some fairly useful little games in not too much time.

If you wanted to learn some OpenGL, you can try to follow the NeHe tutorials: http://nehe.gamedev.net/
When I first started programming, much of that stuff was over my head, but it was good to basically copy paste, then try to modify.
 
Old 07-10-2007, 11:08 AM   #7
rm_-rf_windows
Member
 
Registered: Jun 2007
Location: Europe
Distribution: Ubuntu
Posts: 292

Original Poster
Rep: Reputation: 27
Wow! Lots of response to my questions... Many thanks to everybody...

I think I led some of you on the wrong track... I realize that programming is lines of code, maths, etc., and I do like that! Really!! It's the end product that I'd like to be graphical or at least a little more interesting. Very basic question: How do I get something that has a more attractive presentation than a terminal emulator to open up when I launch a program? Okay, I could create number games, but how, for example, might I get a wrong answer to be in blinking bold red characters and a sound to come on when the user enters the right answer? How might I create moving objects that can be manipulated with the arrow keys or the mouse?

I have learned some of the basics of programing (variables, etc.), and perhaps all of this is a little above me (or perhaps it isn't!)... How can I start doing something of this sort...

What I really need is some good links, some good sites that fill the gap between the beginner programmer and someone who can actually write real programs. Maybe there aren't very many out there. There are tons of sites for beginners, but I haven't been able to find sites corresponding to what I'm looking for...

Another idea: perhaps a list of programs (or mini-programs) whose source code are pretty basic and brief that I could toy with. The thing is, I have no idea what programs have code that is relatively easy to grasp (if any).

[KIA]aze,
Thanks for the tip about apt-get. Does anybody know how to do the same thing from other distros (yum, urpmi, etc.)?

wjevans_7d1@yahoo.com,
Thanks for the tip about the Slackware DVD. I had a look at the kwordquiz source code files. Cool! There are lots of them and I don't know how they work together to create a basic program... (Yet another question)... But it's motivating to know that I can check it all out and try to understand something! I couldn't find the Mandriva src directory, perhaps it isn't on their DVD.
 
Old 07-10-2007, 12:23 PM   #8
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
I think the best way to learn is to try to figure out how to do things yourself and when you get stuck look it up on the internet or ask questions here or comp.lang.c++.moderated. Slackware is great for programming because of Qt Designer/documentation, GTK documentation, and info:libc. If you are interested in a program, looking at the source is a great way to learn how others do things. I've spent a lot of time browsing kernel sources, program sources, and the STL headers. The reason I've been programming for 16 years and have only had one formal course is because tutorials and classes tend to make things entirely too complicated and they end up holding you back; they tend to cater to the least intelligent (in that area, that is) portion of their audience with little regard for those who want to burn straight through and get to the good stuff.

I say learn enough to be dangerous from tutorials, then experiment for several decades. You will figure out what you need to learn along the way if you stay interested in it that long.
ta0kira
 
Old 07-10-2007, 06:37 PM   #9
[KIA]aze
Member
 
Registered: Jun 2006
Distribution: Debian, Ubuntu, Windows XP
Posts: 146

Rep: Reputation: 16
Programs that are not too complicated?
Well, I think the the small games that come by default in Debian and Ubuntu are a good start.
Simple interfaces like GDebi might also be good.

I only discovered the apt-get source trick recently. But now at least I don't have to search for the tar.gz everytime.

I learned a lot from the "tuxtype" code (especially a nice trick for debugging) and this weekend I started modifying the source code of metal blob solid to move Bob around freely to find out where to go (ice levels are frustrating). I got the supertux code for the same reason but haven't done anything with it yet (there's a level editor for it that might also do, but where's the fun in that? ^^).

Oh, and if someone knows simple programs implementing MySQL, SQLlite or Boost.regex, I'm interested.

And you wanted links? Here:
What to start with if you want to make games
http://www.gamedev.net/
http://www.anjuta.org/documents/C/anjuta-tutorial/

I don't know what exactly you're looking for, so this is a quick mix of links I remembered. ^^

Things to google for:
*for games:
SDL
OpenGL
PyGame

*for GUIs
GTK+
Qt
WXwidgets

Last edited by [KIA]aze; 07-10-2007 at 06:56 PM.
 
Old 07-11-2007, 02:26 AM   #10
rm_-rf_windows
Member
 
Registered: Jun 2007
Location: Europe
Distribution: Ubuntu
Posts: 292

Original Poster
Rep: Reputation: 27
Thanks [KIA]aze !

Yeah, I've had a look at the source code for kwordquiz and, of course, there are lots of source files. I now realize that I have to go on a little further in my basic programming exercises to better understand how these files work together and to learn more about libraries. I'll be patient with the mathematical type programming exercises for a few more weeks and check out what you've sent me at the same time...

I do have a more general question, actually, a few questions. Now, I don't know if these questions are easy to answer or if all I need to do is continue studying on a daily basis to eventually learn how to do this, but if I could to some of this fairly soon, it would certainly motivate me.

Here are my questions:

- How does one know what is where in a source code directory (there are so many source code files and other files in there!); e.g., the kwordquiz source code directory or any other similar directory. Is there a site that explains the conventions used to quickly understand the mapping out of these files? How about the extensions? .cpp is C++, etc. but how about the rest?

- This might be really easy or quite difficult, I have no idea. Let's say I wanted to do a simple hello world program in C++, but I wanted to make my own interface and include a background image. Is this easy to do? ... or do I just need to be patient... and I'll get to it eventually in lesson 28 of my C++ tutorial (lol)...?

- Lastly, little extras like the previous question might motivate me, that is, using what I already know and adding a few elements to make the final product a little more appealing, a little more pleasant to look at and to use... (Again, I don't know if this is possible...)

Thanks again for your last reply. I'll go over the links you sent me more carefully when I get back, I've got a few errands to run...

Many thanks.
 
Old 07-11-2007, 03:43 AM   #11
[KIA]aze
Member
 
Registered: Jun 2006
Distribution: Debian, Ubuntu, Windows XP
Posts: 146

Rep: Reputation: 16
Quote:
- How does one know what is where in a source code directory (there are so many source code files and other files in there!); e.g., the kwordquiz source code directory or any other similar directory. Is there a site that explains the conventions used to quickly understand the mapping out of these files? How about the extensions? .cpp is C++, etc. but how about the rest?
*Extensions:
.c,.C= C source file
.cpp,.CPP=C++ source file
.h=C or C++ header
.hpp=C++ header (generally for classes, is paired with a .cpp with the same basename)
.cxx,.hxx=I think I saw them once, probably also C++ source/header files

*How to find out where what is:
If it's well documented and the folder/file names are obvious, no problem.

If it isn't well documented by the creators, use grep.
Code:
grep [-r] <pattern> <file>
grep -r foo * =>search recursively for "foo" in all files
See "man grep" for more info. Another option I find useful is "-i"=ignore case.

I recommend Kate as an editor. It has an inbuilt terminal and "find in files" function (GUI frontend to grep).
Other well-known editors are Vim and Emacs/Xemacs, but they take more time to master.
You can of course also use an IDE (see below).

Quote:
- This might be really easy or quite difficult, I have no idea. Let's say I wanted to do a simple hello world program in C++, but I wanted to make my own interface and include a background image. Is this easy to do? ... or do I just need to be patient... and I'll get to it eventually in lesson 28 of my C++ tutorial (lol)...?
I don't think you'll learn that in a C++ tutorial.
The only possibility I see of creating colored/blinking text in a console would be to use escape sequences. It is easy to do in shellscripts and would therefore be possible by using system calls in a C/C++ program.
I think it's also possible with printf(), but I have never tried it. (will have to do that...)

To create an interface, the easiest way is to learn a GUI toolkit like Qt, GTK+ or WXwidgets.
If you want to draw the interface yourself, use a graphic library like SDL.
Google for a tutorial on those libraries/toolkits and learn.

Quote:
- Lastly, little extras like the previous question might motivate me, that is, using what I already know and adding a few elements to make the final product a little more appealing, a little more pleasant to look at and to use... (Again, I don't know if this is possible...)
Of course it is. Just requires some learning.

Here are some things that might help you:
GUI builders:
http://www.linuxquestions.org/questi...d.php?t=557967

Formatting (make code look good):
Try astyle.

Help on compiling and small list of IDEs I just copy/pasted from one of my posts on the Ubuntu forums:
Quote:
Originally Posted by KIAaze View Post
Read the manual:
Code:
man gcc
Code:
man g++
Ok, now that was the brutal not so helpful response. ^^

Here's a more helpful one:
To compile a simple hello world program:
-C code:
Code:
 gcc -o hello hello.c
-C++ code
Code:
 g++ -o hello hello.cpp
Optionally, you can also simply use:
Code:
make hello
if the program is named hello.c or hello.cpp.

make is normally used with a Makefile which contains all the necessary compilation info (for libraries, etc).

Have you already programmed in C/C++ before or not?
If not you should of course also look for tutorials on the net.
And if you don't know it yet, here's an extremely useful link when programming:
http://www.cppreference.com/index.html
(There is even a Firefox search plugin for it!!!)
TIP: Typing man <function/header> will give you info about C/C++ functions and headers.
Very useful when you are offline.


Now assuming you know how to program in C/C++:
If you are using libraries, use the -L and -l options:
Code:
 g++ -L/lib_dir -lmylib -o hello hello.c
To include headers, use the -I option:
Code:
 g++ -I/header_dir -o hello hello.c
A very useful thing when creating huge programs is the Makefile.
It allows you to compile a program by simply typing "make", install it by typing "make install", remove all compiled files by typing "make clean".

Looking for an IDE? (i.e: click on button to compile ^^)
Now if you want to use a GUI for creating your program like MS Visual C++ or Borland C++ under Windows, you can do so under GNU/Linux.
Here are some IDEs (Integrated Development Environment) for GNU/Linux:
-Anjuta (Only one I really used until now. Very practical to create GTK apps with Glade. )
-Code::Blocks (cross-platform)
-KDevelop (has an RPM creation feature, but I have been unable to find a .deb creation feature )
-Eclipse (java-based, so it might be slow, and i's also more java oriented. I never really managed to compile something with it... Seems bloated and complex. A lot of people say it's great howvever. :/)

See also:
http://en.wikipedia.org/wiki/Compari...t_environments

Most, if not all, IDE under GNU/Linux automatically create a Makefile for your program.

[Under Windows there is also DevC++ if you are looking for a free one.
Code::Blocks also works under Windows.]
http://ubuntuforums.org/showthread.p...ghlight=anjuta

Last edited by [KIA]aze; 07-11-2007 at 03:57 AM.
 
Old 07-11-2007, 08:01 AM   #12
rm_-rf_windows
Member
 
Registered: Jun 2007
Location: Europe
Distribution: Ubuntu
Posts: 292

Original Poster
Rep: Reputation: 27
Thanks [KIA]aze !

Thanks for all of the advice, your suggestions, tips and links. I think I've got enough information now... which will keep me busy for at least a few weeks. Thanks so much.

P.S. - And thanks to everyone for their general advice and comments too !
 
Old 07-11-2007, 08:08 AM   #13
wjevans_7d1@yahoo.co
Member
 
Registered: Jun 2006
Location: Mariposa
Distribution: Slackware 9.1
Posts: 938

Rep: Reputation: 31
Quote:
which will keep me busy for at least a few weeks
I guess you got that right. (grin)
 
Old 07-12-2007, 05:04 AM   #14
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
Here's a couple of slightly lateral suggestions.
1. try and find something you want doing for yourself eg a game or Cd management system.
2. Try and solve real probs on sites like this that other people have posted.
There's a lot of prog help wanted sites like this, and even if you don't come up with a complete soln, you'll learn a lot by trying and by reading other peoples solutions/tips.

These pretty much apply to any IT skill.
 
Old 07-12-2007, 07:08 AM   #15
[KIA]aze
Member
 
Registered: Jun 2006
Distribution: Debian, Ubuntu, Windows XP
Posts: 146

Rep: Reputation: 16
Printing colored text on a colored background with a special style with just printf?

Found it:
http://linuxgazette.net/issue65/padala.html
This should be easier than learning how to use other libraries first.

Now I learned something new too along the way.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Best beginner book for C programming? rmy1 Programming 21 01-18-2010 07:14 PM
help in beginner x lib programming ... alred Programming 3 04-26-2006 11:02 PM
Request:Interesting Intermedia level C E-Books indian Programming 1 04-21-2005 02:49 AM
programming beginner darksvr Programming 6 09-11-2003 02:05 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:03 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration