Programming question

I am looking into writing some code. I’ve been interested in learning C but have found it difficult to find tutorials that are C specific. Most of what I find is C and C++. Now I’m a n00b when it comes to programming but do I need to learn both?

I seem to have found one tutorial (http://winprog.org/tutorial/) that shows some examples of using the Windows API but all other tutorials seem to be oriented towards C++ so I am thinking that this one is also…

I don’t know much about programming so I was going to start in Windows because my laptop has XP installed and this is the machine I carry around with me.

I’ve gone through some basic C tutorials that were terminal/command line oriented so I’m starting to catch on to the basics.

What should my next step be? Should I look into C++ for GUI programming, will C work for GUIs, or should I stick to command line stuff for now?

Just looking for a little direction. Thanks!

~TheNerd

Disclaimer I don’t program as much as I’d like to anymore, doing a lot more Sys Admin work. I also only ever worked on the Apps side of things, never the OS level, so please keep that in mind.

Depending upon what you want to do, what and how much you learn to program will vary. If you just want to do some data processing type programming, you might be more interested in learning some shell scripting. It might not be pretty, but it can do amazing things, and you can grab cygwin to learn, or use knoppix on CD (but that takes a reboot).

If you’re interested in something with more power, and are sticking to Windows, I would recommend Java. Might not be supported on Haiku yet (or possibly ever, who knows). It is fairly easy, teaches the basics of program flow and OOP (Object Oriented Programming), is platform independent, has a lot of tutorials, a well documented API, the Eclipse IDE (or NetBeans is free now I think, nice GUI editor in there), and is pretty similar to C++.

If you go that route, and want to program for Haiku, I’d recommend “C++ for Java Programmers” by Mark Allen Weiss; it’s a very easy read and has some good examples once you feel comfortable with Java. From there, “Programming the BeOS” linked from this site is probably the next step.

Whatever route you go, remember to keep your expectations reasonable. Don’t expect to be able to create the ‘Killer App’ in 3 months, it’ll just drive you away. Find achievable goals and take pride in what you’ve done. A command line program that takes in RGB values and builds a simple web page showing them off in Hex is not difficult, but it’s a good ‘I Did It!’ program to learn with. Also, play with whatever tutorials you do. Push them. Try out everything you can and see what works and what doesn’t. More applications have been built from a simple ‘Hello World’ base than I think most IT managers would like to admit…

What your goal is will dictate what you learn more than anything else. If you want to learn to write drivers, C would probably be the thing to learn (although it sounds like the Haiku devs are doing some crazy low level stuff in C++). If you want to make cool GUI apps, C++ (or Java) is probably a better fit. If you want to parse and clean up log files, scripting is the key. Each of these examples has a lot of exceptions, but the languages you choose to learn are just tools to reach your end. You wouldn’t dig a hole with a hammer, or drive nails with a shovel, you could of course, but you use what’s best for the job at hand.

my eventual goal is to get comfortable enough so that I can write some Haiku code. It might take a while to get there but it would be a good skill to have. I know there are already some tutorials on the site but I find it difficult to use them since I don’t know enough about the basics.

Thanks
~TheNerd

I would highly recommend Sams Publishing’s Teach Yourself C++ in 21 Days. Also, if you want to get into Haiku coding, I’d also recommend getting a PDF of Programming the Be Operating System from Peachpit Press. I wouldn’t bother learning Windows’ APIs if you plan on just coding for BeOS / Haiku. Windows is ugly. Very ugly.

I don’t plan on strictly programming for Haiku. I would like to do some Windows stuff too.

I have a friend to told me today the he has an old Sybex C++ book from 1998. Would this be something I could use or should I get a newer one? Looking through the book it references old versions of Borland and MS Visual C++ so that might be a bit confusing…

Thanks for the advice :slight_smile:

~TheNerd

A good C++ tutorial that just uses the commandline is actually not a bad idea… You focus less on all the fancy non-core stuff like a GUI and you get to focus just on the core concepts like loops, variables, pointers, classes, polymorphism, and so and so on. One word of warning… don’t get stuck in learning all of the little nuances for the command-line (like different ways of getting and displaying data on the command-line), since if you only want to do GUI stuff, that’s pretty much wasting your time when you could be learning the core stuff.

BTW, avoid those overly huge, several hundred page, has every feature in C++ books to start out with. Instead, you want a tutorial – something that focuses on one concept of the core language at at time and teaches it to you well. Although I never finished it, one book that I liked was called: “Rescued by C++” though it probably could have done better in explaining pointers. In fact, I think this book truly represents how a tutorial and/or introduction to a programming language should be done. (A good tutorial will focus on one concept a time and thoroughly teach it to you.) On another note, I have seen the “visual” books recently that teach programming in a visual style, with many visuals/pictures. Although I’ve never tried one, and I’m not sure if they work good for something like C++, they look like they would be an awesome learning tool for some things (especially stuff like html, css, etc… which are very visual).

Chip/Kevin, thanks for the advice.

I don’t think I want to go as low as coding drivers but would like to make some small GUI apps to start. I don’t have anything in particular in mind at the moment but I’ve always wanted to program and just never really got around to it now (except for some PHP/MySQL, HTML, CSS for one of my jobs and my personal sites). Shell scripting is not that difficult and have been able to do accomplish some minor tasks with that for my own personal use.

I considered Java as well but some of my colleagues at work kind of turned me off of it. Since it is platform independent it would be a good place to go I guess but I still think C/C++ is what I would like to do.

As suggested I’ll get myself a copy of BeBook and take a look. I’m also going to take a look at the various C/C++ (maybe even Java) books at the local book store the next time I go. Maybe I can find one that will be fairly intuitive.

I know everyone probably has a different opinion on the subject but I really appreciate all the advice/suggestions. It should help me make a more informed decision :slight_smile:

~TheNerd

Since you have some background with web apps, and want to make the transition to desktop, the biggest difference I think you’ll find is the OOP side of things. PHP is great and it’ll teach you the basics of how to achieve the end you want progromaticly, but it’s much more procedural. I never really used it for anything more than quick and dirty CRUD web apps, so I can’t tell you if it has anything like ColdFusions CFCs (classes in OOP).

If you have some C++ folks at work, see if you can get them interested in helping you to learn. I like Java, but that’s just where I cut my teeth. I’d suggest getting a VM of Haiku set up on your laptop and working through “Programming the BeOS”. Take what you’ve come up with and show it to the guys at the office and see if any of them could help you to improve what you’ve built; you never know, you might make a convert or two, or three, or … :wink:

Before you buy any books, work through a couple of tutorials online and critically judge how you’re doing. See where you feel you need more focus and practice and see if any books address those points. And look at the thinner volumes, you can often gain more in a small practical guide than in a phone book of all the options potentially available. Books are really good for reference, but experimentation will teach you what works better.

Darn it! Now I want to start programming again. Thanks TheNerd…

For me there are 4 aspects to programming:

  1. Being able to solve a problem by breaking it down into smaller problems and solving each one of those. This is language agnostic and includes general concepts like conditional statements (if and else), loops (while, for), the general idea of variables and boolean logic (true and false = false, etc) and the idea of classes, objects, methods and functions.
  2. Being able to use a specific programming language by knowing its general syntax.
  3. Being able to write a specific programming language using the proper idioms and concepts so your code looks like it fits in with code from skilled programmers in that language.
  4. Being able to program against a specific API (Application Programming Interface) and knowing how to properly use that API.

The first item is a general skill that you really just need to learn once. Some people are “naturals” at this and can learn it quickly. These are usually people who naturally gravitated towards programming and made it a profession (I’m one of these.) But many people may have the aptitude but have never tried it. Anyhow, whether you are a natural or not, I think anyone can learn these concepts, and once you do learning new programming languages isn’t too hard. In this step it might be wise to use a higher level language and I highly recommend the scripting language Ruby. In fact you can Try Ruby right now without installing anything.

Item 2 is where you need to pick a language to learn based on your goals. I still think Ruby is a good place to start at first, but since you want to one day write Haiku applications C++ is probably your best second language (BTW I eventually plan to make a Ruby wrapper for the Haiku API, meaning you could make Haiku applications in Ruby…one day.) A lot of people like to say that C++ is just C with classes, but that really isn’t true anymore. C++ is a lot more than that and it is probably better for a person new to C++ to start with C++ and not “muddy the waters” by learning about C first. There are plenty of introductory texts about C++, and your local library probably has plenty to offer for free.

Item 3 takes a little time to learn and you need to have Item 2 down before worrying too much about this. In case you are wondering what I mean in this item, well basically every language has “idioms” above and beyond its basic syntax that all “good” programmers in that language use. For example in Ruby a novice might loop over an array using the “for item in array” syntax, but most experienced Ruby programmers prefer the “each” method. There are similar idioms for C++ (many actually) and for every other language. A book which is FANTASTIC for C++ idioms (and general good advice) is “Effective C++” by Scott Meyers. I actually just started reading this myself and it is great. It is well written and pretty easy to read considering the topic. There are a lot of good examples in it too so you can see some code in action.

Item 4 is probably one of the more annoying aspects to programming, because there are literally thousands of APIs in the world. The difficulty of learning new APIs is why so many programmers become so passionate about their “favorite” platform. Fortunately for you the Be API (and by extension the Haiku API) is a very good one and well worth learning. Dan Park Sydow’s “Programming the Be Operating System” is a good introduction and will get you up to speed pretty quickly (once you have the C++ basics.) I actually have a paper copy I got on sale at CompUSA a few years ago, but the PDF version is on this site. BTW even though I put Item 3 before this one, I think this one can be done before learning idioms in detail.

Another interesting thing is that APIs can sometimes be language agnostic. For example if (or when) I make a Ruby wrapper for the Haiku API the basic concepts will be similar to the C++ version. In fact right now you can write some pretty complex Ruby programs which use the GTK+ API, the Windows API, and many others. I wrote a Ruby program at work which uses the GTK+ API to create a web browser that embeds Firefox and takes screenshots of web pages. I use this program remotely from a Ruby on Rails web app by telling it to produce a screenshot for a given URL and it returns the PNG screenshot (like I said Ruby is really cool.)

To conclude, programming can be very rewarding, but also has its shares of frustrations (coughWebKit portcough), but when you see your own code working it is all worth it. Plus you can scratch your own itches.

Ryan, that’s exactly the type of info I was looking for (no offense to the rest, your advice/suggestions we enormously helpful as well)!!

[quote]For me there are 4 aspects to programming:

  1. Being able to solve a problem by breaking it down into smaller problems and solving each one of those. This is language agnostic and includes general concepts like conditional statements (if and else), loops (while, for), the general idea of variables and boolean logic (true and false = false, etc) and the idea of classes, objects, methods and functions.
  2. Being able to use a specific programming language by knowing its general syntax.
  3. Being able to write a specific programming language using the proper idioms and concepts so your code looks like it fits in with code from skilled programmers in that language.
  4. Being able to program against a specific API (Application Programming Interface) and knowing how to properly use that API.
    [/quote]

This give me lots of direction. Now I have a better idea of how I need to proceed with my learning.

The detailed explanation is great :). I’m thinking that the language itself is one of the easier parts to learn. The analyzing and thought process seems to be what needs to really be nailed down first (am I way off?).

