views:

561

answers:

14

My primary language is PHP, but I have done some (not very much) programming in other languages.

I've written 2 modules for Apache in C. I wrote them in C because this was one of the things where performance did matter. (generating projected maps of the world on the fly and output to .png).

These modules work, and that's as far as I can guarantee the quality of the code. Don't get me wrong, I did my best to write correct code, but I'm sure it has a lot of room for improvement.

I'm playing around with the thought of changing the current modules to be threaded but have no experience with threaded software and thing like chasing down bugs still take me a lot of time.

my question is:
Should I first learn to properly program in C (get a copy The C Programming Language) or do you recommend another approach.

note:
I've currently no plans for using C other that for Apache modules

A: 

If you're not going to be using C for anything else, I'd recommend to switching to Java, as it's concurrency is much easier (in my opinion at least).

It also has a very large standard library that is very easy to work with and will probably speed your development up considerably.

samoz
Concurrency is very tricky, and the problems aren't going to be solved by going to a language that handles it better. I would suggest that somebody with the OP's level of experience stay away from it.
David Thornley
+11  A: 

If you are serious about programming, I think learning C is really important. It's the foundation of many languages and you'll encounter lots of source code written in C. However, we could tell so of Java, C++, etc..

IMHO, I think you should just continue to write your modules and learn new things as you need them. That's the best way of learning things

+2  A: 

I would highly recommend that book. Even if you do not see yourself using C in the future, you never know if you may have to and that is a perfect book to gain some more experience/knowledge for C with.

And as mentioned above C is the foundation of many other popular languages, so even if you dont end up using C more you may end using one of it successors.

jmein
+4  A: 

Sounds like you are doing quite well already. What about open sourcing those modules and asking for feedback from the community?

George Mauer
Now that sounds scary! :)
Jacco
A: 

I'd say it never hurts to learn something properly. And a solid understanding of C will definitely further your understanding of programming.

It does not matter if you will use the language itself in the future, but for understanding what is happening under the hood, its priceless.

Treb
+1  A: 

Even if you have no plan to program in C in the future, or even you are sure you will never have to develop in some c-related languages, I would recommend anyway the K&R book for historical reasons: it's a good practice to learn from the known masters of your art.

gldm
A: 

I'd say it's important for every programmer to master the low-level concepts that are important in C, like pointers and manual memory management. This gives you tremendous insight into how things really work and is useful even when programming at higher levels. However, if you won't be using C on a regular basis, I don't see any point in truly mastering the whole language. For example, I wouldn't spend too much time on the standard library or on learning how to design non-trivial projects in C. Just stick to the key concepts.

dsimcha
A: 

I have progressed from BASIC to FORTRAN then Java and currently mainly using combinations of PHP and Perl. I have never really used C apart from messing around with Apache modules, but whichever language you do learn the best way to learn is by doing.

Use a book to introduce you to the language, but learn it practically.

+4  A: 

Only learn as much as you need to.

You don't need to spend the time to read The C Programming Language and learn every feature of the language for it to be useful. Use The C Programming Language as a look up tool as you need it. If you start programing in c more often, then invest the time is learning the language more thoroughly.

lillq
jmucchiello
A: 

I would definitely recommend getting The C Programming Language (K&R). It is a very concise and useful reference to C. If you find learning from K&R a bit hard I wouldn't hesitate to get a gentler book on the language, but K&R is the book you'll be coming back to when there's something you're not sure about.

Also, it's worth pointing out that threaded programming opens a whole new world of potential problems, so I'd definitely recommend getting a book to learn how to do that properly as well.

arnsholt
any suggestions for a good book on threaded programming? (maybe this should be a complete new question?)
Jacco
A: 

Read the book. You'll be glad you did. It will introduce you to a lot of stuff that you wouldn't otherwise come across. You'll be introduced to all of the features of the language, instead of having to stumble across them when you think you need them.

Rob K
+1  A: 

I think the real issues you're facing here are:

1) is C appropriate for the task you're doing?
2) should you increase your knowledge of the C language as the requirements change?

For question 1, maybe there are alternatives to C for your application. You need to output .png images, and you need to manage threading: maybe Java or Python are better alternatives to C (.png output is a few lines in both languages, while I think you need external libraries and such in C. Same thing for threading.

For question 2, if you persist in using C, probably it's better to study the language more in depth, if you want to avoid pitfalls as complexity increases (expecially for a low level language like C).

friol
The complexity is not in outputting .png. The map-projections are really computation heavy, that's why I choose the low level language.
Jacco
+3  A: 

The best way of learning a programming language is by using it. So stepping forward and actually writing apache modules in C is a good approach. If you, however, want to dive deeper in that language you should do several things:

  • use the language. You already did that :)
  • get to know the language. The "bible" K&R is something you should have at least some knowledge about -- you don't need to know every bit of the book, but you should use it to have at least an idea about the language features that aren't used too often. It will get helpful one day.
  • collaborate with others. Get involved in a project with others to have others read your code and also read their code. Open Source is usually a good way for doing this, though there are other options too.

Speaking from my "career" I also started with PHP and ended up at C. Reading books (I can highly recommend "Expert C Programming" by Peter van der Linden, which unfortunately is out of print) will give you a deeper understanding of the inners of the language and thus make you a better programmer. I don't know every page of K&R but I never regretted using and getting comfortable with it (I think I rather used it than read it -- it's not a text book but a reference in my opinion).

bluebrother
A: 

Maybe i'm a bit of a modernist but if you are going to learn C properly I would not recommend starting with K&R. Why study an antiquated standard? Pick up a book that teaches you the C99 standard and learn from that. Since you're already a bit familiar maybe C Primer Plus or something similar.

nabiy