What is a "real" programming language? [closed] - php

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 12 years ago.
Recently a teacher said "PHP isn't a real programming language", but only gave, in my opinion, weak justification:
It's not compiled.
It's scripted.
It doesn't run on every platform.
Is PHP not considered a "real" programming language? What is a "real" programming language? Must a language be compiled to be taken seriously?
Background
I did an induction lesson into my A-Level Computing Class in school two days ago – we're using Java for the first year of the course. I'm unfamiliar with Java but have a pretty good grasp on general programming fundamentals (variables, functions, object-orientation, loops, etc.).
Our first task the teacher ran through ridiculously fast. She didn't bother to explain any of the concepts, how they work, or what you would realistically use them for, and seemed to take great pleasure in watching most of the students (who were, on the whole, new to programming) squirm in their seats at not having the vaguest idea what she was on about. In hindsight, I reckon she went through it incredibly quickly to see who could really "handle" taking Computing A-Level, since students still have a chance to change their subjects before September begins.
The first and only task was to write a Java command-line application to convert binary to denary (decimal). We had a two-hour taster session to do this, and after explanation how the binary system works we had to begin, despite, on the whole, nobody really having the foggiest idea where to begin. After an hour some were further than others, but nobody had really achieved anything significant. The teacher herself became so confused she called in another teacher from next door. He came round to help people and see where to go next.
Without bragging, I probably did have the most experience in the class and had gotten the furthest in the exercise. He asked me if I'd had any previous experience; I said yes, particularly in PHP, and jokingly commented that I could write something to convert binary to denary in just a few lines of PHP, whilst the Java application was rapidly growing into several screens of code.
He replied, "PHP isn't a real programming language!"...! After some discussion, he gave the three reasons above. However, I pointed out you can run PHP on any platform that runs Apache, but I don't think he really knows what Apache is and was having none of that!