I hope this topic will also help others who may not have wanted to ask this type of question.

Thanks a million folks!

~TheNerd

Ryan makes some good points. I know that once I had a grasp of programming concepts, I was able to jump in very, very quickly into other languages like PHP and Python. (BTW, Python has an excellent system of well documented libraries for a scripting language – makes making a quick script so much faster.)

Anyways, one thing that might be interesting is to tell us the specific type of programs you want to make. Then, maybe we can suggest a particular language and you can just jump right into that one directly without bothering with any others. :slight_smile:

BTW, if it is of any interest to anyone, while it is true that many languages share common concepts (and many even have very similar syntax), there is a growing popularity among a new breed of rarer used languages like Lisp, Erlang, and Haskell. Many of these languages are very powerful, and some require a totally different way of thinking about programming that do not carry over very well from c style languages. Note: there are still many concepts that do carry over, but there are also vastly different concepts that are not very common in the regular languages.

That is actually one of the things I am currently trying to sort out. I don’t know exactly know what I want to program. I would like to start off with a small notepad like app (most tutorials I’ve seen show how to write one anyway). I maybe even like to work on a small media player. Those would be a couple of things I would maybe try out to start, although I don’t know if the media player is too complicated for a beginner.

Does anyone have an idea of a good app/program to start out with?

