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?
Related
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.
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.
There are a ton of PHP frameworks out there (i.e. Zend, Seagull, Symfony, CodeIgniter, CakePHP, Yii, Prado) that do a great job of implementing important pieces of a scalable/maintainable website, and I almost always pick one to start building client websites.
As of recently, I've started getting tired of providing constant development services to clients, and I'm looking at the possibility of writing more full-featured commercial scripts that can be resold over and over again in the hopes of finding that magical "recurring revenue stream" that you always hear about in fairy tales. Please note that I'm not talking about building extensions/plugins to CMS systems like Drupal or Joomla, but full blown website scripts.
So here's my multi-part question:
Is there any reason why I couldn't resell a script built on one of these frameworks as a full-blown turn-key solution (especially if the framework's licensing is something very flexible, like the BSD license)?
If not, why aren't others doing the same thing?
Have you ever seen a commercial PHP script that is based on a well-known open source framework?
I've wondered this for years, and no one I ask has ever really come up with a good explanation. It just seems like it is taboo to do so, and no one really knows why? I've seen commercial scripts that use third party libraries (i.e. jQuery, PHPmailer, etc), but never have I seen one built entirely on an application framework.
It really seems that a lot of people have missed the true nature of the question and even taken it as far as language debates (those never end well).
Is there any reason why I couldn't resell a script built on one of these frameworks as a full-blown turn-key solution (especially if the framework's licensing is something very flexible, like the BSD license)?
Assuming the framework license permits it then there's no reason you couldn't do this. You had mentioned Zend Framework so you may be interested in looking at Magento. While they offer a free community edition they also have a paid edition that works with the Zend Framework as well.
I recently worked with a file upload script that was offered commercially and it happened to be built on codeigniter (name escapes me at the moment).
If not, why aren't others doing the same thing?
My personal opinion is that it's a mix of quite a few factors really. The web based market for on premise applications (as apposed to SaaS) is already flooded with options and is starting to shrink in size. This makes less demand for an application that you would actually see the framework behind (with SaaS you most likely will never know what framework if any is being used).
A lot of the existing large players in the PHP market have been around for a while and already have their own code base that they have created and are familiar with. When you've spent years building your own libraries it's hard to justify moving to another framework.
A lot of the smaller players rarely educate themselves in proper application design and usually stick to procedural code. The big OOP features that exist in PHP today didn't come along until the 5.0 release. Mind you that was around 5 years ago but a lot of your programmers had started on their PHP tutorials and learning adventures before PHP5 was widely available and accepted on standard hosting accounts. As such most of our modern frameworks were not available CakePHP as an example didn't start until 2005. Zend framework wasn't around until 2007. These are all relatively new dates and I wouldn't expect to see a lot of commercial applications moving to them until the current generation of programmers that can write quality commercial applications age a bit (again just my opinion).
I have to heartily disagree with back2dos..
PHP's a solid, incredibly well used programming language for developing web apps. It can, of course, be used for commercial development and millions of people (me included) do just that. I'm not sure PHP bashing is really relevant here.
True, PHP is not compiled but if you really care about this you can use Zend Guard which can encrypt code. Personally I've always found open source code a plus point. Clients like to know they can get at the code if they really need to, it offers some reassurance.
There are lots of OS PHP apps, some great, some awful. Find a niche (like any business), something that has real demand, and develop for that.
So I think you're fine to develop commercial apps/scripts. Just make sure you give them decent support and documentation. You'll find people appreciate that and are willing to pay for it.
Finally on the point of your question, I agree they stand a much better chance of being used if they are based on an open source framework since you'll be opening yourself up to wider market. Zend Framework, as you may know, has a pretty open license which says you can sell anything you develop with it.
I think your most important question is point 2, why aren't others doing the same thing?
Well some people are. Vbulletin have been quite successful selling forum software, even though there's no end of free forum software available. I think their success can be attributed to a paid product, in part. As they're earning money, it's easy to fund further development. Open source, free projects usually require a dedicated team to keep development moving, as there's no money for motivation.
There's no shortage of turnkey solutions available on the web. eBay will have no end of $5 scripts available - they're usually rubbish and unsupported.
Where I work, we develop bespoke 'one-off' applications for our clients, but we're looking at selling the same applications to other clients as an opportunity to scale our business. In this case we're talking about large projects worth tens of thousands, but they're only sold to a handful of customers.
There's no reason why you can't sell a product for 50 or 100 dollars and make money - you'd just need to sell to 10, 100 or 1000 customers to start making a living from it.
And to succeed over the free open software? Produce something that isn't already available, or do something much better than what's available for free.
Finally, another model you may want to consider is software as a service. Take a look at Basecamp (37 signals) for example. Their product is not open source, you can't download it, but you register online and pay something like $10 for their lowest end offering per month.
They don't have to give out source code, and they have a solid recurring revenue stream. They have tens of thousands of accounts.
Yes of course you can sell it.
Most people don't just sell the scripts as normal people and businesses don't know what to do with them and so require a developer to install and configure the script. Developers won't then buy the script if there is an open source/free alternative. If the script performs a valuable task that is often done, then somebody is likely to copy it and create an open source version.
Your key to selling PHP code is to sell it as a service. This could either be the installation and configuration of it (like most web design/development agencies) or an on-demand version of it (think of any online business app).
My company writes and builds a lot of PHP software for businesses and as we get new clients and solve new problems we write our code in re-usable classes which we can then package up and sell to other clients without any further coding - which I assume is what you are trying to do. It's all possible, it just takes time and planning to write the software to make it re-usable for other projects.
Well in this case I think that codeigniter will be the best option because:
Don't need console access to configure
You just have to configure Database Connections
Fast, MVC, Cache, Logs, Good Documentation
Runs in PHP4, must of the people that buy this scripts have server restrictions to Upgrade PHP
Best Regards,
Pedro
As a PHP developer for over 5 years and selling scripts I never tried to developed a commercial script with a framework.It is just because Im not a good fan of any PHP framework.
Someone can say if you don't use framework you are a amateur as a developer.But I think its the a way any developer has rights to choose.
I think some companies don't use frameworks just because they just dont like to say this script based on 'ABC' to the customers.They want to boast about their scripts and only they can developed something like that.
I event seen any commercial web script that used any frameworks so far.
I can think of one reason against it: piracy. If your script is something a bunch of framework guys want, it will be pirated. If it is only for a rich niche, you can avoid this, but then you aint going to get any fairy-tale income.
It's not in the open source spirit of PHP. The trend is to give it away and then bill for the service. You might be better at marketing your script as such, and just charge people after they consult you and you hand them a script download and a manual.
i think, these are the key reasons, why it is not done:
the point of PHP was never building commercial applications (the original acronym means "Personal HomePage") ... it is an insecure, inconsistent language ... there are quite some good PHP frameworks ... nevertheless, the language is ... poor ... other server languages are cleaner, stricter, more secure, more powerfull, give access to a larger codebase and to better developement tools (notably java and the whole .NET stuff) ... i'd never use PHP if i had to built something really reliable ... (my favourite is this "overflow vulnerability fix" of chunk_split (line 1966)) ...
PHP is always open source ... ok, there are obfuscators, or even ways to distribute PHP in a binary form ... but the first is likely to break the code, if you do a lot of reflection/introspection, and the second usually requires some PHP extensions to be run, which is not really sexy ...
there are too many open source PHP projects around for any commercial software to succeed ... this was different before, but nowadays, you can simply get ANYTHING in PHP ... Typo3, Joomla, Mambo, osCommerce, PHPBB etc. ... frameworks as Flow3, symfony, CakePHP ... etc. ...
there are commercial sites running on PHP, but there is no good PHP software/framework i heard about, that i would pay for ... there's always a free alternative, and usually it is better ...
you will be having a hard time creating something, that is really worth buying ... and if you succeed, you will be having a huge community that will copy it, if it is worth buying ... either for personal commercial profit, or simply to provide a free solution ...
well, that's what i think ... :)
edit:
let me clarify my points
seems, i upset some PHP folks here ... that was not my intention (however i am quite disappointed, how biased you seem to be, given the fact that everyone contradicting me is a PHP developer and i seriously ask myself, what other languages you ever used) ... i myself started out with PHP on server side too and after moving through other languages, i came to see PHP in a different light ... explanation is provided ... whoever just does not want to read it, move on to point 2 ...i am not saying, PHP prohibits you from implementing a specific solution ... but it is being used to implement solutions it was never designed for ... it started out as >this< ... and it was constantly extended by many people, which produced:
an inconsistent API ... or does anyone else know a language, having a naming convention, where array_search, count and implode are all array routines? look at ruby, ecmascript or Haxe if you wanna see how beautiful core language APIs can be ... i'd say it's awfully designed ... but it's not designed at all ... it has simply been thrown together by numerous PHP contributors ... that's cool in the sense that you have a function for everything ... the point is, you probably won't find it ... ok, after a while, you will know it all ... probably ... but in other languages, for example, where arrays are objects, it does not take you long to know all core array routines ...
no real philosophy ... look at the languages mentioned above, look at Objective-C or functional languages, if you want, to see how consistent a languages semantics and philosophy can be, compared to PHP's "oh well, we'll just throw in another function, that'll solve the problem" ... also PHP arrays are the strangest data structure, i have ever seen ... something like a hyperpotent hash with internal order for keys and values ... and yet, it's not even an object ...
a lot of unsafe code (a lot of functions exposing overflow vulnerability or not being binary safe, or not escaping is documented, which could be used for XSS attacks) ... when i read an API reference, and it tells me what a function does, but the truth is, i have to take in account a lot of possibilities (long strings could crash my complete system or even inject ANY code, nullbytes could make escaping routines not work, but when printing out the string again, they disappear (this was a strip_tags vulnerability until not too long ago)), then that is what i call unreliable and dangerous ...
slow execution ... eaccelerator and similar extensions can reduce booting time signifficantly, but execution it self will still be slow ... the actual problem is, the language is far to permissive, which causes a lot of overhead ...
PHP was designed as a scripting language tying together a bunch of C functions ... it is often extended with further C functions, due to the fact that it is not the fastest language around ... this gives a nice speed up ... but how the hell do i know, whether a function is safe? who can tell me? i don't want to read through lines and lines of C to know ... so my two main points:
the API is a mess
what is behind that API can be a serious vulnerability for your application!!
in consequence, PHP is hard to trust ... i mean, i personally dislike both Java and ASP.NET, but i have to admit, they are trusted plattforms and trusted for a reason ... now problems arousing from the messy API are being solved by some frameworks ... but if a language requires a framework to wrap the core API in order to have something usable, that is a base for good, maintainable code, then something is wrong ...
how exactly do i use zend guard or ioncube on an arbitrary shared webspace?
really, best thing you can do, is write commmercial plugins for widely spread PHP software, but it seems this is exactly the opposite of what Lusid wants to do ... but hoping to find a niche, that is big enough that you don't need signifficant marketing efforts to reach you customers, that is small enough that you don't get crushed by copycats, simple enough to build as a standalone app and fits a number of other criteria that are prequisites for a commercial success, seems a little naive to me ...
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).
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 5 years ago.
Improve this question
As you probably know, Derek Sivers is the guy who created CD Baby and eventually sold it for some big bucks. He wrote it in PHP originally and then down the road set about rewriting it in Rails. His troubles are the stuff of legend:
7 reasons I switched back to PHP after 2 years on Rails
That article came out in 2007 but being newly infatuated with Rails, I'm wondering whether anything has changed to make Rails more of a wise bet in the meantime, or should I stick with my good old ugly PHP girlfriend?
Does anyone agree that Rails does not offer any significant advantages over PHP?
Austin Ziegler wrote an interesting response to that article:
On Derek Siver’s Return to PHP…
The gist of it is:
Derek chose the technology for the wrong reasons. He chose it partially
based on the hype of Rails, but he
envisioned it as a silver bullet that
would magically make his application
better just because it’s in Rails.
Rails didn’t fit Derek’s application model for CD Baby, and
Derek’s application model is more
important than the technology to be
used, since it represents a business
he understands well.
He ignored his existing experts for the new technology. Neither he nor his
employees knew Ruby aside, perhaps,
from playing around with it. This
wasn’t a technology that was deemed to
be appropriate from experience; this
was a technology deemed appropriate by
management (sorry Derek, you might
still be getting your hands dirty with
code, but you’re still management).
Derek approached the project as a whole-environment ground-up rewrite
with a One Big Day deployment, without
considering ways to phase it in over
time. It’s almost always possible to
find interface points where you can
replace one broken piece at a time.
Ultimately, this is what the Rails
folks wouldshould tell you anyway:
replace one area at a time, each with
a different codebase. Interface them
as REST-ful services. Don’t make them
depend on a single database schema.
Re-writing an existing site is almost always a bad idea. It's hard to put your heart into retreading an old wheel. I worked on a rewrite of a site from CGIs to a Java app server and saw several programmers quit because of it. For one, they preferred their old way of doing things and did not want to learn Java. Secondly, I believe they did not have the enthusiasm to re-write a ton of legacy code that they had been maintaining reluctantly to begin with. Far better to try Rails out on a new task and see how it fares. At least then you are putting it on an even footing with PHP in the psychological motivation sweepstakes.
I have experience with PHP & Ruby + Ruby on Rails (earned money using both, but not a lot).
The Ruby library is much better. PHP's library is a collection of functions in a global namespace with inconsistent names and argument order. strpos vs str_repeat. strpos's first argument is the big string and the second argument is the string to find. explode's first argument is the string to split by and the second argument is the big string. This was a big problem for me. I had to look up a lot of things when using PHP, but not when using Ruby. I can remember things because they're consistent. The names of the methods make argument order clear. Another: PHP's strlen($str) vs count($arr) while in Ruby it's just anything.length.
Ruby the language is better than PHP. It has closures, good OO, nice syntax (this is subjective, but you need a lot less punctuation in Ruby, and that's what I get wrong most often).
That's my experience. Try both and see what works for you.
The best answer will be the author's himself. He seems to make another comeback to RoR!:
Foreword
My former company (CD Baby) was one of
the first to loudly switch to Ruby on
Rails, and then even more loudly
switch back to PHP (Google me to read
about the drama). This book by Michael
Hartl came so highly recommended that
I had to try it, and Ruby on Rails
Tutorial is what I used to switch back
to Rails again.
http://railstutorial.org/book
And skimming his own site, indeed, proves his return to RoR:
Instead of trying to teach everyone my unique PHP framework, all
projects will standardize on Rails 3.
http://thoughts.pro/
The guys who changed from Rails to PHP just by following the renowned article of his, now it is your time to come back to Rails, again!
I read that post from Derek Silvers. There is something weird about it. He tells the tale of a project that got out of control, dragged on for months, and eventually had to be abandoned. He blames this on the Rails framework. Yet he never says what it was about Rails that caused the project to fail. The article would be far more credible if he offered some solid information, but he doesn't mention even one specific place where Rails let him down. The closest he comes is to say that their "needs" (?) clashed with Rails's preferences (which ones? How?)
Meanwhile, people all over the world (including myself) are implementing complex Web applications in reasonable amounts of time using Ruby on Rails.
Given the lack of detail, or really any specific technical information at all, in Derek's piece, it could easily be that the project failed for any number of reasons having nothing to do with Rails.
The original question was "should I heed Derek Silvers' warnings about migrating from PHP to Rails?" My answer would be no, his "warnings" amount to a vague anecdote with zero supporting evidence. It is perfectly safe to ignore them.
Should you reimplement a PHP app in Rails? That's another question. There is no blanket answer to that one. It depends entirely on circumstances.
Luke Crawford's recent post about Muxtape offers another perspective.
I spent my first 4 years as a web developer using PHP, and it was fun at the time, but as I began to realize how severely inefficient it was I started looking elsewhere. I’d abandoned my traditional computer science background for the web and its greater design possibilities, but because of this I knew there was a better way. PHP developers shouldn’t be ridiculed as much as they often are because, frankly, it enables people without a more rigorous background to accomplish amazingly technical things. This should satisfy nerds but usually is turned into some kind of weak ‘machismo’ thing instead. Anyways, this dissatisfaction began in late 2004 and Ruby on Rails was brand-new, stable, and addressed every limitation I’d confronted with my old homegrown PHP MVC framework. I’ve exclusively done Rails work ever since.
In any case, it would be hard to defend the categorical statement "Rails does not offer any significant advantages over PHP."
PHP is a great tool to solve certain problems. Rails is a great tool to solve certain problems.
As both an active Rails and PHP developer (with experience going back to 2000), I strongly disagree with the statement.
I maintain that Ruby offers significant advantages over PHP, and Rails is a better framework than anything in the PHP world. A lot of this has to do with the language itself - Ruby can do things that PHP just simply cannot. Once you grok the elegance of meta-programming, a whole new level of expressiveness opens up to you.
Disclaimer: I am by no means a Ruby or Rails expert.
As someone who's been in the industry for nigh on 15 years I see several warning signs that make me nervous about Ruby on Rails specifically. I'm going to ignore the language here because a language is a language. Ruby is a modern language with closures, exceptions, OO, etc. Some criticize it with regards to performance. These issues are largely irrelevant in that they don't impact real world performance (if it takes 300ms to download and display a Web page, who cares that the serverside codes takes 10, 20 or even 30ms to run?) and transitory in that they are fixed in later versions (as seems to be the case with Ruby 1.9).
Ruby on Rails is a closed, heavyweight stack. I mean this as an observation not an accusation. It is tightly integrated (including with Prototype) much like JBoss Seam in the Java world (being integrated tightly with JBoss/Hibernate and yes I know recent releases and articles have tackled the issue of using it with, say, Glassfish and another JPA provider)
This can be both a good thing and a bad thing. J2EE, for example, being a fairly open stack was the cause for much innovation in the software industry in the last decade as almost every piece of it (notably EJB) was replaced by different projects that could be slotted together. And of course it was, if not the birthplace for Spring, it was certainly the incubator.
On the other hand you have more closed stacks like .Net where their closed nature allows for rapid innovation, a model Microsoft has (generally) excelled at. In a few short years DirextX went from being a joke to completely trouncing OpenGL as a games development platform because any closed system can evolve that much faster than an open standards system. That's just how it works.
The other relevant point I'll mention is that in recent years there has been a move towards ORMs ("object-relational mapping") in Java, .Net and elsewhere and this is part of the impetus behind Rails. I've commented on this previously, for example "Using an ORM or plain SQL?" and I won't reiterate those points in their entirety.
As most of you would know there is a mismatch between the object and relational worlds that ORMs have sought to bridge. In the last year or two I've dealt with this mainly through Java (JPA specifically).
Now when you bridge between two things that don't match you end up with "leaky abstractions" (as Joel put it):
All non-trivial abstractions, to some
degree, are leaky.
Now what I'll add is this: there is an inverse relationship between the complexity of the abstraction and how leaky the abstraction is. Case in point: ibatis. Ibatis is an extremely lightweight yet powerful persistence framework for Java and one I'm a huge fan of. It wraps SQL in external files and on top of that puts many modern ORM behaviour, such as:
Lazy-loading of relationships;
Result mapping;
Grouping of results to multiple levels (something JPA can't do); and
Discriminated types (ie the type is determined the data).
I would estimate that ibatis has 90-95% of the functionality of Hibernate with the only complexity overhead being runtime bytecode enhancement for the lazy loading via cglib (JPA does it the same way) with the only downside that you have to write your own queries (and I don't consider that a serious downside but opnions will vary).
Compare that to a JPA provider that relies on instrumentation, load-time weaving and non-standard class loaders to implemennt that extra 5-10% functionality (and the abstraction is still leaky).
So there is a law of diminishing returns when it comes to making things less leaky. At some point you're better off investing in a bilge pump than you are in fixing every leak in the boat.
Bringing this back to Rails: the leaky abstraction argument is my biggest problem with the Rails philosophy.
What also rings alarm bells for me is the comments you get in posts like On Derek Siver’s Return to PHP… is:
"Derek chose the technology for the wrong reasons.": wait... isn't RoR either a general-purpose Web application framework or a pretty close facsimile? That being the case, why can't you do a site like CDbaby in it?
"Rails didn’t fit Derek’s application model for CD Baby": How so?
"He ignored his existing experts for the new technology.": wait... didn't he hire an expert?
"sorry Derek, you might still be getting your hands dirty with code, but you’re still management": I agree with the comment that this quote is "asinine" and will add that its misleading, irrelevant and arguably a strawman;
"Derek approached the project as a whole-environment ground-up rewrite with a One Big Day deployment": arguably not advisable but if you're willing to spend the time and money on it, I don't see it as a reason why you can't do the site in RoR.
Now 5-7 years ago when EJB was hyped up you got criticisms of it based on lots of things and you'd get stalwart defenders arguing:
"Application X didn't fit the EJB model";
"They didn't understand how EJB works";
"EJB is not for all applications" (they'd rather concede defeat on this one than face the more glaring issue that it's not really appropriate let alone a good idea for, well, just about anything);
etc.
So the anti-Ruby posts (and especially their rebuttals) all sound very familiar to me.
It's worth mentioning the year old rant "Rails is a Ghetto" by Zed Shaw, which is a 6000 odd word rant ("conflagration" is probably a better word) against Rails. Some notable quotes:
This is exactly what makes Rails a
ghetto. A bunch of half-trained former
PHP morons who never bother to sit
down and really learn the computer
science they were too good to study in
college.
and
Notice how it took me a few seconds to
reply. This one single statement
basically means that we all got duped.
The main Rails application that DHH
created required restarting _400
times/day. That’s a production
application that can’t stay up for
more than 4 minutes on average.
and (on memory leaks):
That’s one more reason Rails is ghetto
as hell. Important patches like the
above go largely ignored by the
Japanese developers, and while they
are very nice guys, the above just
smacks of amateur hour.
and
The best part about the whole thing is
there’s potentially 10 new web
frameworks that can take on Rails.
Hell, Mongrel spawned or helped 5 of
those. My favorite of those frameworks
is Merb which is literally “Mongrel
plus Erb” but now it uses Erubis
mostly. What I love about Merb is that
it proved you could make a fast thread
safe Ruby web framework with all the
same ideas as Rails and using most of
the Rails gear at the same time.
However, the joke is that before Merb
the Rails Core morons would scream up
and down you can’t make Rails thread
safe. Ezra however proved them all
wrong by just writing a better Rails
than Rails and all thanks to Mongrel
being so easy to hack and work with.
and:
Ruby on Rails has become full of
people like Koz, with Koz the most
senior of the wannabe smarties. Koz
got lucky at best and injected his
shitty coding into a good project,
messed it up, and then latched on to
security as the way to get more
control. Of course he doesn’t actually
know anything about secure coding
which is why his code seems to have
lots of the bugs (go check out the
date parsing shit. Clue: months don’t
always have 30 days).
And, well it goes on.
So I guess I can sum it up this way: Rails smells bad.
Rails is a good framework, but sometimes migrations are bad ideas.
I prefer to start from scratch, you can't be "translating" PHP code into the Rails context. It just can't be done, mostly because of the Ruby language itself and the MVC pattern.
I'd rewrite it in Rails, but if you love PHP, go with PHP. Don't care about what other people say, do whatever suits you.
In business, time is money - and sometimes you have to go the path of least resistance. No environment, language, framework, etc. is perfect. Learn and use what you want to and keep it movin' homeboys!!!!