First we need to know what a programming language is. At its minimum, a programming language is something that is read by the computer and instructs it to perform certain operations. Many people would also expect a general purpose programming language to be Turing complete. However there could be situations where a domain-specific language isn't Turing complete but is still a useful programming language for that specific domain. Programming languages can be compiled or interpreted, and they could run on many platforms or just one specific one. Different needs require different programming languages. Clearly PHP is a programming language.
My definition of "real" programming language would be any programming language that has at least one practical usage in the real world. This is opposed to an esoteric programming language which typically has no practical usage. Since PHP is used widely to solve real problems it easily meets this requirement for being a real programming language, although it is arguably not a particularly beautiful language.
PHP is a pragmatic language. It was created out of a specific need to be able to quickly make web pages (the name originally stood for Personal Home Pages) and the language was extended as required. Since there was no theoretical background or strong design principles driving its creation (there isn't even a formal specification of the language) it is less clean than many other more modern languages. Features like correct handling of foreign characters / unicode characters are obviously added on afterwards and not cleanly integrated with the rest of the language. This untidiness and lack of theoretical rigour causes many people (especially academics) to dislike the language and this may be part of the reason why your teacher doesn't regard PHP as "real" language.
However PHP is good at what it was designed for and many sites use it, even very large sites like Facebook, Yahoo! and Wikipedia.

It's not compiled
PHP can be compiled (e.g. through HHVM).
It's scripted
That's just another way of saying that PHP is not compiled.
It doesn't run on every platform
Neither does Java.
Sounds like you have a really bad teacher there.

Of course PHP is a programming language. He probably meant it isn't a "real" programming language in the same sense that "real" men don't eat quiche.

define:programming language
It seems, according to this, that PHP is a programming language. Whether it's a real programming language is entirely subjective. Whether it's a good language is also subjective. Certainly, it is most commonly not used as an application programming language, but it can be used to develop shell applications via CLI. I have never done this, so my understanding of it is sketchy, but it's possible.
Now, is PHP "scripted" (I take this to mean a scripting language), and does it run on every platform? You judge:
PHP: Hypertext Preprocessor is a widely used, general-purpose scripting language that was originally designed for web development to produce dynamic web pages. For this purpose, PHP code is embedded into the HTML source document and interpreted by a web server with a PHP processor module, which generates the web page document. As a general-purpose programming language, PHP code is processed by an interpreter application in command-line mode performing desired operating system operations and producing program output on its standard output channel. It may also function as a graphical application. PHP is available as a processor for most modern web servers and as standalone interpreter on most operating systems and computing platforms.
Source: http://en.wikipedia.org/wiki/PHP
Does Java even run on every platform? No. Only those for which there exists a JVM.
Finally, does a language need to be compiled? Many aren't. Even Java isn't compiled in the same way C or C++ is. And then you'd also need to take a look at Perl, Python, etc.
Personally, I think PHP is a real programming language. I started there and easily moved on to C/C++ and Java. I wouldn't use it for the same purpose as Java, and its design is different from Java, but that doesn't mean much. It was easier to learn than Java for me.

First of all, not being compiled and being interpreted (what he surely meant by scripted, which is somewhat vague and used for different purposes anyway) are different sides of the same coin, and thus really the same reason.
The last reason, that it doesn't run on every platform, is just confusing. It sounds like he's trying to tout Java's portability and PHP simply isn't Java. However, Java runs on one very specific platform: the JVM. That platform in turn runs on many other platforms, and thus gives Java its portability, but it's not quite the same as the traditional use of "portable". For example, C is portable and runs on everything from a PDP-11 to the latest embedded devices.
However, C does that by specifying rules of its own abstract platform, and compilers transform C code into assembly according to those rules. This is how Java's portability is similar to C's: they both define rules which are translated into instructions for a specific, concrete machine (processor); the difference is when that occurs.
All problems in computer science can be solved with another level of indirection.
  — David Wheeler
In reality, even assembly or "machine code" is interpreted by the processor into its native actions. (I don't have a good source at hand for this, but I recall that it's lightly covered by A Crash Course in Modern Hardware, which is a good presentation anyway.) As processor speeds get faster, we hardly notice on our underused boxes whether a given program is in asm or run through an interpreter, but this is where the definition of "real programming language" comes into play.
The only sensible way to define a "real programming language" is as "a language to get real work done", but that really punts on the definition of "real", too. (It does, however, establish a distinction with esoteric programming languages, because nobody does real work, for example, in Malbolge, for any definition of "real" you could get ten people to agree upon.) And, compared to today, your choices of a programming language were much more limited by their implementation strategy and overhead (e.g. a runtime interpreter) in the past. However, even today, some languages are more "real" than others for certain applications and expected loads, it all depends on your requirements.
It sounds like your teacher has only experienced PHP through toy web applications (and maybe using 'application' is a stretch for what he's seen). Toy programs aren't real work. PHP definitely has a lot of problems, but I could not say it isn't a real programming language, except in jest.
Debugging is anticipated with distaste, performed with reluctance, and bragged about forever.
  — Dan Kaminsky
There is a certain association of "real" with "hard to do" (related to "real work") and your teacher may have been expressing this sentiment. This has always appeared to me as a form of bikeshedding (there's a better term for this exactly, but I can't remember it), where one's estimation of the value of a thing is related to the effort one had to put into it (e.g. a bikeshed is more important when I provided input on the color of the roof and whether it should have a sign). We intrinsically value our own effort more than that of others – just because we're familiar with it, if for no other reason – even when it doesn't make sense to do so. PHP, despite its faults, does make some things easy, and it and programs written in it can consequently be perceived as worth less.

Facebook, Digg, Wikipedia, Yahoo. I guess those aren't real websites.

Back when I was learning PHP, I too didn't believe PHP to be a programming language.
I'm not sure where I picked the idea up, but I learned somewhere that a scripting language is not a programming language. So I applied this thinking to other languages, such as JavaScript and SQL.
Since then I have changed my mind and understand now that there is a spectrum of languages that goes from high level (e.g. PHP, Javascript) to low level (e.g. c, assembler) with things like C# and Java somewhere in between.

You are right. These reasons are too weak. Actually you don't even need Apache to run PHP.
And first two reasons are just repeat themselves as it's only one reason actually. So, one can say 'PHP is not compiled language' but that doesn't mean it's 'not real programming language'. Java programs doesn't compile into machine codes too - well, it's not a real language as well. q.e.d.

Sorry for the OT, but there are so, so many things wrong with this picture! I just hope that you will bail out of that class, that department, and that school just as quickly as you can. I promise that you'll have nothing near to a semester's worth of knowledge when February comes. And, if you're like me, you'll spend your classroom hours in frustration, resentment, and rage at the time your teacher is wasting for you.
That woman is no teacher! Decimal to binary as an intro to coding? Gruesome!
Is it the University (ha!) of Phoenix?

UPDATE: read carefully before you vote, this is not my approach to PHP/Java, I'm trying to see how his teacher sees the PHP/Java thing. Thanks.
What I think your teacher thought: PHP is a language which is locked inside a webserver, mostly used to generate web pages.
Java, on the other hand, is a general-purpose language used for web pages too but used in other industries like microwaves & cars, you can write desktop application in Java etc.
With this in mind it's understandable why your teached said "PHP isn't a real programming language!"
I'm not biased, I don't like both, Java & PHP :) ...but have to use them both

There is no such thing as a real programming language, real man, or real world. You are a programmer if you can program in PHP.

Certainly, PHP is a programming language. It is even Turing-complete language, which basically means that its "power" is equal to "power" of other programming languages. It is "real" both in strict (it really exists) and metaphorical sense (there are people making their living using PHP). So it seems that your teacher is somehow biased.
However, I see some point in your teacher attitude. PHP and Java come from radically different backgrounds. Despite being useful, PHP is very chaotic. Compare standard class library in Java with standard library of PHP functions - the latter looks just like huge set of unrelated tools. Moreover, there are a lot of PHP tutorials on the Web that are of, politely speaking, mediocre quality. Because you are learning how to program, it's best to learn using good tools, and Java is much better tool to learn programming than PHP.
PS. Google for "PHP sucks" to get tons of information why PHP isn't the best tool in the world.

"So, in the 'definition of a programming language', what makes PHP not a 'proper' one?"
The real reason is the fact that most people do not use it as a general purpose application programming language.
It is because there have been always languages which are better suited (with one exception: what PHP was created for, web programming). PHP is "yet another language not even with better design features over existing ones". Some examples of issues when comparing to different other languages include: lack of stable and portable GUI toolkits (at least on Windows/MacOS), lack of threading, lack of speed, and so on.
Ultimately, people who are going to write general applications in PHP, are mostly people who only know well PHP as a programming language. Because there is no reason to write a new application from scratch in PHP: you'll find that most experimented or talented programmers would never consider doing this.

Its just one of those stupid things people repeat to make themselves sound smarter and shut you ups, its cargo cult smugness. If you ask him to explain, he'll either pretend it was a joke(tell him "nice try"), or try pathetically to defend his position (tell him "oh i see", and back away slowly)

Just to put an argument in the other direction to everyone else...
I feel slightly uncomfortable thinking of PHP as a programming language because I'm not convinced you end up with a program. You don't leave your PHP app running, rather a PHP page is requested and is loaded and processed in order to generate an output page, with side-effects like DB changes, etc.
None of this means PHP can't technically be described as a programming language but I think it's reasonable to separate it somehow from Java/C++ where a program can be left running with some concept of state. Each PHP file is surely its own 'program' since you can request any PHP page... there's no entrypoint to a PHP web-application except the convention of calling the right pages.

Related

What are the architectural limitations of PHP? [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 11 years ago.
I was reading the article "PHP Sucks, But It Doesn't Matter" by Jeff Atwood.
In the comments he writes:
That said, I absolutely think it's important for PHP devs to be aware of the architectural limitations of PHP, and understand the alternatives.
What are those limitations and how do they compare with other scripting / weakly typed languages?
Also, what are the alternatives in those conditions where limitations need to be avoided?
There are basically two real limitations I see:
PHP is a fully synchronous language. This has impact on which things you can easily implement in PHP and which not. For example implementing a Long Polling driven chat application isn't trivial, because PHP would need block one process per chatter. I'm not saying it's impossible, you can hack around this limitation using some PHP Daemon library. I'm just saying that this is one of the cases where other languages, like JavaScript, are more appropriate (NodeJS).
PHP is slow. Please don't understand this an an offense. It's a fact that PHP - as implemented by Zend - is slow compared to other scripting languages. This typically is no problem when building websites, but you obviously can't do certain things: Implementing a ray tracer in PHP is definitely a bad idea - whereas in JavaScript you could do this.
But apart from that, I think that PHP is pretty multi-purpose. You can use it for nearly anything - and I do ;)
Take a look at the date. The article was written in 2008.
It means, that if you'll see the PHP5.3 advantages, you'll find there many things, like closures and namespaces, which were in other languages before. Some of them is already affected the architecture of famous frameworks, like Symfony.
And that list will never be complete.
Meanwhile, I meet a lot of people who think that "weak typing" language is an architectural problem itself.
Then, some people think that inline regex syntax is good thing in, for example, JavaScript, but others think, that "different language" must be written down in string constants there, as in PHP. Etc.
I'll take a stab at this without getting too into the nitty gritty:
The initial design of PHP as a collection of functions still shows through.
Object-oriented patterns that have been implemented in the latest PHP 5 releases are still half-baked and lack multiple inheritance (or "mixins"), proper module support, and are designed to be backwards compatible with the CoF (collection of functions) design.
Method overriding and callbacks are not supportive natively.
Closures. They are there, but they are very weak.
Errors vs Exceptions — methods are inconsistent in which they use (thanks again to CoF design), and error-handling is half-baked.
I'm sure I'm stepping on someone's toes here and I'll get any angry mob, but I'm also sure that I still didn't hit everything. It's largely subjective, but it's easy to see what is to dislike when you stack PHP up next to Ruby or Python.
I don't find it odd anymore that all of "PHP SUCKS" articles are coming from developers accustomed to established Microsoft technologies.
What I do find odd are statements that indicate that PHP is a spaghetti code. It's completely up to the author of the code whether the code will be spaghetti or if it'll use certain design rules when approaching the problem.
The reason a lot of PHP code out there is spaghetti code is because examples and tutorials are such that they don't teach beginners the good coding practices. Also, people are quick to grasp examples like hello world or connecting to MySQL, doing a query and looping over the result - but that's it, that's where ALL tutorials stop. I still haven't found a tutorial that covers the following:
what is a framework and what it helps with
what are data structures and data types (explained in a way a normal human can understand)
what is an array, what are array dimensions, how do arrays work, what are arrays useful for
what is object oriented code, why object oriented code, how does PHP do it, what is considered good, why are there patterns out there and so on
As you can see, a beginner programmer won't be bothered to learn all of those points outlined above, I know that because I was a beginner too and did all the mistakes beginners do. However, even if someone doesn't know how to program, they can still create useful applications.
Many popular scripts were written by people who knew WHAT they want to achieve, however they did not know HOW to properly design the environment (framework) in which they'll deploy their php code.
That's why we see scripts that become incredibly popular due to the ease of their use as a regular user which are hard to extend looking at it as a developer, using weird function names, odd coding conventions and no commenting.
Also, what's ridiculous is saying PHP is slow which is absolute nonsense. When I come across such statement, I want to shoot myself in the head for reading such a blog entry.
One has to know several things before making such a statement:
PHP is a scripting language, that means the interpreter is invoked every time someone requests a PHP page which takes A LOT of CPU power. That has been addressed by using bytecode caching mechanisms such as APC which stores the copy of pre-interpreted piece of the script in memory. The results are impressive, and I kid you not - execution for some of my scripts goes from 20 milliseconds to 1 microsecond, where some benefit "only" 5 times. That's on a system that serves 1 thousand concurrent users. Now, if someone wants to tell me that 1 microsecond is slow (or 5 milliseconds) - I'll take that as bullshit.
PHP is not the only thing involved in serving a web page. There's also underlying server (Apache) which has its own issues, there's MySQL which runs queries - and who says all queries are optimal? There's the network, there's the hard disk, there's the CPU, there are tons of other processes. Configure Apache with PHP-FPM, optimize MySQL to perform good on 8 core machine with 16 gigs of ram, use APC, use Memcache - and voila, you're getting an incredibly fast, scalable system capable of serving an incredible amount of traffic.
Languages that PHP is being compared to are often "compiled" into the bytecode and then executed by
You can extend PHP yourself. Assuming a PHP function is slow, NOTHING prevents anyone from creating a .so in C that is able to do the job faster and then hooking everything up trough extension in PHP. Not that I know what would such job be that would require that, but such a thing IS possible.
Sadly, and I say sadly because I respect certain programmers and admire their work (and I'm by no means a PHP fanboy) but it hurts me when I see uneducated, inexperienced and subjective comments about a tool which spreads misinformation.
As for why big websites use PHP - because it's fast. Because they laid proper foundations before starting the projects. Because it's free, extensible and scalable. Because it follows C syntax. Because you can extend it when you need it to be faster. Because it runs on a free operating system. Because it's easy to use.
PHP is improving everyday. It is open source and used all around the world. That said, when you have a problem, it is most probable that you will find your solution or get help faster than any other language.
The very reason of this article, I believe it is simple. If you (or in that matter any other programmer) used to code in C++, Java etc.. they had a lot of possibilities such as OOP coding and PHP was limited in the beginning.
It is a good thing that PHP has many built-in functions / methods / classes so you don't have to spend hours to code some function / class / method which PHP already has.
You don't have to (and you shouldn't) try to memorize all these functions. It is useless to memorize all of them (which one is doing what, how to use it etc). Imagine you are working on some project which took you 4-5 months to finish (yeah big one (: ) You are not going to use all these functions in all the projects and eventually you will forget what they were doing since you don't use them often.
The point is, you should know the syntax of PHP. When you need to do something, check first if PHP already has what you want to do in its library. Check the manual to see how to use it. This way, you will also LEARN (NOT MEMORIEZE) the ones you use often and this information will be hard to forget.
PHP or any other programming language is just like a normal language which we humans use daily to communicate with each other. If you don't use it, you will forget.
PHP 5.3 and above brought many features. Static feature is one of the biggest feature for me. It made my life so much easier that I can't even begin to describe.
Since PHP is that famous and open source web scripting language, Facebook developer team created HipHop.
What HipHop does is, takes the data from PHP and sends it to C++. C++ does all the process and sends back results to PHP for outputting.
The whole idea of HipHop was to make Facebook use less servers & improve the page display times.
Now you tell me if this seems limited and / or slow to you?
i dont think there is anything like 'architectural limitation' for php. developer knowledge limitation might be the reason. read this http://www.quora.com/What-is-Facebooks-architecture . most of the time, non-world-class developer does not know how they could use php to its full capabilities.
I would assume he is referring to the fact the the OOP portions of PHP are not the greatest compared to languages that are purely object oriented.
Architecture Limitations in Addition to nikic's answer
Writing extensions for PHP is a PITA. Not as bad as with Perl or Java, but not as easy as it could be. The ease of extensibility champion is still TCL which hails from the early 90's. Nearly any C function taking char* can be made into a TCL extension.
Embedding PHP in other systems. mod_php, gtk.php.net shows it can be done, but Guile and TCL are much easier to embed.

Why do you not use C for your web apps? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Closed 2 years ago.
Locked. This question and its answers are locked because the question is off-topic but has historical significance. It is not currently accepting new answers or interactions.
I was having a look at a few different web servers this morning when I came across G-WAN. As I understand, its a web server written in C and you have to make use of it by writing your websites/webapps in C. One clear benefit is speed as the G-WAN site suggests.
However, on the forums, the creator of G-WAN asked why not use C for web based apps and I can not think of a single reason apart from it being difficult (for me anyway, I am newbie when it comes to C). There must be more reasons why we all use PHP, Python, Ruby etc apart from it being easy to develop in these languages. I don't see that as a good reason.
So I put it to you: Why do you not use C for your web apps?
It takes a great deal of care to get a C program correct and secure. That care means that you need to have really good people writing your programs. That means you pay more.
Also, C doesn't have the benefit of drawing from an enormous single standard library of functionality as .NET (and the other major web-centric platforms) has. So you may have to either buy components, or perform interop, or roll your own functionality which comes "for free" with a more, shall we say "web-centric" language like PHP or C# or Ruby or whatever. That means you pay more.
Add all of that to the fact that single-threaded computational speed just isn't that important on the web. If you need more scalability, most organizations can economically just throw more cores at the problem and be fine. This is not true for everyone, of course. I'd imagine that the core of Google's engine is written in C or a similar language not only for speed, but to save real money in power costs.
Hum...
It seems that I am a bit late in this discussion - but I just discovered it now. And I am grateful to all of you for so much input.
I am G-WAN's author, which makes it clear that I have seriously worked on the matter: G-WAN is both faster than all other Web Servers (no processing) and all other Web Application Servers (any processing you can imagine).
Yes, ANSI C also made it possible to process more static content - with less powerful CPUs (ANSI C is not only about making dynamic contents fly).
By the way, G-WAN uses C scripts (no C compiler and linker needed) so the compiling/linking cycle/delay does not exist.
In the process of comparing G-WAN to .NET Java and PHP, I wrote similar applications in all 4 languages: http://gwan.ch/source/
And, to my dismay, the modern scripting languages were not easier to use.
One part of the job which is especially frustrating is to desperately search for the 'magic' API call that will do what you want to do.
Think about how to do 'pretty thousands' in:
C#
String.Format("{0:n}"...
Java
new DecimalFormat("0.00"); ...
PHP
number_format($amount, 2); ...
ANSI C
sprintf("%'.2f", amount);
The "..." mean that some pre-configuration, or post processing, is necessary. ANSI C is clearly easier to use and to remember.
When PHP has more than 5900 API calls (C# and Java not far away), finding the right API call is a challenge on its own. The time wasted to find this (and then to find how badly the native API call is implemented), the time to learn by hart it for the next time you need it, all this time is depriving you from the time necessary to resolve your application problems.
I have read (above) that PHP is more concise than ANSI C? Why then use "//:: this is a comment ::" rather than "// this is a comment"? Why have a so stupidly complex 'pretty thousands' syntax?
The other usual argument is that Java and the like provide dedicated calls for Web applications.
I was not able to find anything to escape HTML in Java so I wrote my version of it:
// all litteral strings provided by a client must be escaped this way
// if you inject them into an HTML page
public static String escape_html(String Name) {
int len = Name.length();
StringBuffer sb = new StringBuffer(len);
boolean lastWasBlankChar = false;
int c;
for(int i=0; i<len; i++) {
c = Name.charAt(i);
if(c == ' ') sb.append(" "); else
if(c == '"') sb.append("""); else
if(c == '&') sb.append("&"); else
if(c == '<') sb.append("<"); else
if(c == '>') sb.append(">"); else
if(c == '\n') sb.append("<br/>"); else {
c = c&0xffff; // unicode
if(c < 32 || c > 127) {
sb.append("&#");
sb.append(new Integer(c).toString());
sb.append(';');
} else
sb.append(c);
}
}
return sb.toString();
//szName = sb.toString();
}
Do you really believe that the same code in ANSI C would be more complex? No, it would be both immensely simpler and faster.
Java (derived from C) is requiring programmers to link multi-line strings with a '+'
C# (derived from C) is requiring programmers to link multi-line strings with a '+'
PHP (derived from C) is requiring programmers to link multi-line strings with a '.'
ANSI C does not have this now completely stupid (obsolete) requirement.
So, were is the so obvious progress claimed by the modern languages? I am still looking for it.
Sincerely,
Pierre.
The same reason we don't use C for most programming. The benefits (which are mostly performance) don't outweigh the costs (development time, lack of automatic memory management, lack of automatic protection from buffer overflows, having a compile stage between the edit and test stages, etc).
Most network applications, especially web servers, are far more "I/O bound" - ie they are capable of pumping out data far faster than the network can accept it. Therefore something that is highly CPU efficient is not a huge win, whereas something that is scalable and maintainable is. So there is no reason to accept the drawbacks of C and lose the advantages of a managed environment like Java, .NET, Python, Perl or other languages.
C isn't a convenient language for manipulating strings.
Compare C#:
string foo = "foo";
string bar = "bar";
string foobar = foo + bar;
Corresponding C:
const char* foo = "foo";
const char* bar = "bar";
char* foobar = (char*)malloc(strlen(foo)+strlen(bar)+1);
strcpy(foobar, foo);
strcat(foobar, foo);
//todo: worry about when/where the foobar memory
//which was allocated by malloc will be freed
If difficulty and complexity were not an issue at all (ha!), then I wouldn't stop at C. I'd write x86 assembly. It's been years since I've used any web server that wasn't x86, and it's looking less and less likely every day.
To use C (instead of assembly, or something higher-level) is to suggest that C is the sweet spot of programmer efficiency and computer efficiency.
For the programs I write, this is not the case: C is a poor match to the kinds of programs I want to write, and the advantages of it over a decent macro assembler just aren't that significant. The program I'm writing right now is not hard in my HLL of choice, but the complexity of it in either assembly or C would be so high that it would never get finished. I acknowledge that a sufficiently smart programmer with enough time could make it run faster in assembly or C, but I am not that programmer.
it's insecure
it's hard to read
it's hard to maintain, development time is slower on the order of a magnitude
most of your web stuff is probably I/O bound, so the would be speedup doesn't even matter, especially when you use a fast language like Java or C#
I know this question has already been answered to death, but there are 2 things not mentioned so far that are extraordinarily important to success in any programming paradigm, and especially in web development where you get a lot of people that aren't necessarily programmers, working with the code.
Involved, useful community, aka People That Have Solved My Problem Already. It's pretty easy for even the noobiest of noobs to Google why they're getting "headers already sent" errors in PHP, whereas that information might not be available for a framework or language that is new to the scene, or otherwise doesn't have critical mass.
Frameworks, so that most programmers can get to solving business problems and not hacking code together.
If I had a critical app that required extreme performance, I would use C, but it would take so much longer to write, that I would never get to market. Until there is either #1 or #2 it's not feasible for me to use it.
C is quite low level languages for many purposes: no-OOP, lots of manual resource management.
There is limited use of C for web, for example Klone. It is mostly used for low resource embedded application cases.
However there are C++ web frameworks like CppCMS that are used for high performance web applications developments.
C++ allows you to enjoy high abstraction and fine grained access to what you are doing exactly giving much better option for deploying and developing large applications.
But you use them in case when performance and resource usage is much more critical
then time-to-market and development costs as generally web development is faster
using good web frameworks for languages like Java, Python or PHP. Also generally
there less competent programmers for C++ then Java/P* languages for same salary.
So it is question of priorities, also there less tools for C++ Web development then for PHP/Python/Perl or Java.
There must be more reasons why we all use PHP, Python, Ruby etc apart from it being easy to develop in these languages
This is the entire reason and the only one needed. It has many benefits, chief of which is time to market. If you can get your Web app online in a month using PHP instead of two months using C, you might just win. If you can add a new feature in a week using Ruby on Rails instead of two weeks using C, again you win. If you can fix a bug in a day using Python instead of two days using C, you win once more. If you can add a feature because you are using language X that your competitors cannot add at all because they are using language Y and it's too hard in that language given their resource constraints, then you definitely win.
And by "win" I really mean you don't lose. Your competitors are using higher-level languages and frameworks to develop their sites, so if you use C, you are not competing with other people who use C, you are losing against other people who do not use C. Just to compete, you have to use tools with similar levels of abstraction.
If performance becomes an issue, you can rewrite the slow parts of your site in better-performing languages. Or you can just throw more hardware at it. Really, a performance problem is what we call a "nice problem to have" -- it means you have already succeeded. But spending more time developing the basic functionality of your site is rarely an option. Writing it in C just so it will run faster is premature optimization, which, as Knuth tells us, is the root of all evil.
All this implies that if you can use a language with a higher level of abstraction than Python or Ruby, you could win against people using Python or Ruby. Paul Graham's story of how he and his team used LISP as a "secret weapon" in developing Web sites may be instructive. http://www.paulgraham.com/avg.html
Of course, if you are developing a site for your own amusement, do it in whatever language you want. And if your site is CPU-bound (hardly any are; they are usually I/O bound) then use the fastest-performing language you can. If you are trying to innovate, though, use a high-level language with the best abstractions you can find.
#Joeri Sebrechts
F.U.D. in action:
PHP, Python and so on are easy to scale up by throwing hardware at the problem.
Well, actually no. They don't scale at all vertically and scale very poorly horizontally.
See: http://gwan.ch/en_scalability.html where it is explained how much trouble is ahead of
bad-performers.
Suppose it costs 1 person 1 year of effort to develop an app in PHP, and it costs
them 3 years to do it in C (as C requires more effort to do the same thing).
Wrong again. If PHP libraries have been written in C then they are directly usable
from C -instantly providing the 'unique productivity' you are claiming PHP has.
That means the reduced hardware need of the C code has to represent 2 years
worth of wages for C to become attractive. In practice that (almost) never happens.
Pure F.U.D. (see the answer above).
Facebook's scale is so large that hardware is a big enough cost to care.
That's why they developed HipHop, which cross-compiles PHP to C++.
It brings the best of both worlds: the simplicity of programming in PHP,
and the raw performance of C++. Facebook is still developed in PHP, but
when you use it, it's all native code.
HipHop is much faster than PHP, no doubts on that. But if you compare
HipHop with a plain-C implementation you have two layers of overhead:
the PHP to C++ interfaces (which use the bloated C++ libraries);
the C++ bloat itself (which makes C++ 2-10 times slower than plain C).
Plus, HipHop has been written in the clueless inefficient Academic mode
(detached from any real-world reality). sure, it can impress PHP coders
but show this code to an embedded programmer and he will feel sorry for
Facebook.
"A language that doesn't have everything is actually easier to program
in than some that do" --Dennis M. Ritchie
Unlike (most of the) programming language END-USERS, Dennis knew a couple
of things about the matter, it seems.
You think being easy is not a good reason. I think it's a good reason. If you need ultimate performance then C is ok, but other languages abstract away the hard stuff to improve productivity, maintainability and reduce defects.
Consider that I'm not a web developer but will ask these questions anyways and offer a point or two.
What web site is only written in one language? Seriously this thread seems to assume one hammer fits all nails.
When was the last time anybody seriosly stated that C was complex? I mean really guys you can't get much more low level. I'm not talking C++ here as the two are often referenced collectively.
C has security concerns, that can't be denied but are they any less than what is seen in the kludges called PHP & Perl? In either case a secure web site is a function of programmer discipline.
In any event off to the comments. The difficulty of using any given language is very dependant on the problem at hand C & especially C++ can lead to fast solutions to a problem in experienced hands.
Industrial uses for web servers, that is embedded servers/sites simply don't have the language choices a normal web server might have. So you end up using a variant of C or possibly something like BASIC. Your goal is to offer up the functionality the device requires and not to worry about languages. On a mainstream web server the way to do that is with high level languages most of the time. Walk away from big iron and your programming freedom goes out the door.
Without the right Libraries it would be foolish in most cases to do a ground up web project in C. The lack of good standardized libraries is a big negative here.
Here is some more web-related code written in C that is worth a look when building your own C library for the web:
cgic: an ANSI C library for CGI Programming
cgit: a web frontend for git repositories
wbox: HTTP testing tool
wget html-parse.c
curl cookie.c
Discount, David Parsons' C implementation of John Gruber’s Markdown text to html language
Protothreads (esp. for embedded systems), http://www.sics.se/~adam/software.html
protothread, Google code project by LarryRuane
uriparser sourceforge project
http-parser, http request/response parser for c by Ryan Dahl on github
nginx
...
Well, given the fact that Web development is a matter of having useful libraries (the kind used by PHP) then I do not see how C would not be useful.
After all, the procedural logic is the same: do while, for, if then else, etc. whether this is C, PHP, .Net or Perl.
And a C loop or test is not more difficult to write because it is written in C.
Most PHP libraries are made in C so the missing-C-libraries-for-the-Web argument does not look that much convincing.
My guess is that C was not advertised as a Web programming language by the promoters of Java (SUN) and .Net (MICROSOFT) because they had their own proprietary (heavily patented) intellectual asset to push for adoption.
As a free (unpatented) standard, C does not offer any 'lock-in' grip on developers... hence, maybe the heavy hand of lobbying in schools and universities to make sure that tax-payer money will fund the adoption of an inferior technology backed by private interests.
If C is good enough for IBM and MICROSOFT (they don't develop their products in PHP or .Net) but not good enough for end-users, then end-users might wonder why they are invited to suffer this double-standard.
I would use C for a web app if:
I have a little budget for the hosting server (small VPS) and my time is not expensive.
I am working for Facebook, Twitter or someone in need to reduce the amount of servers used (with thousands to millions of users).
I want to learn C and I need to find a real world app where I can use it.
I know C much much better than other scripting languages.
I am an eco guy and I want to reduce the carbon footprint of my app.
G-WAN runs code as scripts, yes C scripts like Play! Framework does for Java. G-WAN is very fast and has an easy API. G-WAN makes possible to use C/C++ for web apps when other servers has failed to do that.
One thing is clear: you need a good programmer to write a web site in C, any crappy developer can create a site with spaghetti PHP :-) There are leak detectors and even garbage collectors for C.
All the languages you mentioned are actually written in C/++. The only difference is the advanced classes and libraries that were created from C that make up what is now these other interpreter languages. It is also why they are referred to as scripting languages.
Think of it like baking a cake (PHP/JS):
2 Eggs, 1 cup Milk, 2 sticks of Butter, 4 cups flour, 1 cup Sugar, Baking Soda
But imagine having to make all the element that those things are composed of. (C/++)
17 mg of sodium bicarbonate, 15 tbs of protein, 12 tbs of Vitelline Membrane, Amino Acid, Sulfur, ... Neutron Particles
C is the foundation of many modern languages. It is great and almost the most powerful languages under assembly. You can do it you just need to invest in building all the code that these other languages already did. Like building a cake from the periodic table.
Learn it you can literally make it do anything!
String handling in C can be made easier using:
Data Types (part of libslack)
Libslack provides a generic growable pointer array data type called List, a generic growable hash table data type called Map and a decent String data type that comes with heaps of functions (many lifted from Perl). There are also abstract singly and doubly linked list data types with optional, "growable" freelists.
or:
Managed String Library (for C)
http://www.cert.org/secure-coding/managedstring.html
Another point might be the platform dependency. C needs to be compiled into native code. This code doesn't run on all platforms.
Interpreted languages run wherever an interpreter exists. Many providers for example provide PHP-Interpreters installed on their servers but with a Windows OS. If you now are developing on a Linux-machine. You've got a problem.
Of course this problem could be solved but you see the advantage of developing in PHP in this particular case.
Hope this helps,
regards domachine
"domachine" wrote:
platform dependency: C needs to be compiled into native code.
This code doesn't run on all platforms.
Interpreted languages (like PHP) run wherever an interpreter
exists. Of course this problem could be solved but you see
the advantage of developing in PHP in this particular case.
Did you ever wonder in which language the portable PHP interpreter is written?
In ANSI C.
So, before you dismiss the portability of ANSI C again, ask
yourself in which language your favorite programming language
has been written... (tip: almost all were written in C/C++).
ANSI C compilers are available on all the platforms I had to
work on -and the same is not true for PHP and its gigantic
runtime.
So much for the portability argument.
Similar to G-WAN, but for Cocoa / Objective-C is Bombax, a web applications framework.
http://www.bombaxtic.com
Speaking of Objective-C I can't resist pointing out MacRuby, which has the potential to revolutionize the way we will make web apps one day.
PHP, Python and so on are easy to scale up by throwing hardware at the problem.
Suppose it costs 1 person 1 year of effort to develop an app in PHP, and it costs them 3 years to do it in C (as C requires more effort to do the same thing). That means the reduced hardware need of the C code has to represent 2 years worth of wages for C to become attractive. In practice that (almost) never happens.
Like with every rule, there is an exception. Facebook's scale is so large that hardware is a big enough cost to care. That's why they developed HipHop, which cross-compiles PHP to C++. It brings the best of both worlds: the simplicity of programming in PHP, and the raw performance of C++. Facebook is still developed in PHP, but when you use it, it's all native code.
In the end you can use absolutely any language to develop sites, including assembler (via CGI etc.). If you meant why don't we use a compiled language, well, we already got .NET, Java and others.
You have to love what you're doing to achieve results. Languages like java and php were created with lot of effort to make people's lives easier. Php especially has benefited many self learned web programmers today. You can see the kind of support it has in the world of web development.
Java iam sure was written to give you help in anything that can be possible in today's world. The enormous book is a clear indication, and it's a beast if you are looming for web development as well. Same goes for Python. These are so.e fantastic languages and platforms. No wonder they are hugely popular.
I am a C devotee and partly it's due to certain limitations which precluded me from giving a look at other languages like php. I am writing in C daily and every day I am proud to e and learning a new thing also. This makes me feel very good and I have also started learning about how C was the default choice when writing applications for websites through Cgi. This is abstracted in other platforms and when you develop websites that have to do with databases and web services, you need to know what's happening behind the scenes.
However if you know all that and still want to use a scripting language, there must be a valid reason, and we don't need anyone to advise against that.
10+ years have gone by since the OP asked this, and Google search trends (within the genre of web programming) still show this as an active debate. I want to give a 2021 answer to this one, and since I've been programming professionally since 1979, and have used every aforementioned language exhaustively, I feel quite qualified to answer it.
More internet devices use C than any other language. They just aren't usually the public facing devices per se (Cisco, F5 networks, etc -- their cores are all compiled in C). But these are embedded platforms with a purposeful function that require almost RTOS-like stability. C will continue to be the dominant language here - it's so old that instability issues aren't a factor.
Big Tech uses C all the time ; you aren't going to find a cron job in their stack that does does a log flush or backup being written in bash or in PHP ; if it's complex it's likely that it's a gcc-linked binary that's doing the heavy lifting. Nothing is as reliable as C since it's been around forever and we're not finding new bugs in gcc.
The tech companies during the 1990s really built up the core of the technologies we use today, and C wasn't sexy [at all] to use. Many apps were developed with Java Servlets and applets which is quickly conducive to an MVC model and it's cross-platform. The latter is very important - as I'll explain.
Microsoft didn't quite embrace C or C++.. their Visual C was a terrible IDE compared to Borland's. But Visual Basic was a hit for them, though, which is why VB became ASP classic - which many websites still use today. It was the first language IIS officially supported (VB or Basic). Classic ASP is considered an old language with no support from MSFT anymore, but its usage was widespread in early web apps who wanted to use Windows NT (or Server) for their development. Bill Gates really wrote the best Basic interpreter back in the day, and the simplicity of Basic allowed for a very quick learning cycle to become a developer. However, Borland's IDE was amazing, but the company blew up (along with Novell and other greats from the 90s).
Nobody in their right mind in the 1990s were developing web apps quite yet for Linux, really.. other Unix derivatives, yes - but commercial versions of them. Many people deployed completely different OS's altogether (think of AIX or DEC VMS here). The words "free" and "great software" wasn't often part of the vernacular. IT managers, who became the de-facto original webmasters, didn't want their paycheck to ride on something free (Linux) because in part the distributions were fragmented (perhaps excluding RedHat's or Mandrake's).
IT Managers weren't programmers - so scripting languages became more popular for web development. Websites written completely out of bash were not unheard of.
Java (which is based on C) became perhaps the most popular notion of the future of the web, partially because Sun had great hardware and was renowned for their Solaris OS. Most C programmers who were interested in the web moved onto Java, it was pretty similar and offered concurrency (C wasn't designed as a concurrent language) and mostly stable garbage collection and memory clean up techniques.
VB devolved at MS and, seeking a compiled language for IIS, moved it up to what's now the .NET framework which is simply VB or C# wrapped in complexity. But IIS's weaknesses were overcome by the sheer number of Windows NT/2000 deployments.
The bubble burst and Oracle's Java, Solaris and DBs weren't a favorite amongst IT managers (though it was a favorite with executives because Oracle's sales team were top-notch). For one, Oracle's products were extremely expensive and they weren't (and really still aren't) known as a cutting-edge technology company.. they are the IBM of late - deploying what works and isolating more of the business problem than the technical one.
Post-Y2K, Linux out deploys just about everything on the web because the distributions started really getting to a commercial-level. This whole idea of open source was working. Windows was suffering from virus issues repeatedly and Apple was written off as a dead entity. Commercial platforms were becoming more under fire as CFO's were tightening budgets.
Linux started with a legacy PHP interpreter from the get go and the language has really grown from there. Most who deployed Apache would use this language simply because it was stable. Again, at this point we still have IT managers running these efforts.
Mid-2000s when Marketing functions started taking over the web presence of their respective companies, the needs quickly changed. Marketing folks love testing (think multivariate A/B campaigns) and so scripting languages really started sneaking up as the best way to accomplish quick changes that could be pushed to the web without having to hardcode HTML.
We forget, the ECMAScript (Javascript) really took off, Flash started to die, and so this whole idea of how to control the DOM came about when faster and faster browsers were able to leverage the UI.
Of all the modern languages out there, the frameworks really have usually been responsible for propelling the success of newer languages. Bootstrap was quickly absorbed when mobile came about, and integration with a legacy PHP app was easier than it would have been with a hardcoded C app. We started seeing mostly scripting take over compiled languages as the choice-du-jour, though .NET has it's place for certain things yet, though that's diminished in the last 2-3 years.
In the end, C is still the most widely used language "behind" the internet. Routers, load balancers, intrusion detection systems.. it'll all be in C (or C++ but more likely, C). These appliances are now moving to being software deployed but the hardware appliances are still used by the larger datacenters. For example, AWS has a wrapper around a grouping of Cisco switches to change the routes based on ToD (time of day) predictions. Amazon, Google, Facebook all realized that a "follow the sun" model of load balancing was a good starting point and really could only trust that to low level hardware devices to correctly do that. Scripting languages and even compiled ones are surfacing that are - for all intended purposes - really based on C anyway. But with the advent of k8s and Docker it makes more sense to rip a node.js framework and start working on a small unit of code that could be pushed independently of what the other pieces of code was doing. Outsourcing was used alot in the earlier days and this is about the only solid way of programming a system without conflict in a larger development environment.
We are still at the beginning of the internet.. in other words, in another 10 years there will be yet another cycle, and it'll likely be away from typing. Drag and drop DAG nodes will be used to create web apps in a similar way that a VFX artist uses Nuke or Maya to build a motion graphics clip. Twilio does this and even training an ML model is already beng done this way using Peltarion.
We're not yet to the highest level languages possible, as our abstractions in Ruby or PHP are still C-like, and throwing dollars at STEM education won't bring in legions of kids to study computer science. However, the barrier to entry will continually be lowered, but the need for a diverse understanding of languages will still be required for the complex applications or specific applications that require "something" like directly addressing a CUDA core (for example).
We are simply seeing a diversity in languages, as predicted by Ritchie himself, come about. Frameworks have matured so it makes no sense to drop a new developer on a C+CGI project when bringing up an Angular scaffold takes 5 minutes.
This was all expected, actually, by most of us from the 1980s. As programmers become diverse, so do the ways to attack the problem in front of them. As open source becomes evermore possible (and incredible!) there's simply no financial advantage to starting something from scratch. Headless CMS systems in fact are already being deployed so that the backend of the CMS doesn't require the dev team to write a line of code - they just worry about the user experience... and even then, the tools are getting more mature.
My point is this: C is definitely used on the web, and embedded systems use it all the time. MVC applications have progressed to where a framework can build a simple app for you within an hour, without compilation, and it happens that those frameworks are more extensible on the newer languages. It's an apples to oranges comparison for me - I still use C to do data normalization (for example), but if I'm being paid to write a web app, I can begin a Vue.js app while drinking a beer, so why work harder?

Is it worth learning C as a web developer? Will I ever use it? [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 11 years ago.
As a web developer, is it worth me learning the programming language C? Will I ever need to use it? I am currently using PHP and Ruby on Rails.
The unending pain of getting C programs to actually work reliably will teach you a lot about why PHP is a more civilized way to write software.
And yes, you'll use it eventually.
Some day you'll run across a problem ill-suited to PHP or Ruby. You'll be able to fall back to C and look like a hero because you know something more than other folks.
Not really. If anything, learn C because it is fun, and a great language to help you learn more about system internals. Working on web development is very high-level, and you won't get much chance to really get in-depth with the system. Using C can help you better understand how instructions are executed at a low level, how memory management works, and how to create a lot of the things that PHP / Ruby have built in.
Joel Spolsky urges computer science students to learn C:
"Advice for Computer Science College Students" (January 2005)
Learning Latin has it's benefits for understanding the structure of modern derived languages; so in that vein, I say why not?
I've found it very useful knowing C as a web developer. For example, one web app I've written includes a photo gallery. It stores the photos outside of the webroot so that it can check the user's permissions before showing the actual images.
Eventually, I discovered that the overhead for displaying a page full of image thumbnails was incredibly high using the web app in PHP. So, I rewrote the actual photo display code in C as a cgi program, which reduced the overhead to almost nothing.
I don't think learning ANY new language is ever a "bad" idea. Specifically to C, it can only give you a better understanding of how the languages you are using run "underneath the hood".
As others have stated you may not use C, but there are still a number of important concepts relevant to computers and computer science. Some insights can be gained from such classic texts as C Programming Language, by Kernighan and Ritchie.
This includes
Example of very good documentation and writing style in explaining a language in a brief document. You'll find that the complete language is explained in a book not much more than 100 pages. Compare this with some of the tombs of books sold today which position themselves as teaching a language and yet are often more than rehashed API manuals.
Understanding pointers, memory management, arrays and character indexes. All good information which aligns with core computer subjects; albeit low level, but a worthy piece of information for an professional programmer.
Its an easy quick reference book. Again you won't break an arm lifting it and yet gain a lot of knowledge from it.
In general C is useful for those occasions when you really do have to get closer to the machine or need to extend a language through use of a C-API.
Firstly, you have to define "web developer." Are you building websites or web-based software? While both of these tasks easily can fall under the category of "web development," they are somewhat different in terms of the skills set you need to be successful at it.
You're more likely to run into background processing and file/operating system interaction with software than "just" a website, and thus increasing the probability of using a low-level language like C.
Having said that, will you ever use it? Unlikely. High-level languages have been introduced by the dozens to tackle web development. From a web development point of view, if you're having to resort to C, it's most likely because you don't have the necessary skills in more suitable languages. Remember the massive amount of sites and software solutions of varying sizes that run fine on PHP and Rails.
Is it worth learning? Maybe. If you feel like you need hardcore programming skills to complement your web development skills and you have time to spare; go for it. If not, don't. You're probably better off getting really good at Ruby/Rails instead.
Speaking from my own experience, insofar as going from Python to C (and back again, woo!): Yes - learn it.
If you haven't already, learn fundamental, low level data structures; learn them well.
Learn what really makes an HTTP post tick, maybe write some low level debugging tools for yourself and others. It's amazing at how "under the hood" you can get in web development, when you can write an apache module. (Huzzah, bucket brigade!)
Learn the in's and out's of setjmp/longjmp, and perhaps come out with a better understanding of exception handling - that is, how it really works under the hood - in higher level languages.
You might never find yourself writing a line of C code for web development, but if you learn the language well, you'll be giving yourself an edge, all the same. Just be sure not to cut your toes off with it. (:
You'll probably never have to use it, so if you just aim at "usability" just forget it. However, learning C is a good way to get a grasp on the fundamentals of programing. You'll probably gain a much deeper understanding of PHP and RoR for free.
Bug generally, if you feel confident in your languages, no -- it's not worth the price ;).
Although I don't use C anymore, I find it useful to be able to talk to other programmers in their language. You may not have the expertise to solve a particular problem yourself, but you can talk intelligently to someone who can.
The same goes the other way, of course.
And, as pointed out above, C is the foundation of just about every other language that has come after it.
Learning a new language is always a pleasant experience and have a positive impact on the way you program.
Are you going to use C in web development. The answer is, most likely, no. Unless you are going to code a PHP extension or a custom web server.
Its always good to learn a new language , since you are already using Ruby and Rails framework . Knowledge about C programming will come handy when you are trying to learn in depth about Ruby scripting language , Since Matz Ruby Interpreter or MRI is written in C . And also most of the Web servers are written in C and C++ programming language .
Once you have an Idea how Web Servers works , you have an edge in creating a scalable applications , and will also able to analyze plus and minus of the Web Servers above which you are deploying your application.
"Be Jack of all you can be Master at any programming language and at any point of time in your Career" ....:)
Learning more languages is always a good idea. C is great, because a ton of languages are officially or unofficially based on it, and knowing what happens at a lower level can only help.
OTOH, to really advance your knowledge, I'd suggest learning a language that is as drastically different from what you know as possible - Erlang, LISP, Haskell, Smalltalk...
I'll put it this way. C is nuts. It was written in a time before people thought in entirely object-oriented ways. It will frustrate the crap out of you. Its hard to understand AFTER learning things the way you know them now.
But it is immensely helpful in understanding how everything else runs. Its a great language to help you transition to other languages because most modern languages inherit from or are built on it (syntax, data constructs, etc).
Moreover, both Ruby/Rails and PHP are based heavily in C. A lot of supporting libraries are written in C for those languages. Its crazy fast because it's compiled and is quite a bit lower-level, has a much smaller API than either PHP or Ruby/Rails.
I would definitely recommend learning it, even if its just for the fun of learning a new language. My prof always told me: "If you can give me a manual and a project worth working on, and I'll learn any language." So if you can find those two things, go for it!
I say, I say, I say:
Yes... but just a bit.
Just least some very basics: strings, pointer manipulation...
Even if you never actually use it, you'll get much better understanding about performance issues in higher lever languages. Consider strings we're working with all the time:
links are hard by Joel Spolsky
If you learn there is a great chance of achieving success, otherwise there will be no doubt.
Learning languages is never a bad thing. But as a web developer I think your time would be better spent honing on another technology. I've delved in Rails, and Java, but think if I really wanted to learn something new as a web developer, I'd be all over Django, google app engine, javascript, silverlight, flash ... and a handful of other technologies before I even thought about c.
In my opinion, for someone who writes software that runs on a computer, learning C is like learning Latin or Greek for a scholar of anthropology or literary science.
A significant body of the work that has been achieved in software development today has been done in C and that is what you really want to learn: it's not so much about writing your software in C, it's about being able to understand. Both what is possible and what has been done. Were everything comes from and also why we are moving more and more away from C in many areas.
Happy Segfaults! ;-)
The opportunity cost of learning C is high - you can learn something practical instead.
If you are a web developer and wish to continue to be one, it would probably make more sense for you to learn something more applicable to your field: Ruby and figure out how Ruby On Rails works, Python and how Django works, C# and how the MSFT MVC works. Or Flex. Or JavaScript and mooTools/JQuery.
While you can get a lot of basic computer science concepts out of learning C, you will probably never have to touch it. When/if you do, you'll learn it then.
If you wish to learn computer science ( not just slightly lower-level programming ), you can try Project Euler or some algorithms, operating systems, etc literature.

What to learn after PHP? Scala or Clojure? [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I have a heavy web dev background with PHP. My reasons for learning a functional programming languages are:
to improve my programming skills. It was heavily suggested that learning a FPL helps. this has high priority because I want to be better and better.
learn a general purpose programming language to solve tasks like scripting (OS scripting, text manipulation etc..)
to be used as an alternative for PHP in web development.
Also which has the better community support, tutorials and books and the better web application framework?
Feel free to suggest other languages.
For functional languages, learn both Scala and Clojure. You'll learn new ways of thinking from both of them. Go learn some Reia and Erlang while your at it too.
Seriously, the more languages you have under your belt, the better off you'll be as a programmer regardless of the language you end up using.
Rant: "What language should I learn?" questions are getting tiresome. The answers should be the same every time, yet no one gives the correct sage advice. Instead, everyone spreads FUD and suggests that the language they happen to use for their day job is the one you should learn. Poppycock.
I've tried both Scala and Clojure recently, based on similar motivations. Here's what I found:
Scala is enormously versatile and powerful; Scala lets you define types with great precision and it allows you to define DSLs that are terse and clean. Scala has a lot of cool constructs that one wishes Java had, including a bunch of functional extensions. But when it came right down to it, I ended up coding imperative Java in the Scala language because the complexity of all that cool stuff overwhelmed me.
I did some Lisp back in University, and always had a hankering to get back to it again. Some really cool cutting-edge stuff is done by very smart people in Lisp, and in very few lines. I wanted to be one of those smart people, or at least try to be like them. But I never really understood Scheme, and I missed my "infinite supply of libraries" from Java. I couldn't see myself writing a GUI in Scheme, and had trouble envisioning a Web application.
Then I tried Clojure and it seemed like everything clicked into place. Clojure was intentionally made more outsider-friendly: There is an attempt to cut down on the parentheses and to use different parenthetical punctuation for different situations. Treating things like arrays, text and XML as sequences, combined with a powerful set of sequence functions, made a lot of problems quite simple, as does the support for arrays and hashmaps. It's (intentionally) like functional Java. The functional mindeset takes a bit of getting used to, but nowhere did I find it as approachable or as enjoyable as in Clojure. My code hardly needs loops any more, yet it's more clear about where it's looping/sequencing, and more concise. I can do mutable state if I really need to, but I have to be explicit about it; in exchange, that state is protected by Clojure's concurrency mechanisms. Concurrency, then, becomes almost a no-brainer, sometimes my code executes safely in parallel with no conscious effort of my own.
Not coming from Java, this will not seem very useful to you, but Clojure can do anything that Java can, including fully compatible .class files. Most importantly, it can interface with all Java libraries, and that ability alone will make PHP seem like a toy language to you.
My suggestion is to learn JavaScript.
I mean, really learn it.
Here's what a self-professed Clojure advocate has to say about Scala. Make up your own mind, of course, but you may find his perspective useful.
Scala Vs Clojure — Let’s get down to business
Scala vs Clojure — Round 2: Concurrency!
You may also be interested in what he has to say about PHP vs Clojure.
That's a very difficult call. Personally, I think Scala is more useful as a general language for web developers. There are many web frameworks for it, or adapted to it. On the very quick&dirty side, for instance, there's Play. On the full-fledged with excellent Comet support side, there's Lift.
But you talked about learning to program in a functional style. In that regard, there is no way Scala can compete with Clojure. Scala can be used in a functional style, but it makes sure you don't have to. With Clojure, on the other hand, doing anything but functional style is painful.
So, if you want an alternative to PHP, I'd bet on Scala. If you want to really learn functional programming, Clojure.
Finally, let me state that I do not think Clojure isn't a general purpose language, or that it can't be used for web development. I just think Scala is more on both regards.
Get a bag of cement, harden up and Learn You a Haskell, for Great Good!
It's purely functional, so you cannot fall off the ship.
It's general-purpose with loads of libraries (including a web application stack), and no VM startup time penalty (JVM languages are not great for OS scripting and the like, since you have to start the JVM every time).
Jumping form PHP to Scala or Clojure is going to be a huge culture shock. PHP is very focused on quick/dirty getting things done (or 90% clean with the last 10% dirty (-:), whereas functional programming languages force a certain correctness and abstractness onto your thinking. Before you get to Scala or Clojure, you're going to want something inbetween. If it was me, I'd
Pick my final target as Clojure, since (as I understand it) you get the entire Java standard library with Clojure, making it immediately more useful than something pure like Scala
I'd spend some time building something in Java, just to get a feel for a strongly typed OO language. I picked Java over C# (or even ZendFramework style PHP) because it will prove useful once you arrive at Clojure. Google Web Tools might be a good place to start with this. It's kind of web development, but very very Java like and not at all PHP/HTML like.
Spend some time looking at the guts of jQuery, and either develop your own jQuery module or add a core feature. This will get you used to the functional way of thinking, while applying it to a problem you're familiar with.
Final bit of advice: Try to embrace the common methods of the language/platform you've chosen. Don't try to bring your style of PHP coding to either language. Although it will seem easier at first and let you get some kind of results, you'll miss the point of the exercise, which is to think differently and more broadly about problems.
Good luck!
If you are looking for a good alternative for PHP, I suggest Python and Ruby. If you need a Functional language with good support for web development - learn Erlang. Here are some projects/frameworks that will help you create highly scalable web applications in Erlang:
Yaws - An Erlang webserver particularly well suited for dynamic-content webapplications. (Also see this Apache vs Yaws benchmark)
Erlyweb - A component-oriented web development framework written in Erlang and designed to work with Yaws.
Erlang Web - The Erlang Web is an open source framework for applications based on HTTP protocols, giving the developer better control of content management.
Nitrogen - An event-driven web framework for Erlang.
It is also one of the few languages that is specifically designed for building fault-tolerant, distributed software.
While it gets less press coverage than Clojure and Scala, I'd really recommend you to take a look at Fantom: http://fantom.org/
It's like the best of all both worlds and really should deserve more attention.
I'm a new convert to Clojure. It's making me expand my mind but it's approachable enough to be fun and productive. I'm a happy customer.
But
PHP and Clojure live in different universes. I've had some introductory dabbling in FP languages, and a few false starts into other Lisps before embracing Clojure. For a less experienced developer coming straight from PHP, Clojure might be too much of a culture shock.
As a reasonable compromise between the two, and a language that is scripty enough to let you approach FP on a gradient rather than a plunge, I recommend Ruby. Ruby is modern, clean and elegant. In its JRuby incarnation, it's even fast. Learning Ruby and playing with Rails is enjoyable and instructive.
Though Scala is my favorite language for now, i think it's not the best choice to learn FP. It's mainly OOPL with good support of FP. I would suggest to start from Haskell to quickly dive into FP. You will learn how the following concepts of FP work (which are not just supported, but enforced and ubiquitous in Haskell):
1) powerful static type system with type inference
2) lazy evaluation
3) side-effect free computing
After dynamically-typed "pragmatic" PHP and pure functional "academic" Haskell you will have quite full picture of programming languages landscape.
My $.02 is to check out Perl. I may sound like a geezer, but keep in mind that Perl has CPAN (http://cpan.org) and many very, very helpful online resources.
Ruby is probably the most "functional" mainstream language that's also good for scripting. Python is a close second, but ruby's habit of implicitly returning the result of the last expression in a function/block is the tiebreaker for me.
Both have excellent web frameworks (Rails and Django, respectively), and both will definitely broaden your horizons after programming PHP. At the same time they will allow a lot of opportunity for incremental learning.
Neither of them use S-expressions and both allow imperative programming, so there won't be anything to force you to give up the imperative style cold turkey.
Finally the much-lamented TCL is basically Scheme as a scripting and extension language. I'm not sure where it's at these days, but the ArsDigita Community System was written in TCL.
Web development depends ENTIRELY on: First, the quality of the web-framework and second the tools for development. I do not know why you want to move to functional languages for programming web applications.
Python allows some functional constructs for programming and it has frameworks and tools. Lua allows the same level of functional programming and it does not have either high quality frameworks for web development or tools, however its simplicity/primal-nature is its elegance.
Now as a puritan I'd say look at haskell, but that is counter-productive :D,. You my friend are looking for Python. I have not evaluated Ruby, but it might have some functional constructs.
May not appear so fancy, but I strongly suggest JavaScript.
A lot of years ago I was strong at PHP development, but then switched over to Java, C#, C, Objective-C. During my Java time I stepped deeply into JavaScript and did some pretty cool things with it. Someone I know developed an entire client-side temporary lightweight DBMS. Just have a look at Ext.js what they do with JavaScript. It's so underestimated, but doesn't deserve it. I suggest you google for "Douglas Crockford Video". At Yahoo he has created several excellent presentations about JavaScript, also I suggest you get the book "Javascript - The Good Parts" from Douglas Crockford, and "JavaScript - The Definitive Guide". Both the best JavaScript books available. And you'll be amazed what's possible and what a beautiful language it actually is. In fact, you can do AI with it, it has Lambda, there's actually nothing really "cooler" than that! What a pitty it's only used for clientside scripting. Few people know JavaScript can be used for serverside programming as well, but that's really rare / not well documented.
And thanks to Adobe Air you can bring JavaScript to the Desktop.
It would be an optimal addition to your PHP knowledge. It's always good to do related stuff. You can be the best Web Developer, or the best Desktop Software Architekt. But our brains are too slow to grasp all proffession needed nowadays to be the Guru in multiple directions. Beeing the Guru is essential for success, I think. Some friends of mine just do one thing: Beeing the Guru. They study their entire life one small subject and are extremely successful. They earn 5 times as much as any I-can-do-it-all-but-know-just-5%-in-this-topic-Developer in a quarter of the time only.
So I also suggest: Write a 600 pages PHP book before you forget your PHP knowledge while doing something totally different.
I did forget almost everything I knew about PHP and JavaScript, but in those early days I definitely was one of the expert guys who showed others a lot of stuff. Now it's a pain I have to ask so many basics again to recall them in my tiny brain. By writing your book, you'll recall your PHP expertise very fast even after a few years of doing something different, because it's your book, fitting your brain, from your brain. And you'll not loose your PHP-expert status even after several years of doing something else.
Good luck.
I tried Scala and found it a bit much (huge amount of operators that you have to recall how to use). But that could just be me. I've heard that Clojure is more functionally pure and closer to Lisp, but haven't checked it out.
F# is Microsoft's take on functional languages, you may want to check it out. I hear it has been used for several projects in industry.
I would suggest learning languages that have frameworks beyond the web front end such as Java EE (Java EE[JSP/JSF] + Java) or .NET (ASP.NET + C#, etc.). That would give you a bit more leeway with your career options, and you would be able to connect server components to a web front end with (relative) ease.

The Pragmatic Programmer: After PHP, what's next?

I'm reading The Pragmatic Programmer and I'm on the section where the authors suggest that we learn a new language every year. I'm currently a PHP developer and I'm wondering, what should I learn next?
I'm looking for a language that will help me improve my skills and help me with my daily tasks. Something useful.
Any suggestions?
[Edit]
Awesome answers guys! Thanks.
I'm still contemplating your answers and I'm leaning on studying Python or a functional prgoramming language as you guys have suggested (maybe Lisp).
Going for the option of learning something new, rather than something a bit like what you have done before.
C++ or C
A low level language that requires manual memory management and teaches you how things work at a lower level. Good community base and is one of the languages that a programmer should learn.
I would suggest one of these over assembly as although assembly is even lower level it is pain to produce a project. Learning a language like C or C++ will have the bonus of allowing you to learn assembly very fast if you ever want to do it, as there are relatively few new concepts compared to going from Java to assembly.
Haskell
A purely functional language that totally changes the way you look at some problems. It takes a lot of effort lean if you are already used to a imperative style of writing code.
It has the great advantage of teaching you the joys of recursion, and even if you are never payed to write a line of Haskell it should impact the code you write in other languages, allowing you to see better and cleaner solutions.
Java or C#
If you don't use PHP in an Object Oriented way (Not just using classes, but features like inheritance as well), then these languages force you to write in a OO style. I wouldn't recommend these if you are happy with OO programming.
Python and Ruby seem to be a relatively painless transition to/from PHP.
I'd go for Java or C#, so you learn something that is not another scripting language.
JavaScript.
And I mean really learn it, not just "enough to get by" the way the trend seems to be. I've seen otherwise-great (on the server side) web developers that can waste 2 days on a trivial JavaScript problem because they don't understand it at all.
I don't think there is a language that a developer will come across more often than JavaScript, and when you need to use it, you need to use it: you won't have the freedom of picking some other language to run on the clients browser. The good news is that it shouldn't take very long to grasp when compared to some other programming languages.
A good place to start is with JavaScript:The World's Most Misunderstood Programming Language
I believe it would be strongly beneficial for you to try and pick up on one of the popular functional programming languages as they require a completely different mindset and methodology for solving problems. They really allow for you to program elegant yet minimalistic solutions to difficult problems. Some of the more common languages include:
Erlang
Haskell
Lisp
Whilst I agree learning a new language is a good idea - make sure you are learning them and not just collecting them. For example - I come from a Java background and I keep catching myself writing in other languages in the way I'd write something in Java and not taking advantage of the new language's facilities. I'm sure you wont - but just be aware that it's a natural thing to do so keep an eye out for if you start doing the same!
As for which I'd learn; I'd second learning Ruby (plus optionally Rails if you want to do web apps) - it's a very nice language and quite an easy transition from PHP. The "Pickaxe" book from pragmatic programmers is a good place to start.
If you have access to a Mac - I very much recommend learning Objective-C and Cocoa. I certainly learnt a lot by studying these - I think more than any others I felt that understanding these made me a better all round developer. As for books - start with Kochan's "Programming in Objective-C" for the language side, then progress on to Hillegas' "Cocoa Programming for Mac OSX" for the GUI side.
Good luck!
I started off learning PHP after C. Then I discovered Perl and I never looked at PHP again. The reasons? Perl, like PHP, was dynamically typed, but far more modular. The Camel book about Perl was a delight to read. Running a Perl script from the command line was far quicker than PHP which needed all possible libraries loaded - Perl permitted me to choose what extra functionality I wanted at run-time keeping simple scripts light-weight. The Perl community is relatively advanced compared to other languages. The Perl language lets you program in a variety of styles, from procedural, to OO.
Functional languages seem to be gaining interest I'm planning on looking at F# primarily because I'm working with the Microsoft stack most at the moment.
I'd also recommend looking at topics that aren't language specific such as improving OO skills, using design patterns, and anything else that helps refine your skills as a developer to make you more of a craftsman rather than collecting languages that you won't get to use on substantial project and therefore will never really master.
Python + Django if you want to stay in scripting.
C if you want to understand how it works behind the scene.
C (as in C, not C++) would be my suggestion. It will instantly make you appreciate just what interpreted or higher level languages actually do for you (or save you from, depending).
It is also the first logical stepping stone to C++, though I know a lot of people who just dived into C++. Learning C first will (as above) either make you appreciate, or hate C++ even more.
To be a really well rounded programmer, you need to deal with managing types on your own, as well as managing memory without the safety net of a garbage collector. It used to be that those two were prerequisites for being a programmer at all.
Besides, think of all the fun you could have writing your own PHP extensions :)
This could turn into a debate.
My suggestion is to learn a new language that has something to do with your existing skills.
My "first language" was C, which brought me to C++ and Visual C. When I took on consultant jobs I enter the realm of PHP.
Starting from here, I am collecting skills in Javascript and jQuery, since they are tightly coupled with PHP. (DOM, CSS, and HTML aren't languages, so they don't count here.)
Or maybe you want to take another direction and go for SQL.
Choices is yours and crossroads are everywhere.
Not sure if you are programming PHP under the MVC model? But if you are not that is another good methodology to learn.
Examples: Zend or CakePHP
It totally depends on what you want to do. I don't think anyone can say what you should learn next, but rather share you with our experiences that will help you make your mind. After all, the decision for your next language should be based what what kind of applications you want to develop (desktop, mobile, web, etc).
I'll share you with my experience. I used to be a PHP programmer and I faced the same question, what do I want to concentrate on. I ended up to learn Java and I've been happy with my choice. Here are some of the reasons why I think it was a good choice
Java is a widely used language in the corporate world. This means that with good Java skills you'll be likely to find (more easily) a (better) job, more so than with Python or Ruby skills (disclaimer: this can of course vary between regions and countries, this was the case in my area)
I had done lots of web sites and applications with PHP and I've loved the web as an environment. Still, I felt that PHP wasn't quite the language to create full blown enterprise applications - that was something I also wanted to do - to be part of making large enterprise applications. Luckily, with tools like GWT or Vaadin I've been able to create enterprise applications which run in the web environment - all in Java. That was like a win-win for me, I was able to create large software for the web.
Java has forced me to think more Object Oriented, something I've benefited when writing PHP as well.
Java is multi-platform, so it is easy to write applications for linux/mac/windows or even for mobile devices (Java ME)
My two cents.
It depends on your motivation for learning the language.
If you want to learn a new language to do your day-to-day work more effectively I would suggest Python or Ruby. They are popular languages that are both highly productive to work in, and can be applied to a wide range of programming tasks. As someone else has pointed out there are versions for both the JVM (Jython and JRuby) and for .Net (IronPython & IronRuby) so if you want to learn either of those platforms they are a good way to start. They are also both easy to learn and fun to use. My preference is for Python, but that is probably because I have been using it for many years.
If you want to increase your employment options then go with the most popular languages used in business - this means either Java or C#.
If you want to expand your mind then I suggest a version of Lisp. I recommend Clojure - it is a dialect of Lisp that runs on the JVM and gives access to all the Java libraries. There is an excellent introductory book in the Pragmatic Programmers' bookshelf.
JavaScript (preferably through jQuery and Ext.js)
RegExp (preg_match flavour)
SQL (MySQL, PostgreSQL, SQLite dialects)
XSLT (and XML)
Each is very different. Each serves different purpose and each is very useful for PHP web developer.
If you want to try something different I'd go with
ActionScript (great opportunities)
C# (great IDE)
Python (complex ideas, misleadingly simple syntax)
Rebol (fun of having strange constructs work flawlessly on first guess)
Lisp.
(Or some other functional language.)
I coded in PHP for years and then took a (functional) Lisp class. It was four weeks of wtf %#f pain and then pure joy. Understanding functional programming, and especially recursion, really gives you and edge when coding PHP (or any other solution-oriented business language).

Categories