Is it possible to develop websites with C/C++?

Asked

Viewed 5,742 times

19

I know a little bit of PHP, but I see that on content sites, sometimes it gives a crashes and etc.

Researching, I saw reports (very superficial) that it is possible to develop web applications with C/C++, and that these, in turn, would have much more performance than php, which are interpreted language.

I would like to know if this is true. If anyone can help, please be grateful.

  • You can do anything with c++, drivers, operating systems, applications. Web applications are no exception. Whether they are more efficient? This is based on opinions

  • 2

    You can develop websites in C/C++ but it will require much more effort than if you use a language more suited to this type of development.

  • @Haroldo_ok This is also based on opinions. Similar to other languages, there are also libraries in c++ that facilitate the development of servers, following even for example the MVC pattern

  • https://github.com/ipkn/crow

5 answers

30


Yes, it is possible yes. But almost no one does. Generally the gain is not worth the effort, which is much higher.

What is more, if one does not master every process of development, master every minutiae of language, it can have a much worse result. Languages do not perform miracles. They can allow the programmer to get the desired result if he knows what he is doing.

All the programming languages mainstream can be used to develop websites, since what we call websites are text pages. Every language can generate text. These texts need to be used by an HTTP server. Every HTTP server can call an executable and get this text somehow. Of course, if the language can communicate more efficiently with this server, better. There are libraries for C/C++ that help with this. Note that it is common for these HTTP servers to be written in C or C++.

The programming language is not the problem.

Stuck

It is possible that these locks are related to your problem which is quite complex. But it’s also possible that it’s because you’re not using PHP properly. Then changing language will not solve any problem, it may even happen otherwise. PHP is very easy, it is more difficult to do something wrong in it. But I see that many people do. PHP is one of the most used languages to develop websites, do complex things, and does not lock.

I even have criticism of PHP, but almost everything for the web can be developed with it. It will not always be the most suitable language, but in simple things it usually is. Even if it is not the most suitable, it will still be reasonably adequate.

What people often do when they need extreme performance is move to Java or C# which is almost as easy as PHP and with much better performance.

I could suggest a number of things I could do in PHP itself to improve performance, but even that shouldn’t be the problem. It must be something related to the algorithm adopted. So more specific questions about a one-off problem may be helpful in finding what is occurring.

But reinforcement, that if you do not know how to do everything very well, not understand every aspect of computing, you will not get good results in any language. Maybe the way is to improve on that point.

  • Interesting explanation, reminded me a college professor who said that everything in development is possible, the question is whether it is feasible.

15

Yes web programming in C/C++ it is possible, this even refers to the beginning of dynamic web applications. In the 90’s CGI with Perl for text manipulation and C/C++ for "heavy processing" were the norm.

Programming language, on average, is not the first bottleneck of a website. Network latency, IO, etc are factors that weigh far more than language in the vast majority of cases.

Of course the cost of processing exists as well as the cost of scaling a website to handle thousands / millions of simultaneous requests... In addition, with studies indicating that a delay of one second can impact sales by 7%, there is economic incentive to optimize performance.

Let’s assume you have a problem where the programming language really has become relevant to the other bottlenecks of performance and scalability. Even in this Universe things are not so binary; the decision need not be between purely interpreted vs purely compiled languages. In fact, the sweetspot for solutions web seems to be in virtual machines with compilation just-in-time. This was the Facebook solution for PHP (see HHVM), of much of the development Nterprise for large websites (Java, . NET, etc.) and even for Javascript (see V8).

You don’t need to expose developers to C/C++ idiosyncrasies to get a significant gain from performance. In fact, even assuming that a properly optimized C/C++ solution will always be faster (which is not true), the law on decreasing returns causes to extract these last drops of performance of language in a world with so many other factors hardly worth it.

In the vast majority of cases, it ends not viable give up years and years of evolution of languages, tools, techniques and knowledge accumulated by the various communities specialized in web development to write a solution in C/C++. Frameworks for web development in C++ as Cppcms and Wt, regardless of technical merits, simply do not have the same traction of technologies in newer ecosystems.

So I would say that web development in C/C++ is possible and there are applications in certain niches. That said, I see little chance of this kind of development becoming mainstream. The argument of gain of performance with C/C++ to "avoid crashes" does not hold and it is very difficult to think of a good reason to write C/C++ web applications in 2016.

6

As @Maniero commented, possible is, but almost nobody does.

This is simple to understand: C/C++ does not have this focus of being a language for Web.

It would be like trying to develop a website with Pascal, COBOL or other language with a different purpose.

C/C++ is a language that allows you to develop anything, but there are more suitable languages for certain purposes, as well as SQL for database interaction, and R for calculations that help Big Data, there are languages with support for web development such as PHP, Java and ASP/ASP.NET using C# for example.

In general, you can, but you would have to program or find libraries for basic things that these other languages already have.

Now, about your performance problem, blaming the language is premature. There are sites in ASP/VB that work very well until today. Your problem may be network, file access, traffic, database, etc., a lot of things that, regardless of language, will slow your site down.

I suggest you dig deeper and identify where the problem is. Most likely you will be able to solve using PHP and your site will perform well.

1

I recommend using C#. I just started interning at a web programming company and I’m using ASP.NET and C#. In college I learned C/C++, and C# is very similar and easy to learn and the best is that it saves much work as there are bookstores for everything, including for web applications, and the best is that you can use the same code to develop for various platforms (e.g. Android or iOS) using Visual Studio, which is free in the community version.

  • I don’t like C# but it’s noteworthy that Stack Overflow is written in C#.

0

The critical component, which is the web server itself, is already written in C or C++.

As for the application code, you will spend 100 times more to develop in C than in PHP or Javascript. In fact the page will have a 3x more performance in terms of CPU. Just take a better machine in the cloud, for a few extra dollars a month, to stall the performance.

Just by this reasoning it is already difficult to justify the additional expense. But there is more.

The main bottleneck of Web performance is the network (internet). Speed and mainly latency. Working network access, using CDN, using cache for static objects, all this will give much more expressive results at first.

Surely your web application uses a database. The performance of this bank will be a bottleneck long before the code of its own application. On a big and busy website, this is where you’ll spend the bulk of your budget.

A website is usually very dynamic, changes every day, continuous development. And that doesn’t go with C/C++, it goes with interpreted language, which you won’t use just because it’s easy or because it has cheap programmers on the market; it will because it’s productive, because it will allow you to quit work in the evening instead of having to turn into night.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.