I’ve learned php and c++, i will list the things i liked and didn’t liked on each of them, how i decided to learn them in the first place and why i feel the need to learn a decent alternative to c++, i’m not a professional programmer and only do projects for myself.
PHP – Decided to learn because i wanted to build a dynamic website, that i did and turned out very good, i even coded a ‘not so basic’ search engine for it that would display the results ‘google style’ and really fast, pretty cool stuff.
PROS – Pretty consistent syntax for all stuff (minor caveats), great functionality, a joy for me to code in it (it seems to ‘know’ what i want it to do and just does it)
CONS – Painfully slow for number crunching (which takes me to c++ that i only learned because i wanted to do some number crunching and it had to be screaming fast)
C++ – Learned because number crunching was so slow in php and manipulating large amounts of data was very difficult, i thought, it’s popular programming language and all, and tests show that it’s fast, the basic stuff resemble php so it shouldn’t be hard to pick up
PROS – It can be used to virtually anything, very very fast
CONS – Although fun to code at the start, if i need to do something out of the ordinary, memory allocation routines, pointer stuff, stack sizes etc… will get me tired really quick, syntax is a bit inconsistent some times (more caveats)
I guess that from what i wrote you guys will understand what i’m looking for, there are thousands of languages out there, it’s likely that one of them will suit my needs, i’ve been seeing stuff today and a friend of mine that is a professional programmer tried OCaml and Fortran and said that both are fast for numerical stuff, i’ve been inclined to test Fortran, but i need some more input because i want to have some other good ‘candidates’ to choose from, for example the python syntax seemed great to me, but then i found out from some tests that it was a lot slower than c++ and i simply don’t want to twiddle my thumbs all day.
16
Sounds like PHP was too high of a level for you and C++ was too low. I’m a C++ programmer myself and I do agree that sometimes signal-to-noise ratio, especially for a new person, can be quite low. It still has its place in many areas, but I would not use it for general programming.
The languages I would recommend would be C#, Python or Java. Of those Java is at the end of the list because it seems like it’s no longer the hot item in the industry and if you are going to learn something, might as well pick up a skill other people are looking for.
Both C# and Java are similar to syntax of C++, but they are less flexible which is a good and a bad thing. For you, its mostly a good thing since the flexibility is what introduces complexity. Both languages will not allow you to pave over memory and will worry about allocations for you so you can focus on the actual logic.
Python is quite different and I’m not entirely sure how it compares in speed since I believe it is still interpreted whereas C# just-in-time compiles to machine code. But it is still a fun language.
3
If PHP is too slow for you, you can always write the performance sensitive parts in C++ and then call those C++ functions from PHP (see this stackoverflow question).
For relatively fast servers, Java and C# are also good options. They may not always be as fast as C++, but for most purposes they are “fast enough”.
For some workloads, you may also hear that node.js is the fastest, but not in your case. Node.js specializes in I/O-bound operations, and you seem to be stuck in CPU-bound operations, so node.js would be “pretty fast, but not mind-blowingly so”.
For C++, there are a number of things you could do to improve the situation. I suspect you might be doing something wrong if stack sizes are such a huge problem for you.
- Pointers might be easier to handle if you try smart pointers.
- Avoid manually allocating stuff if you can. If you want to allocate memory for a bunch of stuff, just use a vector and let C++’s STL do the complex stuff for you.
Finally, you might try a PHP compiler to accelerate PHP without needing to switch languages. See Phalanger, phc and HipHop.
Try many different technologies and see what works for you.
If performance is really a major issue, and your calculations can be split into many smaller independent steps, then languages like OpenCL might help.
1