Should I learn C?

teammatt3's picture

He has: 2,102 posts

Joined: Sep 2003

I forecasted for next quarter and I decided to take a class on C (the programming language). It's by the same professor who is teaching my unix class so I’ll be used to his teaching style. But I’m having second thoughts. I want to take the intro to PHP class. I have gotten away without learning PHP for quite a while, but I think it is essential in my future to really learn it well. Do you think it would be a waste of a quarter to take C? I don’t think it’s very popular in the web development arena. But is it a good base to start learning real programming? Or should I just skip it and take PHP instead?

Next week we are going to start shell scripting in unix, is that a good enough base to start programming?

Abhishek Reddy's picture

He has: 3,348 posts

Joined: Jul 2001

C is neither fun nor pretty. But it is useful, largely due to the profusion of operating systems in the *nix tradition. It's worth learning C solely to understand how its memory management and pointers work. This will help you as you learn other languages, because most of what you'll use is implemented on a C/*nix-inspired stack -- even Microsoft Windows. (For example, you might understand one of the reasons why PHP sucks. Sticking out tongue)

I don't think PHP can teach you anything uniquely that's good or novel. It's yet another dull language with subpar features, that just happens to have found a niche in web programming due to fortuitous timing. You can put PHP to good use, of course, if you already know how to program a web application in a dynamic language.

I'm not sure PHP will be all that important to your future. Increasingly, you will have the option -- if not compulsion -- of using any of Java, C#, Python, Ruby, Perl, maybe even Lisp or Javascript for your web backend, and of course an ECMAscript client-side. Any of those languages would be better than PHP to start with now.

So I'd go with the C course, given those two choices. Smiling

Busy's picture

He has: 6,151 posts

Joined: May 2001

I did a C\C++ course, learnt how to crash a computer pretty well Wink
As Abhi said, C is neither fun nor pretty, you need a complier to compile before you run the scripts where as PHP can run off the page (apache does the compiling).

C is very library based, you use a lot of them but don't need to know what, where or why. PHP is all on hand, functions as well but you don't need to include libary files to run certain functions.

ALthough PHP is based on C, there is no real connection, if anything learning PHP for me was like learning another language based on a whole different arrangment.

End of the day a lot of it lies on what you want to do for a living, webdesign/development or programming. I'd just go with PHP if your just doing web stuff, but would go Java, Perl etc for programming

JeevesBond's picture

He has: 3,956 posts

Joined: Jun 2002

Abhi wrote: For example, you might understand one of the reasons why PHP sucks.

Why not skip the wait, you could explain it to us now Abhi (and I do mean that). Smiling

C is still a very widely-used language. TIOBE Programming Community Index (for what it's worth) puts it at the second most popular language by quite a margin. The clear leader is Java though. Ruby has been surging up over the past few months. While my favourite language of the moment: Haskell, is languishing in #46th. Sad

Abhi wrote: It's yet another dull language with subpar features, that just happens to have found a niche in web programming due to fortuitous timing.

Ouch, that's a harsh surmisal! What are your reasons for this slamming? Are you talking about all the disparate functions? Lack of object orientation?

I agree with Abhi overall, C will give you a firm foundation to learn other languages. Plus you will have the opportunity to learn things such as pointers and memory management (yummy, malloc() action), which aren't in PHP. Even though most languages handle 'garbage collection' automatically these days, it's better to have a good working knowledge of these concepts. They will still affect most programming you do. Even Visual Basic developers such as myself had a bunch of techniques to make the VB runtimes use memory more efficiently. Smiling

a Padded Cell our articles site!

Greg K's picture

He has: 2,145 posts

Joined: Nov 2003

JeevesBond;210591 wrote: Why not skip the wait, you could explain it to us now Abhi (and I do mean that)
. . .
Ouch, that's a harsh surmisal! What are your reasons for this slamming?

I agree with Jeeves, especially thinking back to your reactions in this thread

If the class was taught by someone who knows the subject really well and can teach really well, then I would recommend the class in C. PHP is easy enough to learn from just resources on the net.

If you understand the structure of C, then IMO it will mae it easier and/or improve your desing in other languages (including php).

-Greg

FrankR's picture

He has: 45 posts

Joined: Oct 2006

In my opinion, the C programming language is a great place to learn a procedural language and a bit about how computers really work. It is rather close to the bare metal - meaning that when compiler optimizations are turned off, your code is translated to assembly code in a straightforward manner. The Kernighan and Ritchie classic, entitled "The C Programming Language (2nd Edition)," has long been considered a must-have for the library collection of every discerning programmer.

I definately think that you should go for the C class. I believe that what you learn will be undoubtably valuable. You can pick up PHP at any time. Once you learn how to actually program, you can pick up any language and work with it. PHP is a great thing to learn on your own and for work, but C will serve you well whereever you go and whatever you do.

I hope this helps Smiling

Cheers!

Frank

Author of SQL Converter for Excel, which is an Excel add-in for converting data to MySQL.

teammatt3's picture

He has: 2,102 posts

Joined: Sep 2003

Looks like you guys think I should take C. I'll stick to it.

Quote: PHP is easy enough to learn from just resources on the net.

Yeah you're right, I just need the patience to sit down and go through them :snooze: .

JeevesBond's picture

He has: 3,956 posts

Joined: Jun 2002

teammatt3 wrote: Yeah you're right, I just need the patience to sit down and go through them.

Indeed! Probably the best way to learn is to get the basics down, then build a simple project. You'll read what you need to learn then, but in a way that isn't mind-numbingly boring! Laughing out loud

Greg K wrote: I agree with Jeeves, especially thinking back to your reactions in this thread

Greg, that link doesn't work. Sad I really want to know what you're linking to!
I have heard from a variety of sources that PHP is a limited and flawed language, am really interested in why people think this. I've used PHP quite extensively, but have yet to hit the boundaries of it's abilities.

a Padded Cell our articles site!

He has: 1,758 posts

Joined: Jul 2002

Doesn't PHP use a C style syntax anyway? If it does (and I'm sure it does) you'll find learning PHP much easier when you know the basics...

Greg K's picture

He has: 2,145 posts

Joined: Nov 2003

Jeeves, fixed the link in my post. My main thought was back to his first reply to the thread.

-Greg

Abhishek Reddy's picture

He has: 3,348 posts

Joined: Jul 2001

Greg and Jeeves, this thread was not about why PHP sucks. I didn't want to discuss that as it would hijack the main discussion. Greg, I am also not selling anything.

However, as Matt has his answer, and you asked for it, I'll jump into a critique of PHP in a moment. Before that I should get a few things straight.

Every language has its faults, and PHP is no different. My criticism of PHP is threefold: it has a set of flaws, it has few redeeming features, and other languages are better.

PHP is Turing-complete, of course, and isn't a tarpit. It has many relatively useful features above that, so as I said, it can be put to good use. Though the language is subpar, applications written with PHP need not be. Indeed, there are several PHP-based applications I really like. Therefore, the scope of this critique is limited to PHP only, and doesn't reflect on the code and programmers that live on it. Smiling

"PHP", like most language names, is overloaded. It refers to the language (grammar, types, constructs, architecture), the environment (functions, library, garbage collector), and the implementation (Apache module, binary, settings, conf files etc). Each of these has its own problems.

Why PHP the language sucks:

  • Namespaces or lack thereof. This is probably the first deficiency that strikes those who've programmed in other languages. PHP has a bloated grammar as a result of its inability to abstract away non-core functions into libraries. Users are also limited by this, though inferior file-based separation is available, as is OO lately. Better languages: just about every one I named in my previous post, except for JS they all have packages/modules as well as OO or an equivalent abstraction.
  • Lexical scope, or lack thereof. PHP only provides (super)global and function-local variables. No lexical variables, no dynamic variables. I can't think of any other modern language at this level that doesn't provide lexically scoped variables. Perl and Lisp also have dynamically scoped variables. And don't forget PHP globals aren't implicitly inherited by functions.
  • References, or lack thereof. There are "references" in PHP, only they aren't really references as you know them (C or C++), but symbolic aliases. This leads to all sorts of complications and limitations when returning or passing by reference.
  • Recursion, or lack thereof. PHP uses the system stack instead of the heap for recursion, so segfaults (!) when it runs out of space. Note that it doesn't even raise a stack overflow exception as Python and Java do.
  • Programming paradigms, or lack thereof. Lisp folks often claim Lisp's being "multi-paradigm" as a feature. When it comes to PHP, it's anything but. PHP has a kind of procedural tradition inherited from C, though now with two kinds of object-orientation systems bolted on, one homegrown and the other like Java's. It's not a pretty sight.

Why PHP the environment sucks:

  • Non-orthogonality of PEAR and PHP core. What is PEAR exactly? It's halfway between Perl's CPAN and Java's Class Library. In any case, it isn't used much, probably because PHP's core functionality includes similar stuff it shouldn't, like mail() (vs PEAR::Mail), and because of insufficient abstractions.
  • Weird function protocols. There's more non-orthogonality here in that there are separate functions to do similar things. See: string functions, case-insensitive string functions, regex functions, etc. Arguments and return values are extremely inconsistent. And there's no consistent nomenclature. A lot of these functions should be in libraries anyway.
  • No Unicode support. Nearly every other modern language supports it without fuss.
  • Garbage collector and memory management. The GC uses refcounts, so cyclic references are a problem. Just about every modern language I know uses a less naive approach to GC. The refcounting GC was alright prior to the introduction of OO, but not anymore. PHP objects are fairly costly, partly due to pass-by-value and deep copying, which is a pain when the default memory allocated to PHP is 8M. (I've seen Drupal and PhpWiki run out of memory while loading a reasonably small set of plugins into an array.)
  • Magic quotes can be turned on or off in php.ini, so you can't assume either way. Programs have to check first, which adds complexity.

Why PHP the implementation sucks:

  • Backwards compatibility. Though PHP5 fixes a lot of things, there are many incompatibilities between PHP5, PHP4.4 (or 4.5?) and prior. A lot of stuff became deprecated fast, rather than being phased out gently. OO and references are probably the biggest deals. domxml (4) vs DOM (5) extensions too. It's hard for me to even critique "PHP" because behaviour across versions varies so much. In comparison, Java's philosophy represents the other extreme (nearly everything must be backwards compatible), while Python represents a reasonable compromise (gentle evolution).
  • Thread safety. PHP isn't seriously thread-safe. PHP 4 and 5 are incompatible with Apache's mpm_worker, though it will work (buggily) via FastCGI.
  • Caching. PHP is naturally slow, which isn't a huge problem as it's technically easily solved by using caching. The problem is that Zend provides this separately from the canonical implementation. I can't think of a good reason why. There are other free alternatives in PECL too, but again not included by default.
  • Development with PHP sucks. Mainly, the (very new) interactive shell is impotent. For an interpreted, dynamically typed, rapid development web programming (particularly in-the-small) language, I think this is unforgivable. There is also no de facto standard web framework, or indeed any substantially useful framework. That's because none of this fits with PHP's philosophy of hastily slapping together unsustainable code. It's why PHP frequently draws comparisons with Basic. Contrast with Java, Python, Ruby and Lisp, which have powerful interactive shells, and/or well-structured web frameworks and service libraries.

Why is PHP so bad? I think the cause lies in its history. The language grew out of a small set of library functions for web programming. Only it didn't stop growing; anything that was remotely useful was piled into the core, without concern for orthogonality, consistency, compatibility, or any other design considerations. It's a classic case of a domain-specific language mutating into a general-purpose language due to external forces.

Why is PHP so popular if it's so bad? Popularity doesn't suggest good quality, unfortunately. PHP got lucky, being supported by the right platform (Apache) at the right time. mod_php was much faster and simpler than CGI at a time when FastCGI and other alternatives weren't popular.

Why won't PHP be so popular in the future? PHP4 isn't just rough around the edges, it's fundamentally broken, as has been the development philosophy of the project. PHP5 is an improvement, but it is still playing catch-up to other languages. It's like a new language because of the incompatibilities and doesn't enjoy a great deal of market share. Competitors like Ruby, Python and Java have been making inroads already. I expect with .Net 3.0 C#, or other languages on that platform, will also grow as web frameworks and service APIs mature. FastCGI provides a level playing ground, too, nullifying mod_php's advantage. It will be interesting to see how PHP6 turns out, but I can't imagine it saving PHP from itself.

Is PHP good for anything? Yes. Despite its flaws I find that it's easy for a novice to learn enough of it to do useful things quickly. Experienced developers can produce dynamic sites rapidly. And it is widely supported, particularly on shared hosts.

However, I suggested not taking a class on it because PHP tends to encourage bad programming habits (especially for novices) and lacks relevant interesting features, in comparison with C, at least.

[Note: forgive me if the above is not 100% accurate. The main source of error might be the differences between the incompatible versions of PHP. I don't know all the changes very well; I may not be aware of a problem that's been fixed in PHP5. However, my points should still stand as PHP4 remains very popular.]

For more:
http://www.bitstorm.org/edwin/en/php/
http://spyced.blogspot.com/2005/06/why-php-sucks.html
http://www.ukuug.org/events/linux2002/papers/html/php/index.html
http://maurus.net/work/php-sucks/
http://tnx.nl/php
http://keithdevens.com/weblog/archive/2003/Aug/13/HATE-PHP

Smiling

teammatt3's picture

He has: 2,102 posts

Joined: Sep 2003

Just a (really late) follow up: I was very glad I took the C class. I learned a lot about program efficiency (that was pretty interesting), memory management, pointers, numbers, and just programming in general. After taking that class, I picked up PHP pretty easily and while I'm still a beginner, I think that class really made a difference in how I go about programming.

I can't say all C classes will be great, but mine certainly was (though, it was very hard and time consuming; we started with 42 people and ended the quarter with 18)

He has: 1,380 posts

Joined: Feb 2002

Having never mentioned anything, I think I'll put my two cents in here, albeit as a post-script.

C was the first language I had to learn in a classroom setting, and it wasn't that bad.

I've always looked down on over-developed languages like C# and Java, because unless you're going to do some very complicated things (like games), there really is no need. Why should you be 4 levels of abstraction away from the machine? Why not keep it at 2?

C is an easy language. I don't know what some of you guys are talking about, but in principle it really doesn't differ that much from other languages, besides the level of abstraction and a few things. Yes, pointers suck. Yes, memory management is a hassle. Yes, trying to figure out that seg fault is Hell.

But all in all, it teaches you alot. You learn why people choose languages like Java over C... because they're lazy and scared. You rejoice that languages like PHP don't have actual pointers, just things that are only slightly similar, and in concept only.

The best part, though, is realizing that once you learn a low-level language like C... you can pick any language of similar level, or higher, up very very quickly.

They have: 24 posts

Joined: Jul 2007

C is a good programming language, especially for Unix environments and low level work.

There are many other evolved programming languages, even if C will always remain the most popular, especially when it comes down to hardware programming. I have learned myself C and X86ASM over time and I must say that working with these programming languages and gaining experience in the field has proven useful later on, especially when going for a job application at a medium size local company.

I encourage you to learn C but you must be prepared to face a programming language that is not that fun, even if aplicable in many environments and offering quite a lot of advantages over most others.

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.