Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

How does learning C benefit a programmer?

by nysus (Deacon)
on Jul 29, 2001 at 01:03 UTC ( #100604=perlmeditation: print w/ replies, xml ) Need Help??

As I read about advanced Perl techniques, I'm becoming more and more curious about the C programming language. Stuck in my mind is some advice a while back from a fellow Monk who, to paraphrase, said that learning C along with Perl would be very beneficial to understanding programming in general.

As I consider taking the plunge and pick up a beginner's C book (any recommendations?), I'd like to hear thoughts on this. In what specific ways would you say C can expands programming horizons?

$PM = "Perl Monk's";
$MCF = "Most Clueless Friar Abbot Bishop";
$nysus = $PM . $MCF;
Click here if you love Perl Monks

Comment on How does learning C benefit a programmer?
Re: How does learning C benefit a programmer?
by Masem (Monsignor) on Jul 29, 2001 at 01:17 UTC
    I started reading up on C about 10 years ago, and always got stuck up on anything more advanced than loops and the basics.

    Then one day, the entire concept of pointers clicked. The rest of C was (practically) a breeze to learn after that.

    Then came C++, and I had the same sticking-point with regards to references, but I shortly learned that these were just glorified pointers. Particularly in relationship to what was passed to functions and was mutable in those.

    Since that point, I've not had a problem with any other language that is "low-level" enough to have access to memory locations directly. Has this helped me for a language like perl? Certainly; while you don't really have direct access to memory, references are very important in achieving fast communication between subroutines. Once you see this, building complex programs is rather simple (though of course there's probably more that people need to tackle from that point in regards to what perl can do).

    -----------------------------------------------------
    Dr. Michael K. Neylon - mneylon-pm@masemware.com || "You've left the lens cap of your mind on again, Pinky" - The Brain

(tye)Re: How does learning C benefit a programmer?
by tye (Cardinal) on Jul 29, 2001 at 01:41 UTC

    C is like a glorified, portable assembly language. It nearly forces you to understand memory allocation, memory addressing (pointers), and other low-level stuff. I've seen people program C without understanding such, but not do it well.

    Perl is very much like C in a lot of ways but it is very unlike C in this regard.

    The next item (update: after Perl w/ C) I'd probably add to the list would be some "functional" programming language.

            - tye (but my friends call me "Tye")
      You said: The next item I'd probably add to the list would be some "functional" programming language.

      Can you be a bit more explicit? I'm assuming you mean there is little or no value in learning C and it would be better to learn something like Python or Java instead. Would this be accurate?

      $PM = "Perl Monk's";
      $MCF = "Most Clueless Friar Abbot Bishop";
      $nysus = $PM . $MCF;
      Click here if you love Perl Monks

        He doesn't mean that C isn't a functioning language. In my other comment, I originally touched on this, but decided not to as I was beginning to sound preachy, but unfortunately, you're going to have to suffer through my sermon now.

        There are several main catagories of languages. you will usually hear of functional, logical, and object oriented languages on the internet. There are many other types that you will hear of in more serious practice, such as assembly and procedural.

        You will not gain the benefits of learning C from learning Python or Java. They do not offer many of the things that you would learn from C, however, Java is a good intro language for object oriented programming, you might consider learning that before learning C++.

        What he meant by learning a "functional" language is learning a language that enforces it's own functionality. One such langauge is LISP. It doesn't mean that your programs in LISP will function properly, but rather that they will always be experessed in terms of a function, in the mathematical sense. (+ 2 3) would be a logical line of lisp that returns 5. So you could say (+ (+ 2 3) 2) and get 7. All of the commands in lisp work this way, but it gets a lot harders to understand without properly writing it all out from here on out. Rather than programming procedurally, as in.
        $x =5;
        print $x;
        Your programs ALWAYS take on a functional feel to them.

        Most collegiate computer science programs strongly encourage their students to learn a functional language at some point in time. I remember my first brushes with them as kind of stressful for most of the students, but that it was greatly rewarding to master LISP.

        One fun "first lesson" in LISP that I would recommend is to download GIMP and try making some drawings using it. While this is a good intro lesson, I would hardly stop my training in LISP here, as it would be sorely lacking, (especially since LISP is a popular language for AI, and this is not even a common application).

        Anyway, that's the rundown on functional languages. Good luck in your pursuit of enlightenment!

        UPDATE I almost suggested ML, or perhaps SCHEME, but decided Lisp was the most common among them. hding's post on learning functional programming in ML reminds me of "quilt ML" from my programming languages textbook sophomore year!

        Just Another Perl Backpacker
Re: How does learning C benefit a programmer?
by coreolyn (Parson) on Jul 29, 2001 at 01:55 UTC

    Currently I'm plowing through a Java book. The CD that ships with it is a 'C' tutorial. The author spends the intro and the first chapter saying if you don't know the basics of 'C' basics do the CD before reading the book. In this case because Java structure and syntax is a type of 'C++' language for dummies. (Of course I've heard some say that 'C' is assembly programming for dummies.)

    In the case of Perl 'C' is one of the building blocks of the language many terms and structures are laced throughout the language. If your comfortable with Perl you probably would be surprised how much 'C' you've already learned.

    For me coding = laziness/OperatingSystem, but sometimes you can't be lazy. Sometimes you have to crawl into the damn chip and tell the bit to it's face what to do. Other than assembly, nothing is better for accomplishing this then 'C'. But 'C' is also a pain in the arse. Nothing is done for you, it assumes nothing, and you have to clean up behind it like a kid before toilet trainning.

    In the end, if you know 'C', the OS is yours even if you don't need to use it, and you also gain the benefit that all other languages that you will learn have some vague familiarity.

    coreolyn
Re: How does learning C benefit a programmer?
by RhetTbull (Curate) on Jul 29, 2001 at 01:58 UTC
    I believe that learning C will most definitely help you be a better programmer. A majority of the software you use (including perl!) is written in C -- it can be powerful, portable (mostly), and fast. As others have said here, truely grokking C will force you to have a better understanding of how the computer works (e.g. pointers, memory allocation, etc.) It's a step up from assembly language (which I also recommend learning) but still close enough to the hardware to make you understand your machine. A quote I once heard was "C -- all the power of assembly language with the ease of use of assembly language." heh heh.

    The book I most recommend for someone who already programs but wants to learn C is Kernighan and Ritchie's The C Programming Language. Kernighan and Ritchie invented C (and did a fair amount of the original Unix OS I believe).

Re: How does learning C benefit a programmer?
by virtualsue (Vicar) on Jul 29, 2001 at 02:11 UTC
    C was a great language to learn 10-15 years ago. I'm not too sure it would be particularly beneficial for a programming language student these days unless s/he had a specific need for it. I heartily recommend learning other languages, however, simply because it broadens your horizons and helps you learn different ways to think about programming problems. Why not try Java instead of C? It's more current, and more useful to you career-wise (if you care about that). Other interesting languages are Smalltalk, Lisp, Eiffel, etc.

    If you still want to learn C, the only book on the subject that I have ever used is the "The C Programming Language" by Brian Kernighan and Dennis Ritchie. Countless people have said over the years that it's a terrible book for beginners, but I never found another C book that I liked better. Since it's a controversial recommendation, you should probably get other opinions before you spend any money.

      Sorry answering so late, I just returned from extended weekend vacation... :(

      I recommend learning C as one (important) step in understanding your computer - and C bring you so close to hardware it's scary sometimes... ;)
      I learned C after knowing couple of assembler languages, Algol and PL/1, and after that one can get feeling how C builds layer between assembler and traditional high-level languages as perl.

      If you are inclined to learn another language allowing you to do scary trick and gain complete control of the computer, try FORTH. It allows you to do things as no other languages - for the price. It was said only 10% of programmers are able to program reliably in FORTH, but they all can be very good and productive. The way FORTH is build it might run on bare processor without OS (FORTH will be the OS). It has some simple concepts and some extremely powerfull techniques to define new concepts. I newer seen another language allowing to define new control stuctures so easily. Not data structures, control structures.
      My professors of computer science taught me that programming means "extending language by adding concepts to better solve tasks from problem domain" -- adding new data stuctures and operators/procedures to process them.
      FORTH is ultimate example of this approach. For some reason it is not very popular - I can understand it is not easy on beginners, but IMO it is very empovering excercise on your understanding.
      I've seen implementation of complete Tiny-Pascal part of Pascal language written in FORTH on 11 pages not too dense written - one page was interpreter on P-code and one was CDL-like extension to FORTH, basically YACC for FORTH.

      I recommend to learn C assuming it will be just one of other languages which concepts you are willing learn. If you have intention to learn only one more language (after perl you already know), I will have hard time to decide between java (with all the objects and hype and usefullness for your career etc) and maybe VisualBasic. Maybe, if you are interested in Windows platform, VisualBasic might be a good choice. It is farther away from perl than C, and will give you different perspective. Also, it is common script language for all MS Office products, and believe me, you can do a lot of smart things in VisualBasic for MS Word, or for Outlook, if you'll learn MS Office object model.

      "The C Programming Language" by Brian Kernighan and Dennis Ritchie. Countless people have said over the years that it's a terrible book for beginners...

      I believe it is misunderstanding. This book was never intended to be for beginners - I believe it says so in preface. Just the opposite: is is book for programmers experienced in other languages to get quick understanding of common features other languages have common with C, and how they might differ. And book does excellent job solving this problem -- I alway remember how much more enjoyable experience (for a programmer knowing half a dozen different languages) is to learn new language from a book like Kernighan/Ritchie's book. The only exception so far was Camel book -- and also because it it not intended as first programming book for complete novice with no experience of programming whatsoever.
      IMO, because you already know perl, you'll enjoy Kernighan/Ritchie's book better than another "C for complete beginner" book. Also, "Big Blue C" book is a classic, as a Camel book. Concept of first program as print "Hello, world!"; comes from here.

      pmas
      To make errors is human. But to make million errors per second, you need a computer.

Re: How does learning C benefit a programmer?
by bikeNomad (Priest) on Jul 29, 2001 at 02:30 UTC
    As others have said, C is the underpinning of much (though not all) of the freely-available code that's available on the net. Some reasons you might want to learn it:
    • if you want to get a feel for the operations of your programs at a level closer to the actual machine
    • if you want to extend Perl through the use of Inline (or XS) (though you can use other languages with Inline)
    • if you want to help with Perl (or much other open-source) development
    • if you want to do embedded systems development with small microcontrollers and don't want to use assembly language (IT is only one part of the computer programming world, after all)

    Some reasons you might want to learn some other (different kind of) language first:

    • C's structure is not as different from Perl's as some other languages are; you are going to be re-hashing many of the same ideas
    • You won't pick up too many powerful new ideas from C that you can use to improve the way you look at designs
    • C can be a difficult language in which to express algorithms readably, especially because of its lack of memory management and high-level data structures.

    Other sources of good ideas? Object-oriented languages, functional languages, parallel processing languages, distributed-system languages, database languages. Oldies but goodies like Smalltalk and Lisp will have more information available on the 'net, generally.

Re: How does learning C benefit a programmer?
by hding (Chaplain) on Jul 29, 2001 at 03:17 UTC

    I've found that it gives me something to fall back on when I can't get parts of my Lisp code to run fast enough. :-)

    More generally, though, it forces you to deal with things on a more elemental level, closer to what the machine is actually doing (at least for machines such as they are nowdays). C does very little for you compared to other languages (i.e. higher level languages). You get to have all the "fun" of dealing with memory management, pointers, etc. Learning all this has great pedagogical value. :-) It also will give you great appreciation for the people who have written nice things like garbage collectors for you.

    Of course, it's useful to know. Many OSes are written in C; many available libraries are C libraries. Even if you're not using C directly, there's a decent chance that you might want to interface with such, and so knowing about C can be useful for that.

    That all said, I can't think of too many times when I'd want to write anything in C. IMHO it's better off to leave it for when you actually (demonstrably) need it.

    As others have said, Kernighan and Ritchie is the canonical source for learning C

Re: How does learning C benefit a programmer?
by japhy (Canon) on Jul 29, 2001 at 03:34 UTC
    I'm going to rewrite my regex parser. Then I'm going to rewrite it in C. Then I'll have rewritten Perl's regex compiler in C. And, as Simon Cozens as quaintly pointed out, by definition, that means I'll have rewritten the regex compiler in C. (So I can rewrite Perl's regex compiler, and use the new structure to locate optimizations.)

    _____________________________________________________
    Jeff japhy Pinyan: Perl, regex, and perl hacker.
    s++=END;++y(;-P)}y js++=;shajsj<++y(p-q)}?print:??;

