开发者

Learning C++ from PHP [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.

Want to improve this question? Update the question so it focuses on one problem only by editing this post.

开发者_JAVA技巧

Closed 7 years ago.

Improve this question

I have PHP background and want to start learning C++. How should I proceed?


Start at the start. The similarities between PHP and C++ will take about half an hour to get through ("this is an object, this is a loop, ..."), and there are subtle differences which will kill you if you're not paying attention during that half hour. Learning C++ will take months to years, depending what you mean by "learn". It's just not a worthwhile optimisation.


Unfortunately, with this particular subject you'll see a lot of superiority and thus not get a very straight answer. This is due to the nature of PHP's structure, how common it is to see it in "casual" form (Think WordPress), and it's ease of use and relatively small "learning curve".

To be clear, PHP and C++ are very similar on the surface - But the same could be said for any C-based language. You have your variables, loops, arrays, classes, etc. But where do they differ?

Beyond syntax (Which is quite similar anyway), PHP was designed to be easy to use, while C++ was designed to be efficient (And as technology evolves, that becomes less and less relevant). That aside, PHP was designed to work in a web-server environment while C++ is for applications in general (You can even develop web apps in C++, if you want to).

Down to technical details, as mentioned before, C++ was designed to be efficient and thus allows close access to memory management & co. Like any high-level languages, it was designed to shield the user from the raw technical aspects of the machine (Rather than writing in assembly, or, heaven forbid, machine code). PHP goes one step further and leaves the programmer to only focus on the logic of the application.

To conclude, C++ is like PHP on the surface, but a whole lot different in design AND purpose. C++ performs operations beyond the scope of PHP's abilities, and thus is a more complicated language and takes longer to learn. Personally, I had an easier time 'learning C++' after having dealt with PHP because it managed to separately introduce numerous concepts in a very straightforward way.

PHP:

<?php

$count = 0;

while ($count <= 10)
{
  echo $count,"\n";
  $count++;
}

C++:

#include <iostream>
int main()
{
    int count = 0;
    while (count <= 10)
    {
        std::cout << count << "\n";
        count++;
    }
}

In the end, as with most languages, the only obstacle is learning the differences. Really, it's just logic/logical thinking that you express in a readable format.


Because you know PHP, you'll "feel at home" a little bit when you start to learn C++ because you'll be used to typing semicolons at the end of statements, using braces for conditionals, etc.

You'll likely be able to progress more quickly because you know PHP, but there are C++-only constructs and ideas that will be new. That, and though the syntaxes are similar, they're not identical.


As others have said, the similarities are superficial at best. Basic C syntax is pretty much the same - loops, conditionals, etc, but the interesting parts of the language are vastly different.

This is going to be a big learning curve, but when you reach the other side you'll be a much more aware and qualified developer.

One of the big problems that I foresee is basic coding style. The majority of the PHP code that I've seen is poorly structured at best, relying on a mashup of procedural code, objects and misc. hacks. Memory management is nearly a non-issue in PHP, whereas you need to always be aware of it in C++.

Also, note that even the differences between C and C++ (there's no such thing as C/C++, despite what the book publishers seem to think) are substantial.


I would start from the beginning. I started on Java which is more similar than PHP and I still made a point to read the book I had from the beginning. It's important to know the little subtleties about the language. As for resources, I have no strong opinion on any book I've seen, but I do prefer books. This is the book I started with. It got the job done, but I know my boss/professor wasn't happy with it and has since replaced it.


PHP and C++ may look similar on the surface (they share a lot of lexical elements and quite a bit of syntax), but they are two very different languages. The type systems are different (C++ arrays and PHP arrays are not the same thing), the toolkits are different, etc.

Start at the beginning.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