views:

189

answers:

5

My primary interest is network programming. I have done quite a bit of reading and experimenting and am familiar with mechanisms of most protocols. Now I want to start writing code. I read introductory stuff on python and grasped it well too. I had just started playing with the python modules, when I met somebody (with a tall reputation) at the local lug meeting who told me that I could always learn python very easily later but C was the language I must know, specially given my interest on network programming. I did some research and thought maybe the guy is right.

So I've been with K&R for 4 weeks now. It didn't intimidate me but I am progressing very very slowly and maybe that's why also slacking a bit. I am posting this because I'm at the stage where it's even worrying me now. I'm always thinking that in python i could be building stuff right now. I know python won't teach me low level things like memory management etc, but my progress is pain-stakingly slow in C.

Question: Should I continue battling with C like I'm now and write some working code in it or switch to python where I'll be at a bit more ease? Will a high level language spoil me too much to come back to C later?

A: 

The answer is quite simple: It depends on what you really want to do with network programming. If you want to implement a new protocol on a low level - stick with C. If you just want to use TCP/UDP-Sockets you will be fine with Python. Of course you can gain a very deep insight in what network programming is about by doing it in C, but if it's slowing you down too much and you feel that you don't need it - let it go.

Best wishes,
Fabian

halfdan
Actually, I would somewhat disagree with your suggestion that if one wants to implement a new low level protocol that one should stick with C. It depends on what you want, to some extent, but things like Twisted may serve you better than writing low level C code, especially during prototyping of a new protocol. Time to solution with Python will probably be faster, and if performance is a problem one can always reimplement bottlenecks in C. Between the Python standard library and various modules available, there's plenty of flexibility for high and low level implementation.
James Snyder
A: 

The basic ideas of programming matter more than the language they are implemented in. If you're still a novice programmer, it may be worth it to stick with the language that you find simpler before diving into the deeper end of the pool. One of vital abilities of a good programmer is being able to switch between levels of abstraction, and even a "high abstraction" language like Python has plenty of levels for you to play around with.

Take it slow. Learning to program well takes time, and if you continually frustrate yourself, it can be agonizing. When you find yourself running up against Python's limits and you want the power of a "low abstraction" language, then learn C -- and you can use what you've learned from Python to get a head start.

singingwolfboy
+1: If Python works for you, stick with it. Why switch?
S.Lott
+1  A: 

I have learned both languages in the past few years, and python is more useful to me, especially for network programming. Keep in mind that now is a bit of an unstable time for python because of Python 3 being backwards-incompatible and everything which needs to be ported to it. When using python, do yourself a favor and stick with v3.x as much as possible.

As for your original question, I would say that if you want to just write simple programs for yourself and maybe other, more complicated things to be released, you should stay with python. However, most programs for Linux (including the kernel) are written in C, so if you want to help with that in the coding area, you will need to learn C. Keep in mind that the longer you use python, the easier it will be to learn C. Also remember that, at its core, C is a simple language, though its syntax may seem a bit excessive coming from python.

Oh, and don't worry about "spoiling" your self with high-level languages, you will find that high-level and low-level languages each have their place and that moving between them will be easy when you want/need to. Whole books have been written about this, but the summary is that you should use low-level when you need performance, small size, and/or portability, and high-level when you want the program done fast and you don't need to do heavy processing (and therefore need execution speed). Don't take my word for it though, you should so some googleing before you make up your mind about what language to use for a project.

In summary: You can get by without knowing C, but once you get to more advanced projects, you will benefit from being able to use it.

marcusw
+2  A: 

That feeling that you are going slower when you program in C compared to Python is not just your inexperience with C. It is part of the language. Coding in C requires a lot more mental checks to be sure that everything is being done properly. Memory allocation is just the start. Type considerations, variable lifetimes, header files, scope rules are all harder in C than Python. What you put out at code writing time you get back (hopefully) in shorter execution time and much more control over the computer's resources. Since programmer productivity is much more of a problem than machine productivity I would stay with python if you can.

verisimilidude
A: 

If you are serious about low-level network programming then you'll need to learn C sooner or later. Generally speaking C is more suited for implementing code that operates at the lower layers (layer 1, 2 and 3).

If your goal is to create web applications/services then you should focus more on Python.

StackedCrooked