Re: How does learning C benefit a programmer?
by Nitsuj (Hermit) on Jul 29, 2001 at 04:19 UTC
    Let me get it out of the way by saying that perl is a good language, right off, now, onto why you should learn C.

    C is an excellent language, and it is important for many reasons. Anybody who questions its relevance to perl should download the source distribution and look at its contents... as it is written entirely in C.

    C introduces many important concepts to programmers, but by no means do I believe that a programmer's training is complete in having mastered it.

    One important thing is memory addressing. Memory addressing is an important concept. Another is typecasting. While typecasting is important to learn, types are not strongly enforced in C, as in it is not a "strongly typed" language. An example of a strongly typed language is Ada, a popular programming language that was developed for use in embedded systems (and is actually one of the better programming languages known to the world, it often gains criticism for being "clunky" or "awkward," but most Ada programmers would tell you it merely requires you to program correctly).

    So, what am I saying and how does this relate to you? Learning C is a step in the right direction towards being a better programmer. It opens a realm of possibilities to you that you may never have considered before, such as writing operating systems, device drivers, and even 3D video games. This isn't to say that what you have learned from perl isn't good knowledge, and this isn't to say that you will know how to write an operating system just by knowing how to write C code (far from it), but anybody who hasn't learned C certainly could benefit from it.

    Just Another Perl Backpacker
