LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Do I have to learn C to understand Linux? (https://www.linuxquestions.org/questions/programming-9/do-i-have-to-learn-c-to-understand-linux-545737/)

moo-cow 04-13-2007 07:55 AM

Do I have to learn C to understand Linux?
 
Hi everyone!

I'm using Linux since quite a while now and I'm happy to notice that I'm beginning to "know my way round". I can write little bash, sed and awk scripts to help me with my everyday tasks and I've also had a thorough look at Python, which is ideally suited for helping me with my work, which is linguistic research, i.e. mainly text processing.
However, this does not seem to be of much use in understanding and modifying source code of Linux applications, 90% of which seem to be written in C. I do not want to write revolutionary new programs, I'd just like to look under the hood of some Linux apps and perhaps write a little patch here and there to adapt them for my purposes and, in this way, maybe even contribute back to the Open Source community one day.
Do I have to learn C now? At first glance, this doesn't look at all like the newbie-friendly "written pseudo-code" walk-in-the-park that is Python! Variable declarations, pointers, memory allocations... I'm scared! My main concern is: Is it even feasible to learn enough C for the above purposes in my restricted spare time (which would be pretty much 8 PM till 8 AM! ;)), or should I leave that to the computer science students and full-time Linux hackers?
I would be glad if you could tell me about your own experiences with C and Linux -- and whether I should or shouldn't learn it from your point of view.

With best regards,
Rehceb

ramram29 04-13-2007 08:15 AM

It depends on what you want to do. If you want to learn how to write hardware drivers or system commands then you will really need to know C and Assmebly very well. If you want to write an application you have more flexibility in what to pick. For example, a lot of application delevelopers pick a combination of PHP and Perl which are a lot more simple than C or C++. With PHP, Perl and Apache you can develop web applications. The way I see it, C is more for optimized system programs, libraries, kernel drivers and services.

slzckboy 04-14-2007 11:13 AM

If you are curious enough about it to post this thread then why not just give it a go and see where it takes you.

I feel that learning C has enriched by Linux experience.
Like you,I did it in my spare time.
I'm no guru but I can make apps for myself to do this and that.
I am getting better at reading other peoples code,i've modified a couple of things etc and it just gives you an appreciation of what is going on under the hood so to speak.

:0)

introuble 04-14-2007 02:28 PM

Quote:

Do I have to learn C now?
You don't have to do anything, it's a matter of will and determination. And .. I don't think Python is really all that "walk in the park" you make it seem to be. Just how "deep" is your knowledge of the language? Anyway, if you'll try to learn a language like C because others suggested it and not because of an internal desire, I give you 5% chances or less to succeed.

indienick 04-14-2007 06:39 PM

I don't really think you necessarily need to know C to fully comprehend Linux.

The closest I come to knowing C is Java.

I've had attempts at learning C++, but that always fell apart for me, as I saw little to no point in a few aspects (these aspects weren't C++-specific, but were "paradigms" in object-oriented programming).

The languages I've settled on are (in order of use): Common Lisp, Python, Java, Bash scripting and KornShell scripting. I know more languages, but there isn't anything I can't do in any of those languages.

Moreso, while learning Common Lisp, I finally understood the reasons/purposes behind some things I had only ever, previously, come across in C/C++ books that were just supposed to be accepted and not understood. I suggest giving Common Lisp a look over; warning, though, it's weird. I use Common Lisp almost exclusively, however. It grants me what I need, to the extent that I rarely ever touch Java or Python.

:)

ErV 04-14-2007 08:18 PM

Quote:

Originally Posted by indienick
The closest I come to knowing C is Java.

They are different. As I saw in sources C doesn't provide much high-level function. It stays very close to asm programming and works with raw pointers. In java (as I know) there aren't pointers, it's a high-level Object-Oriented language that can let you forget about machine-specific features (since it's completely cross-platform). C is generally more low-level, have slightly different syntax, etc. C isn't even a completely "object oriented". C++ is closer much closer to java. (IMHO) C is closer to a Macro assembler with advanced libraries.

About the subject:
(personal opinion)I think someone should have at least some basic programming skills (language doesn't really matter, as long as it's not Prolog :)) to work with linux effectively.

introuble 04-15-2007 12:53 AM

Quote:

I don't really think you necessarily need to know C to fully comprehend Linux.

The closest I come to knowing C is Java.
#1. Then again who says *you* fully comprehend Linux? :-)
#2. To *FULLY* comprehend Linux you must know C, amongst other things. Take a while and ponder of the meaning of "FULLY".

Quote:

stays very close to asm programming
I don't think it's "very close" to assembly.

Quote:

C isn't even a completely "object oriented"
C isn't OO at all. C++ is.

Quote:

(personal opinion)I think someone should have at least some basic programming skills (language doesn't really matter, as long as it's not Prolog ) to work with linux effectively.
Surely it depends on what you want to do with the Linux system. What if all I do with my box is listen to my collection of audio CDs? What do I need programming skills for?

