I'm learning C++; I'm already fluent in PHP. I read up the differences between C++ and PHP. None of the articles that I read mentioned that PHP has far more built in functions than C++.
Right now, I'm trying to split a string in C++ and I found this: Split a string in C++?
In PHP, I can simply do explode($delimiter,$string)
Am I missing something? Or is it true that PHP has more built-in functions that C++.
Both C++ and PHP have the concept of libraries which include new functions and classes..
A lot of the PHP functions are just simpler ways to do more complex things, for example, explode
can be written using split
and strpos
instead.
Same thing for C++, I find that C++ is more lean in that aspect, sure sometimes you will have to write your own explode
, or simply use some other library that someone else created.
As for which has more, I don't think it matters, both are extensible.
PHP is to C++ as Java is to Javascript
They are completely different languages as a whole.
Yes, PHP was built with C++, this does not mean they will have the same functions.
Other languages were built with machine code which built up to PHP and C++ and other higher level languages, but this does not mean I can do: 1000101010111010011000
in PHP and mean something...
C++ is closer to assembly language. And while there are thousands of functions part of the std library (and std++ library), it's not surprising you feel there are more libraries in a interpreted language such as PHP (which is written in C/C++).
C and C++ each seek to provide minimal interference between the programmer and the underlying machine (while still mainlining a semblance of portability). The creation of libraries is therefore left up to the programmer to implement to suit their task at hand. While this creates more effort on your part, the resulting code can be incredibly efficient and yield impressive performance enhancements.
Of course it's up to you to decide if the performance gains are worth the tradeoffs of increased effort.
Best of luck with your study.
Part of C++'s beauty lies in the fact that it is basic and does not have built in functions polluting your namespace.
Many of the functions/objects/algos that are built into other languages are part of C++'s Standard Template Library (STL). The STL is part of the core language spec, but to use the functions you need to include the proper headers.
If you want to learn C++ you should make yourself familiar with the STL and the Boost libraries.
Just because C++ doesn't have a particular function that PHP has doesn't imply that C++ has a smaller standard library overall. I'd guess that the C++ standard library also has many functions that PHP does not have. For example PHP doesn't have compile-time rational arithmetic in its standard library.
I don't know which language has a larger standard library. You'll just have to get the documentation for each language and count the number of functions.
Does C++ have less functions than PHP?
PHP and C++ have equally the same amount of functions: One function construct which can express a certain large amount of total functions. It's probably easier in C++ to raise the number of functions that are possible more easily than in would be in PHP in case you hit this limit some time in the future.
Am I missing something? Or is it true that PHP has more built-in functions that C++.
I'm no C++ expert, but I'm pretty sure that in terms of built-in functions PHP has "more" than C++ but you can't compare it that way because the languages are too different. While it's wise in C / C++ to not have many build-in functions by default, it's the opposite in PHP as it is a scripting language that lies there to be used so it was stuffed with functions over the years.
Or to formulate it this way: You use C++ as a language to produce those functions that are compiled later on as a PHP-binding (extension) which are then available as long as you load the extension in PHP. But you will never do it the other way round.