Re: How does learning C benefit a programmer?
by greywolf (Priest) on Jul 29, 2001 at 08:38 UTC
    Knowing C definately helped me learn Perl quickly. Likewise knowing Perl should help you learn C quickly. This would allow you to learn a fair amount of C without a steep learning curve or a large time investment. Besides it never hurts to know another language.
Re: How does learning C benefit a programmer?
by rchiav (Deacon) on Jul 29, 2001 at 19:45 UTC
    You have a lot of good responses here, but I just thought I'd add a couple points.

    The first thing learning C would do for you is give you a much better appreciation of Perl. You'll quickly learn all the tedious tasks that Perl hides from the programmer, and what really has to hapen when you do a  $name = $first . $last. My most common thought when I first started to learn Perl was, "Wait! You can't do it like that!" It was a struggle for me give in to the simplicity you'll find in Perl.

    And as others have mentioned, you'll learn a lot about memory allocation and management. With Perl, this is one of the things that just happens. With C, you're responsible. Take a look at Why Not Translate Perl to C? for a very brief example. Read the whole thing. It will also give you some insight into the magic that Perl performs.

    Hope this helps..
    Rich

    P.S - Take a look at Practical C Programming. My youngest brother (15) wants to learn how to program and I got him this book. He's going to learn C first to appreciate how easy other languages are :)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlmeditation [id://100604]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (6)
As of 2014-11-29 01:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (203 votes), past polls