What problems would you expect when switching from JS to C++? [closed]
What problems would you expect whe开发者_StackOverflow社区n switching from JS to C++ ?
C++ is incredibly different from Javascript. A few main differences:
- Static typing (usually types of variables are specified, most types are known at compile time)
- Low level memory management (no GC so you'll have to allocate and free a lot of memory yourself)
- Different object system: C++ is class-based, while Javascript is prototype-based. You'll also have to learn everything that this entails, e.g. access modifiers, class-based inheritance
- Less safety than JS. C++ doesn't hold your hand much like Javascript does, if you don't allocate the right amount of memory or try to access an out-of-bounds array index, etc. your program will crash (and you've introduced a critical security flaw in the program as well)
- Templates and everything that comes with that
- I/O are different, obviously, because you're dealing with files rather than HTML and the DOM.
There are also obviously some trivial differences, e.g. you'll have to compile and link your programs before you execute them. You'll also have to learn a new standard library.
You may also find this amusing.
JavaScript is a very high level language which has found it's main application in the web. C++ is a very low level language compared to JavaScript. The main difference (painful difference) you will find is that C++ does not have a garbage collector. You need to allocate and free memory by hand.
精彩评论