1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

C++ or Java for Undergraduate Research Oppurtunities?

  1. Nov 11, 2011 #1
    Hello, everyone.
    I've been learning how to code for a bit. I picked Python because I figured I'd be able to skip the issues I would otherwise have with syntax and focus more on the programming aspect of it.

    Soon, though, I'm going to be ready to dive into one of the other languages with a foundation in the basics. I need to now (for the near future) pick between C++ or Java as my next language.

    I plan on pursuing an undergraduate degree in Mechatronics engineering beginning next September, and the university I'm going to go to has an http://en.wikipedia.org/wiki/Undergraduate_Research_Opportunities_Program" [Broken] which I will want to participate in. As of now, I think I want to eventually work within control systems engineering. I would therefore likely pick projects that are within fields similar to CSE.

    I already glanced through the postings on the website, but I was still hoping I could get an opinion from you guys. And I also plan on eventually picking up MATLAB along the way, in case you guys were going to suggest that in lieu of C++ or Java

    So with that in mind, what language would you recommend?
     
    Last edited by a moderator: May 5, 2017
  2. jcsd
  3. Nov 11, 2011 #2

    Hurkyl

    User Avatar
    Staff Emeritus
    Science Advisor
    Gold Member

    If I may instead answer the question "I want to learn C++ or java for my own edification and programming ability", I would answer C++. You'll learn more, and I feel all of the benefits that java would have over C++ you already have due to having learned python. The main advantage java would have in your position is tighter integration with python -- i.e. the Jython interpreter. That said, that has the potential to be a rather significant advantage. (I, unfortunately, do not have experience using Jython, so I'm comparing my experience integrating C/C++ and python to my imagination of how Jython would work)
     
  4. Nov 11, 2011 #3

    chroot

    User Avatar
    Staff Emeritus
    Science Advisor
    Gold Member

    You're better off staying away from Java -- it's a dying language. Here's a plot from http://www.tiobe.com/index.php/content/paperinfo/tpci/index.html", which measures the popularity of programming languages by mining the internet.

    http://www.tiobe.com/content/paperinfo/tpci/images/tpci_trends.png

    You should draw your own conclusions, of course, but I'd suggest learning C++. In the end, you'll learn similar skills from both C++ and Java, but I'd expect C++ to be more marketable in the future. You might also want to consider Objective C.

    - Warren
     
    Last edited by a moderator: Apr 26, 2017
  5. Nov 11, 2011 #4
    Java may be becoming measurably less popular, but it is still VERY far from being "a dying language."

    Let's take a look at that graph again: Java is decreasing in popularity. That's plain to see. But C++ is decreasing in popularity just as much as Java is, by this graph. And as you can tell, Java is still used way more than C++. The graph makes it look like a factor of 2 difference. That's big. Java is used a LOT.

    Warren makes a good point, though, even though he ties it with the wrong reason. Java is pretty similar to C++, so you'll learn valuable skills from both of them. In fact, all 3 of Java, C++, and Python are pretty high-level languages. So it would be REALLY useful to learn about assembler and C and then see how C is translated to assembler by the compiler.

    It's my guess that in control systems engineering, you'd be programming a good bit with microcontrollers in assembler.

    Finally, ahttp://www.joelonsoftware.com/articles/CollegeAdvice.html", who is a pretty smart guy in the Software Engineering business:

    Yeah. Don't get hung up much over whether to choose C++ or Java. Also, whichever of those you DO choose, don't stop there http://www.joelonsoftware.com/articles/ThePerilsofJavaSchools.html"
     
    Last edited by a moderator: Apr 26, 2017
  6. Nov 11, 2011 #5

    Vanadium 50

    User Avatar
    Staff Emeritus
    Science Advisor
    Education Advisor

    I would add that it is preferable to know how to program than any given language. Bad programmers can program badly in any language.
     
  7. Nov 11, 2011 #6
    Oh yeah, I definitely agree with Vanadium. Just like if you're a musician, it doesn't matter how many different instruments you play (unless you're percussion, I guess). What matters is how good you are at one instrument.
     
  8. Nov 12, 2011 #7
    The Jython interpreter doesn't provide that much of an advantage since there's also the Cython and CPython interpreter.

    The graph gets it's data from mining websites, doesn't that mean its not really applicable in this situation considering I'm not going to be doing much web-programming? But it still makes your point about reduced popularity, I guess.

    As much as I would love to learn assembly language, and the mechanics of how compilers work, I don't think I have either a decent source to learn from or a strong enough foundation to go deep.

    And I get what you said about developing decent skills in one language, which is why I'm picking either C++ or Java and sticking with it for the next year or so.

    Still haven't made up my mind, but I'm leaning towards C++ atm.
    Any additional replies are more than welcome.
     
  9. Nov 12, 2011 #8
    I did all of my work (modeling dynamics of BECs) this summer using Python and Cython. It is very easy for one to build a prototype of the model using Python without getting too hung up on the details of the language. Wrapping the program up with typedefs and bringing it down to C speeds is very easy with Cython. Although C itself does not support classes and objects, you can work around all this without too much effort using Cython.

    That said, it would help you use Cython to know a bit of C or C++. Moreover, one might sometimes want to strip down certain parts of the program to lower level languages when one needs control of the finer details. To this end, the traditional languages used are C and FORTRAN.

    Thus I would strongly suggest going for C++ (or even C) rather than Java.

    Even within Python, there's a lot to explore. For science and engineering, the numpy and scipy toolkits blow you away. (Google to find out more about these) I find that they offer a good competition to MATLAB for most jobs that I need done. There are also plotting toolkits like matplotlib and Mayavi, which are very good and easy to use.
     
    Last edited: Nov 12, 2011
  10. Nov 12, 2011 #9

    AlephZero

    User Avatar
    Science Advisor
    Homework Helper

    I'm puzzled by what the TIOBE graph actually means. It makes no sense to me that "C" scores more than twice as high as as "C++". Does anybody still even market compilers that only support C and not C++?

    I suspect they are doing an automatic scan of the number of web forums, tutorials, etc, rather than measuring "real" programming activity, and certainly not measuring programming in the scientific community.

    To the OP - learn how to program, in depth, in whatever language you like. Python is as good (or as bad) as any other. Then you will be able to pick up enough of another language (or several!) to "get by" within a few days, because you already know what you want to do, and all you need to learn is a new syntax for how to write it down, which is fairly trivial.

    If you really want to learn a second language now, I would go for one of the variants of LISP. That will expand your thinking about programming a lot more than learning trivia like the difference between friend functions in C++ and packages in Java, etc.
     
  11. Nov 13, 2011 #10
    If you learn either C++ or Java, it won't be hard to switch to the other. But for any sort of scientific programming, go with C++. Java works through a virtual machine, which makes it unusable for any sort of serious scientific programming.

    Also, learn machine and assembly language. In any sort of heavy duty scientific programming, you are just using the language as a short hand for generating assembly language.
     
  12. Nov 13, 2011 #11

    Hurkyl

    User Avatar
    Staff Emeritus
    Science Advisor
    Gold Member

    As I understand them, Jython and Cython are quite different.

    Jython is an actual python interpreter. Your python code can directly access java objects when using this interpreter.

    Cython, on the other hand, is effectively new compiled language. You use it to compile python code, and to write wrapper modules around your C libraries.
     
  13. Nov 13, 2011 #12

    Hurkyl

    User Avatar
    Staff Emeritus
    Science Advisor
    Gold Member

    That's only true if all you learn about C++ is the "C with object oriented programming support" aspect -- but quite frankly that doesn't really count as learning C++, and that's not an important aspect of C++ anyways, given the context.

    A dozen years ago, you'd be right -- but you overlook JIT compilers.

    This is bad advice, I think. Very, very few people should ever program in assembly language, and the vast majority of them should only write tiny snippets of assembly code. The OP has a lot of things to learn before learning assembly is actually a productive use of his time (let alone be anywhere close to the most productive use of his time).
     
  14. Nov 14, 2011 #13

    chiro

    User Avatar
    Science Advisor

    Some domains will require that you code things down to the bare-metal because speed is so-critical. This was the case with video games: you still have many routines coded using the SIMD routines because it is just important.

    Given that twofish-quant does work in numerical optimization routines, I'm not surprised by his statement, and for his purposes I think he is telling the truth.

    Most coding now requires more complexity than it used to when everything (or most things) were written in assembly and it's just not practical for most projects to be written in even one high level language like C++.

    However knowing what goes on in the state-space of your memory and the flow-control is absolutely critical if you want to know what you are doing. Knowing exactly how data is passed, how it is represented and how it is accessed is important especially if you want to interface between two code-bases like say between DLL's or between processes or something of that kind.

    Now granted you can get away with not knowing assembler and still know these kinds of things, but if you did know assembler, you would automatically understand all of these issues and when the same problem was presented in a different context, (i.e. one context could be passing data between DLL's, one other could be translating structures from programs compiled in different languages, if they are defined differently), then the person who knows assembler will find this a lot easier than the other guy who doesn't on average.

    My advice to the OP is to learn assembler if he/she wants to do any coding in either a) optimization environments (like games, scientific programming) b) wants to do work in environments that pass data around like with DLL's (or if you have to god forbid debug compiled code) or c) wants a deeper understanding of what is really going on.
     
  15. Nov 14, 2011 #14

    Vanadium 50

    User Avatar
    Staff Emeritus
    Science Advisor
    Education Advisor

    Once again, you are vastly overstating your case. ANY sort of serious scientific programming? What I think you mean is "unsuitable for the kinds of scientific programming where the raw throughput is the limiting factor". That's not all of it, and the case could be

    Much of our DAQ interfaces are written in Java. This is an area where throughput is less important than ease of coding, portability and adaptability of code and consistency of user interface.

    I also know of one case where code was ported from C++ to Java, even though it ran 2-2.5x slower. By doing so, the code could now run on idle Windows machines through condor, increasing the available cycles by 10-40. This was a big win.
     
  16. Nov 14, 2011 #15
    DAQ interfaces where throughput isn't that important? I guess it depends on what you are trying to measure...

    Just learn to program in either language. If you go into scientific or engineering programming you are more likely to be using C++ than Java. I have done projects in C, C++, Ada, and small parts in assembly. Java isn't suitable for embedded applications or applications where you are trying to maximize performance... but if you are just trying to learn programming its syntax is similar to C++ and the coding concepts are the same so it doesn't matter.
     
  17. Nov 14, 2011 #16
    Hi Hurkyl, do you care to explain about this statement? What should be an important aspect of learning C++?
     
  18. Nov 14, 2011 #17
    No I'm not. JIT compilers don't give you enough control over what is happening at the machine level. What you want is to put things in the L1 cache so that the CPU doesn't have to deal with fragmented memory.

    The other problem with Java is that because all classes are virtual, any sort of loop over an object requires a memory lookup, whereas with C++, you can statically inline those types of functions with templates. Once you've statically inlined the function, then you can use SSE instructions to pipeline the floating point.

    The few people that need to think in assembly language include computational physicists. If you have a huge simulation then how the compiler changes the instructions into machine code is the difference between something that take two weeks to run versus something that takes two years to run.

    One reason that it's not that necessary to program in assembly language is that where it matters, people have already done it. Both Intel and AMD have assembly language BLAS libraries that are hand-tuned to do matrix operations in assembly language. Even though you don't have to program in assembly, you still have to think in assembly to understand why they do some of the things that they do.

    I've never had to program in assembly code recently, but I've frequently had take a disassembler and look at assembly code produced by the compiler to see what instructions were being executed.

    This matters for getting jobs also. The types of services that an investment bank can offer is often limited by what the computers run overnight between the end of business and the start of business, and shaving 20% in runtime can make a huge difference.

    And then there is GPU which is a total game changer.
     
    Last edited: Nov 14, 2011
  19. Nov 14, 2011 #18

    chroot

    User Avatar
    Staff Emeritus
    Science Advisor
    Gold Member

    I would never give my money to an investment bank that hand-codes its routines in assembly...

    twofish-quanta, when speed matters that much, you're right, assembly may be the only way to go. On the other hand, in many situations, speed doesn't matter that much, and the benefits of higher-level languages far outweigh their cost in speed. The bottom line is that one should always choose the right tool for the job.

    - Warren
     
  20. Nov 14, 2011 #19
    It's not as if you have much choice in the matter. You give your money to bank A who gives the money to bank B who gives the money to bank C. Eventually it ends up going through a supercomputer in Jersey City or Canary Wharf.

    Also sometimes assembly isn't fast enough. There are some cases in which I know of in which people have hired EE's to build custom *hardware* to do a calculation.

    There's a difference between programming in assembly and understanding assembly. One of the cool things about C++ is that with a good compiler, there isn't a speed/maintainability tradeoff. With well written C++ and tuned libraries, you can end up with code that is essentially the same speed as assembly.

    And then you wrap everything in Python. One thing about numpy and scipy is that the libraries are well designed enough that for many problems there *isn't* a performance hit. Because the low level operations are vectorized, you can write Python code that's almost as fast as hand written assembly, if you understand what the CPU is doing.

    The reason for taking a course in assembly language is to improve your higher level language programming skills, so that when you write something in C++ or Python, you can imagine what the compiler is doing with the code, rather than treating it as a black box. If you give me some C++ or Python code, I can visualize what the CPU is doing with the code and if it's too slow, I can figure out why.

    The problem with JIT compilers is that they encourage "black box thinking" which is a bad thing.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: C++ or Java for Undergraduate Research Oppurtunities?
  1. Undergraduate Research (Replies: 4)

  2. Undergraduate research (Replies: 1)

  3. Undergraduate research (Replies: 2)

  4. Undergraduate research (Replies: 6)

  5. Undergraduate Research? (Replies: 62)

Loading...