I assume none of these are available in Haiku yet but would one of these be a good choice for GUI programming? Could a beginner learn these or should these only be used with some other programming experience?

Thanks again :slight_smile:

Why not try Yab, it works on various platforms (Yabasic on windows and linux). The Yab package for BeOS/Zeta/Haiku has a nice gui included. To me it resembles Visual Basic for M$. An easy way to create great programs for Haiku and Windows alike. Try these links-
http://www.team-maui.org/projects/yab
http://besly.de/
http://www.beosmaxfiles.org/
http://haikuware.com/

haikuware’s and beosmax’s images both contain Yab.

It’s funny that I never thought of Yab since I knew it was on the Haikuware image. This might be a viable route to take. At least it would get me into some programming quickly. But I’d still like to learn C++.

Another great pointer. Thanks!

~TheNerd

seach bebits for yab quite a few apps are made with it, such as Mybudget, see - http://www.thaler-online.com/flojo/?page_id=4 . Also Vasper’s Dungeon Master roller app is made with it. Even Yab’s IDE is made with it. One thing is wrong with Vaspers precompiled package though. See here under EiGHtBiT’s comment - http://haikuware.com/index.php?option=com_remository&Itemid=38&func=fileinfo&id=74

I did some digging around and found some Yab tutorials. I think I might start with this just to get myself familiar with programming and some basic concepts. From what I can tell Yab is built for Haiku, BeOS and Zeta. Are there any implementations of Yab on other systems (I.e. Linux or Windows)?

Thanks!

~TheNerd

Well, I’ve ordered a Ruby book…let’s see how long it’ll take before it joins an unread C++ book on the shelf :stuck_out_tongue:

yeah yabasic, the program yab’s built on, is available for windows and linux. But those versions don’t have there own IDE, you have to use a text editor instead. Check Vasper’s blog http://vbeosa.blogspot.com/ for a small article of portability on his Dungeon Master app running on linux w/o modification. PS - Vasper also has his own Yab forum here - http://beosmax.org/

Thanks Scott. I did find Vasper’s forum and the yabasic site. I see that yabasic is no longer being maintained but the info is still on the site.