jschiwal 04-15-2007 01:15 AM

Quote:

I'd just like to look under the hood of some Linux apps and perhaps write a little patch here and there to adapt them for my purposes
Usually you can do a lot to change by writing shell wrappers that set particular options for commands. Or creating aliases. For example, look at all of the options on how ls displays its output. Also, look at all of the formatted output options for the find command.

Also, some of the libraries that you would use to write a program in C have Python bindings so you can use them in Python. Try entering "Python wrapper" in Google.

indienick 04-15-2007 11:00 AM

Wow, I'm getting shredded for my comment about C and Java.

introuble:
Comprehension is subjective. :)
I don't necessarily need to know what went in to it, just to know how it works. It's like machining, it doesn't matter if I use a fly-cutter or an endmill; they both have their particular applications, but can both achieve the same result.

What I was trying to say, and should have made clearer in my previous post, is that you can get away with knowing HOW Linux works without an intricate knowledge of C. Elaborating, knowing C can explain how to, programmatically, detach a process from the current TTY and have it run in the background passing all output to either a log file or /dev/null, but that knowledge of C isn't needed to know how to do it in, say, a system administration script.

Depending on what kind of programming is desired here, which I believe the OP has made clear as open-source application development, the language to be used, is going to be, simply decided on the project.

Kernel modules and development - C; GUI/application - C, C++, Java (I'm excluding Python from this as it does not have an intrinsic graphics library unto itself - it makes use of Qt and GTK+ library wrappers); System administration - Expect (Tcl/Tk-subset), native shell scripting, Python; AI programming/neural net development - Common Lisp, Prolog; Mathematics - Common Lisp, Scheme, Algol; Device driver development - C, 80x86 assembly, 80x86_64 assembly, GNU/Linux kernel assembly; Generic system development - C, C++, Python (see the Unununium project)...

ErV 04-15-2007 03:59 PM

Quote:

Originally Posted by introuble
I don't think it's "very close" to assembly.

Let me explain. (IMHO) C is close to macro assembly. It doesn't try to hide system mechaincs from you - for example it represents strings in the way they exist in memory - as a 0-terminated sequence of bytes, while Pascal, for example, uses a built-in "string type", that hides a lot of work with memory reallocation.

Higher-level assembers (with macros support) have a lot of features that make them similar to C/or other non-OOP languages - for example, they have wrappers that handle function calls, loop and if/else situations. They have structures, constants, a simple preprocesor, etc. The only difference there is that assembler still uses asm instructions instead of predefined library functions, and that assembler still have to declare memory model, etc. I think that C provides just enough features to write low-level functions (kernel :)) without having to write unportable assembler instructions.

slzckboy 04-15-2007 04:07 PM

Moo-cow has probably taken up golf instead now anyway.

moo-cow 04-15-2007 04:58 PM

Quote:

Originally Posted by slzckboy
Moo-cow has probably taken up golf instead now anyway.

LOL, movement? Probably even outside in the fresh air? Never!
Having taken a closer look at C and pondered your comments I decided that C is indeed manageable and useful, but a bit too time-consuming for now, as I'm writing my master's thesis. But as soon as I'm done with it, I can reward myself by finally learning C. Now I'm at least motivated to finish the darn thing.
Until then, I'll take comfort in learning a bit of Elisp, which lends itself to occasional Emacs-hacking just for the fun of it. Maybe I'll even like it, what I somehow doubt, though, as "Lisp has all the visual appeal of oatmeal with fingernail clippings mixed in" (Larry Wall). :D
Thanks for your opinions!

moo-cow

nadroj 04-15-2007 05:38 PM

i hope your not a CS major! :p whats your thesis on?

moo-cow 04-15-2007 05:52 PM

Quote:

Originally Posted by nadroj
i hope your not a CS major! :p whats your thesis on?

Hehe, and what a poor CS major I'd be! No, I study Applied Linguistics, my thesis being on the influence of English as the pervasive world language on German. In short, German communicative norms are shifting towards English ones, which is pretty interesting to say the least. Uh-oh, OT alert! :tisk:

introuble 04-16-2007 04:09 AM

Quote:

you can get away with knowing HOW Linux works without an intricate knowledge of C
Again I disagree. Let's replace "Linux" with "a Mercedes car" and "C" with mechanics. Can you get away knowing how a Mercedes works without an intricate knowledge of mechanics? Knowing "Ah .. it has a motor and some wheels which go on the ground etc." is not knowing how the car works. Knowing how the car works means knowing exactly how all it's components work individually and together. You've said that with C you know how to programmatically make a process run as a daemon but you can also do it with something like `./task &` or whatever. Perfectly agreed. But does that mean you know *how* linux does this task? You call fork(), etc. Great. What does the kernel do when you call fork()? That's my understanding of knowing how linux works. There's a difference between knowing how to use a tool and understanding how the tool works.


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