Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

PHP Php or c++ ?

  1. Jun 28, 2008 #1
    Hi,
    I was thinking of learning c++ as it would help me in my first year at university. However, someone told me that i should learn php first as it is easier and then learn php.

    Is that true?
    If not then are there any good tutorials on the internet for C++?

    Thanks.
     
  2. jcsd
  3. Jun 28, 2008 #2

    chroot

    User Avatar
    Staff Emeritus
    Science Advisor
    Gold Member

    PHP is essentially only useful for web design. (If you wanted to learn a php-like language, consider Perl, which is more general-purpose.)

    C++ is a difficult language full of nuances and opportunities to make mistakes. I'd suggest python over both -- it's an easy-to-use, powerful, general purpose language.

    - Warren
     
  4. Jun 28, 2008 #3
    python....rings a bell...is it like a 'baby version' of c++ ?
     
  5. Jun 28, 2008 #4

    chroot

    User Avatar
    Staff Emeritus
    Science Advisor
    Gold Member

    No. Python is several generations ahead of C++, and has almost nothing in common with it in terms of syntax or features.

    - Warren
     
  6. Jun 28, 2008 #5

    Borek

    User Avatar

    Staff: Mentor

    For sure don't start with php. It is too specialized and oriented on one particular task. Once you will know how to program in general, php will be a breeze (and could be you will find it limited).
     
  7. Jun 28, 2008 #6
    Thanks.

    So which language would u recommend me to start off with?
     
  8. Jun 28, 2008 #7

    D H

    User Avatar
    Staff Emeritus
    Science Advisor

    If you are going to learn a language on your own, absolutely not C++. It's syntax is a bit quirky, it has a rather steep learning curve, and if you learn it on your own you almost certainly will learn some bad habits that will be hard to unlearn. Learning C++ is best done in a context where someone can show you the ropes and where you can ask someone for help.

    Much better would be to go with a kinder, gentler language. Python has already been mentioned. I'll mention two more: Ruby and Erlang. My personal recommendation: Ruby.
     
  9. Jun 28, 2008 #8

    chroot

    User Avatar
    Staff Emeritus
    Science Advisor
    Gold Member

    Ruby is an interesting language, but I do not yet consider it to be "general purpose." Most importantly, it does not have bindings to any GUI toolkits. In other words, you can't make windows and buttons and dialog boxes and so on in Ruby, something which many new programmers desire.

    Futhermore, Ruby seems destined to get stuck in the world of web design, and it borrows too much of the horribly-designed Perl syntax for me to stomach.

    Python has almost all the same basic features as Ruby (except continuations and a few other seldom-used constructs), is used by a much wider audience, and will be much more useful for University-level tasks like scientific or numeric computing. (I'm assuming the OP is pursuing some form of technical degree.)

    I'm not against Ruby, nor am I trying to turn this into a language war. :biggrin: I just think some of the things Ruby lacks (like GUI bindings) make it a poor choice for a first language, and I wanted the OP to know about that before digging into either language.

    - Warren
     
  10. Jun 28, 2008 #9

    mgb_phys

    User Avatar
    Science Advisor
    Homework Helper

    Python's big advantage ( apart from being a very powerful, easy to learn and easy to read language ) is the number of scientific add-in libraries - eg scipy / numpy
     
  11. Jun 28, 2008 #10

    nrqed

    User Avatar
    Science Advisor
    Homework Helper
    Gold Member

    What about Java vs Python?

    I am more interested in scientific calculations and in simulations (for example, simulations of fluctuations on a spin lattices a sa function of the temperature and so on). What would you suggest?
     
  12. Jun 28, 2008 #11

    mgb_phys

    User Avatar
    Science Advisor
    Homework Helper

    If you are doing the sort of problems where the computer gets it's own building you are going to be using fortran - it's what supercomputers are built for.
    Python is fast enough for most things ( the scientific libs are written in 'C') even if they aren't which would you rather do, spend 10mins writing the program and have it run for an hour - or spend an hour writing a program that runs in 10mins! Computers are cheap programmers are expensive.

    And the final reason is that all the cool kids do Python, Java is for people that think TPS reports matter.
     
  13. Jun 28, 2008 #12

    nrqed

    User Avatar
    Science Advisor
    Homework Helper
    Gold Member

    :biggrin:

    I am not planning to do super computations (i.e. computations for research), mostly for animations for pedagogical purposes.

    I definitely would rather spend 10 mins writing it and letting the computer do the rest of the work!

    I guess my question was if Python is easy to program for (simple) simulations.

    Thanks
     
  14. Jun 28, 2008 #13

    chroot

    User Avatar
    Staff Emeritus
    Science Advisor
    Gold Member

    Java is just a cleaner version of C++. It had its heydey, and may even still be the most-used language, but it's rapidly declining in popularity.

    Python is in an entirely different category. I would strongly suggest Python for any kind of scientific computation, if you don't want to use commercial products like MATLAB. Python continues to gain popularity and reputability -- Google selected Python as the de facto language for it's entire Google Apps product, for example.

    You almost can't go wrong with it, in my opinion!

    - Warren
     
  15. Jun 28, 2008 #14

    chroot

    User Avatar
    Staff Emeritus
    Science Advisor
    Gold Member

    Speaking as a computer engineer with 15 years of computer programming experience (wow, I suddenly feel old), I can tell you that Python is the easiest language to read and write that I have ever seen. It is absolutely a pleasure to work with.

    - Warren
     
  16. Jun 28, 2008 #15

    nrqed

    User Avatar
    Science Advisor
    Homework Helper
    Gold Member

    Thank you Warren. Is it easy to make simulations (like a GUI allowing to set parameters and watch some physical systems evolving in time)?
     
  17. Jun 28, 2008 #16

    mgb_phys

    User Avatar
    Science Advisor
    Homework Helper

    Python supports openGL so you can do complex graphics. The main gui toolkits are wxPython or pyQT (python ports or wxWidgets and QT respectively)

    Another common approach is to write images and use some external tool to showthemas a movie - this is necessary when it takes a while to generate each new stage/image. Python has the PIL - python imaging library to make this easy
     
  18. Jun 29, 2008 #17

    Borek

    User Avatar

    Staff: Mentor

    Sometimes it is much easier to tell which language not to use, than to recommend something. I have heard a lot of positive comments on Python, but I have no hands on experience. C++ is not a good idea as a first language, it is better to have some idea about programming before switching to C++ (and/or C).

    20 years ago, in Turbo Pascal times, Pascal would be my language of choice, but these times are long gone.
     
  19. Jun 29, 2008 #18
    I actually think C++ might be a better language to learn than other OOP languages where everything is treated as an object, such as ruby. This is because C++ supports multiple paradigms in addition to OOP, like generic and procedural programming. You can be "eased" into programming with procedural programming, which imo is easier to learn than OOP and less confusing. While java claims to support procedural it is actually not very well implemented.

    Many books on C++ start you off with procedural and ease you into the OOP elements, and this is a good way to learn. At such a point, you will be more easily to adapt to Java. (I learned the basics of C++ in combination with java, and wish I had started with C++ first.)
     
  20. Jun 29, 2008 #19

    chroot

    User Avatar
    Staff Emeritus
    Science Advisor
    Gold Member

    OrbitalPower,

    Python supports procedural programming, and is easier in virtually every respect than C++.

    Java is rapidly becoming a dead-end language, and it's the most rigid and verbose of all the languages mentioned in this thread.

    - Warren
     
  21. Jun 29, 2008 #20

    D H

    User Avatar
    Staff Emeritus
    Science Advisor

    One of the hardest things for a beginner programmer is just getting started. Once that has been accomplished the beginning programmer needs to learn about some simple logic and data structures. A beginner language should be simple enough so that getting started is easy, complex enough to enable learning of logic and data structures, and clean so that the intricacies of the language don't hinder learning.

    C++ certainly has no problems dealing with the complexity issue. However, it does not do a good job with the "just getting started" problem and it does a terrible job with the clean/compact problem.

    I'm not a huge fan of Python, but I would recommend Python over C++ as a beginner language any day.
     
  22. Jun 29, 2008 #21

    f95toli

    User Avatar
    Science Advisor
    Gold Member

    I think the "best" language I've ever used is Ada, it is quite unusual nowadays but I know it was the standard language in many organizations (e.g. DoD) for writing critical apps for a number of years (because it is very easy to debug).
    Ada 95 was used to teach programming at my university and even although I had used Pascal, C, C++ etc before I attended those courses I DID learn a lot, mainly because Ada was designed to essentially force you to pick up good habits (Ada supports strong typing etc). It is a very well-structured and consistent language (some would say a boring language...).

    Note that I would not recommend anyone to use Ada to write anything that will actually be used, but it is a good language and if you understand Ada you can quite easily learn more "quirky" languages like C, C++, Fortran etc (although I guess that is true of most languages, once you know one you can learn others quite easily).

    Java is a "fun" language because it is easy to write applications with a nice GUI, but I am not convinced it is a good language for beginners.
     
  23. Jun 30, 2008 #22
    Jumping right into C++ as your first programming language is not the best plan...

    I would suggest learning Python first, it will give you a solid base for programming and also get you into good programming habits. I suggest you grab a book; get a UNIX based OS and get to programming. After you get a good foundation in Python your road to programming is much smoother, after this I would strongly suggest you learn a dialect of Lisp (preferably Common Lisp or Scheme). Lisp will change your perspective on programming, it is by far the language that I learned the most from. After this you should be ready to get into C which will lead you good on in to C++. If you want before starting C/C++ it will be excellent if you have the time to learn a bit of Java, the syntax is quite similar to C++. Have fun and explore the shear power and might of C++, the raw speed of C++ is amazing. After you have all these languages under your belt dive deeper, Assembly, Prolog, MS, Haskell, there are tons of educational languages out there take advantage of them.

    -Ink
     
  24. Jul 1, 2008 #23

    Ben Niehoff

    User Avatar
    Science Advisor
    Gold Member

    The languages that I have used, with some comments:

    BASIC: Fun when I was 10. Not very useful.

    C: Frustrating to get used to, but it's the paradigm that many language syntaxes are built on. If you learn C, you can learn anything else (and breathe a sigh of relief when you use a more advanced language and don't have to worry about malloc()-ing everything anymore). C was my introduction to compiled (vs. intepreted) languages.

    C++: Slightly less frustrating than C. Slightly.

    Fortran: Hated every second of it. The only reason this language still exists is the massive amounts of legacy code being used by the aerospace industry. It is clumsy and pedantic. Fortran fans extoll the virtues of Fortran for mathematical calculations; however, every mathematical calculation I can think of would be easier to implement in C. And that's saying something.

    JavaScript: Limited to web design, and confusing as all get-out. It seems features were added pretty much randomly, whenever Netscape felt like they were needed. Very inconsistent (but very necessary, if you do web design).

    Java: Everything is an object. Programming in Java feels like playing with LEGOs! Good if you want to learn OOP principles fast. Less confusing to learn than C++. However, as noted by everyone else, Java is going out of style.

    Perl: Perl's highly-flexible syntax is a blessing and a curse. You can write your own programs in a few short lines, but good luck trying to read anyone else's. Very useful if you do text-processing. I have always loved Perl's regular expression engine, and used it extensively. Perl is useful for Web applications as well as standard command line stuff, and can draw GUIs well enough.

    Python: Had to use it for a class, didn't really get into it (I was on a Perl kick at the time). But it's quite useful; does everything Perl can do, with a much more consistent syntax.

    Lisp/Scheme: Lisp is a programming language from another planet. It is what's known as a "functional language", which is a drastically different paradigm than the procedural style of C-like languages (i.e., most of those listed above). It is an implementation of Church's Lambda Calculus, which means that functions execute according to parenthetical nesting, rather than proceeding down one line at a time. It's a highly mathematical structure, and I found it very beautiful, but it took a bit of thinking to figure out how to do things, because I was used to the more procedural style of other languages.

    PHP: As mentioned, this is for web design only. Not recommended as a first language. It's also rather inconsistent, especially across versions, which is frustrating when designing web applications that might end up running on PHP 4, 5 or 6. The language is slowly approaching a structure that makes more sense, but most web hosts are a few versions behind. The worst thing about PHP is that it can't make up its mind whether it should be strongly-typed or not; in many ways, it would be more useful if it were. As it is, types get converted between each other on the fly, and often with unpredictable or undesirable results (is some variable an empty string or a zero, or a string containing the character '0'?, etc.). On the other hand, it seems to be pretty easy to throw things together with PHP, until you run into a situation where you actually care what type something is and/or how something is being interpolated.
     
  25. Jul 1, 2008 #24

    D H

    User Avatar
    Staff Emeritus
    Science Advisor

    That's just wrong. Just two of many reasons why Fortran fans stick to the language are exponentiation and arrays. Fortran has an exponentiation operator. C does not. C's pow function is a very poor substitute. Fortran flat out does a better job with arrays than does C. C++ comes closer if you define matrix and vector classes, but the result is clunky and slow compared to Fortran.

    BTW, last time I used Fortran was twenty+ years ago. Some Fortran afficianados are hard core. Very hard core. That C will not create an exponentiation operator because it is too far from the underlying machine is just silly. It is perfectly valid in C to say 'x=y', where x and y are very complex data structures. C's arrays have always been viewed as a weak point of the language by Fortran fans, and for good reason.
    I love perl, particular its regular expressions, but hate its syntax. Perl is vulgar. We use $%@# in any other context to denote a cuss word.
    No. Lisp is just in low Earth orbit. Forth is in geosynchronous orbit, Prolog is a language from another planet, and APL is from another universe.
     
  26. Jul 1, 2008 #25
    In saying the above I'm guessing that you don't really know how messy Perl can get when you program something over 30 lines. And then coming back to a Perl program longer than 30 lines after a month will make you just puke your guts.
     
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook