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.

  • 12
    So you tried C++ and it wasn't working out for you. That's not unusual. But why the heck did you think to try PHP next? It's like trying to learn classical guitar and giving up for Guitar Hero. – joshin4colours Sep 22 '12 at 19:32
  • 3
    D never gets any love :( – You Sep 22 '12 at 20:43
  • 2
    Try C++11, it fixed many of the original C++ pains – SK-logic Sep 22 '12 at 21:12
  • 6
    Memory handling tiring you? Odd. I have written C++ for years with rarely ever having to type new, and never delete. Maybe you just think you have learned C++? – sbi Sep 22 '12 at 21:30
  • 2
    @DXM: Mostly because only people who don't know how to RAII come up with those bugs. – DeadMG Sep 23 '12 at 16:03

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.

  • Java fell second on language popularity (TIOBE)... behind C. So it's still hot especially with the big data wave coming. – m3th0dman Sep 22 '12 at 19:59
  • @m3th0dman: Because TIOBE is such a great source of language popularity... – Xeo Sep 22 '12 at 20:42
  • 1
    PHP isn't too high level, it's just very slow and impractical for what i want. Thank you for the answer i will give C# a look. – wxiiir Sep 22 '12 at 22:35

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.

  1. Pointers might be easier to handle if you try smart pointers.
  2. 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.

  • I've thought about some of those solutions before, thank you for answering – wxiiir Sep 22 '12 at 22:32

Not the answer you're looking for? Browse other questions tagged or ask your own question.