Which programming language to learn?

In summary: Charm++.In summary, a fellow astrophysics student recommends learning C or Fortran, but preferably C, because C++ is an object-oriented language. Different programming languages can be used for different purposes, but Python is a good learning and prototyping language, and it is fast and has unlimited integer arithmetic.
  • #1
Dathascome
55
0
Which programming language to learn?

Hi there,
I've decided to start teaching myself a programming language and it was recommended to me by two people both in the field I'm getting into (astrophysics) to learn either C or Fortran but preferably C. I was told C rather than C++ because C++ is object oriented and I don't need to worry about that for what I'll need to be doing.

I was also talking to a fellow who does computer science and he told me that C is good and all but I shouldn't be wasting my time with learning that now and i should be learning perl and/or python because they're more efficient in some manners.

If anyone doing physics or astronomy has any advice on this matter it would be greatly appreciated.
 
Computer science news on Phys.org
  • #2
It depends on why you want to learn the language. If it's to run simulations, I would think there are a zillion software packages available that run astrophysical simulations. You just need to learn them instead of a programming language. If it's to design your own software package, then i have no clue which would be easiest.
 
  • #3
I would suggest you teach yourself both C and python.

Python is a good learning and prototyping language where you can work out the basic algorithms. It is easy to write good code with few (easily detected) bugs, develop good habits, and also get a good sense of object oriented programming if you want to learn that. Python has excellent debugging feedback when errors occur!

It is also pretty fast for an interpreted language, has unlimited integer arithmetic (so you could e.g. calculate 100! and it will print out all the digits)
and many useful built in data structures. It is also an open standard so you can download good useful interpreters and code is pretty well interchangable between systems. You can also download many packages which can handle big numerical calculations by loading modules written in C.

If you actually want to crunch some numbers, you will want to compile C programs. Short of delving into assembly you'll find the fastest code is written in C. Indeed it is the standard compiled language of Unix/Linux operating systems and most all the non-assembly coded programming is done in C.

Once you've mastered say Python for simple or objected oriented programming and C for hard-core work you will find it easier to translate code into other languages (with the language manual in hand).

I also think the syntax of Python and C are such that you can begin learning both at the same time without confusing the two styles.

My advice is start with Python. Then learn C once you have learn the basics of data structures. As an exercise you would try to implement in C some of the built-in data structures of Python.
 
  • #4
you will soon find that some languages are better suited for some tasks than others. However, whoever told you that you don't need to bother with C++ because it's an OO language is very short sighted (IMO). You will find it very difficult to get away from anything recent that isn't OO or has some OO characteristics.

These are the ones that I would put on the list
C/C++
Fortran
Shell scripting (if you plan on being in a *nix environment)
PHP/Perl/Python

I wouldn't bother trying to learn them all at once. Just learn them as you need them.
 
  • #5
as a computational science student(my supervisor is in astrophysics) I suggest starting with C...it has probably the highest learning curve out of any language(besides asm)...and IMO its best to start early one of the key things to learn in C is memory and bit manipulations ( printf("%p",pointer); is your friend)

One question u will have to ask yourself is what do you see yourself doing in the future. IF it has anything to do with HPC(high performance computing/parallel computing) you shouhld really start with see and code anything (math and physics concepts ) that come along your way. ALso if it has anything to do with visualization or physics in games...stick to C/C++.

Can't say much about python but I'm learning it currently(well the c component of python) but i can say that python in my app is only used as a scripting language ontop of a C/C++ driven engine. That is it allows the engine to execute runtime commands for visualization but not for the simulation itself. But as said in the above post its a nice language to write simple short code but that can be said for any language like matlab/maple.
Even C/C++ is short code if you know where to look for the libraries. Cygwin is a good place to start but sadly my preference is MSVC# compiler and IDE.

As for C and C++ well charm++ is written in C++ and it drives some of the most sophisticated molecular dynamics and astrophysics sims. But make sure along the way you learn some type of neetworking protocol something i didn't do till my masters(mpi is a good place to start). The only benefit C++ has to C is inheritance but I'm pretty sure you can fake inheritance through void*. I personally don't like pure OO and don't see the point to it(neither does my supervisor) so you should look to do a OO/functional hybrid.

i would have to disagree with the post above that you should start with python to look through their data structures before converting them to C
becuase you may still come across the many difficults of learning pointers.
There's a good gaming book written by an 18 year old about data structures and he give explicit code examples(primatech series if i remmeber correctly).

also your standard university textbooks like...crap i can't remmeber the author or name it comes in 5 parts in C/pascal and i think now in java.
 
Last edited:
  • #6
jambaugh said:
Python is a good learning and prototyping language where you can work out the basic algorithms. It is easy to write good code with few (easily detected) bugs, develop good habits, and also get a good sense of object oriented programming if you want to learn that. Python has excellent debugging feedback when errors occur!

I disagree with your constant assessment that Python is a "learning and prototyping language." It's as fast as C for many operations, it's extremely easy to learn and maintain, and it has an enormous standard library on par with more mainstream languages like Java.

It is also pretty fast for an interpreted language, has unlimited integer arithmetic (so you could e.g. calculate 100! and it will print out all the digits)
and many useful built in data structures. It is also an open standard so you can download good useful interpreters and code is pretty well interchangable between systems. You can also download many packages which can handle big numerical calculations by loading modules written in C.

Well-written Python programs spend most of their time in the underlying highly-optimized C implementation. Python is at least as fast as C for most scientific applications, and is frequently faster for novice users who tend to write rather poor C code. In fact, Python has a commanding presence in the world of scientific computation, for good reasons. It's completely disingenuous to describe it as a teaching language or as being unfit for doing "real" computations.

My advice is start with Python. Then learn C once you have learn the basics of data structures. As an exercise you would try to implement in C some of the built-in data structures of Python.

My advice is to learn Python and MATLAB or Mathematica thoroughly. I suggest simply learning C well enough to be "dangerous," i.e. able to read other peoples' code and make small modifications. I wouldn't even attempt to write a complete numerical code in C unless you find out that you have to, for some reason or another.

- Warren
 
Last edited:
  • #8
chroot said:
My advice is to learn Python and MATLAB or Mathematica thoroughly. I suggest simply learning C well enough to be "dangerous," i.e. able to read other peoples' code and make small modifications. I wouldn't even attempt to write a complete numerical code in C unless you find out that you have to, for some reason or another.

- Warren

I would say that if you know or have some knowledge of C, learning Matlab is a snap and vice versa. I know C and picked up Matlab in about 2 days. A friend of mine did the opposite and learned C after working with Matlab in less than a month. The major difference is that Matlab has a butt-load of intrinsic functions that C doesn't. I'd learn Matlab as fast as I could then go on and learn other laguages to add in other functionality (Matlab has the ability to read C and Fortran routines).
 
  • #9
I'd also recommend MatLab. Think of it as a tool more than a programming language. You should also find out what the language of choice is in your inteneded environment. Fortran is still popular in some niches of the scientific world (for example the Cray computers Fortran compiler generates faster code than their C compilers, some of this due to the extensions to the language and the effort made by Cray on Fortan versus C, an apparent indication of the relative popularity of Fortran versus C on their machines).
 
  • #10
I'd stay away from MATLAB as your first language because it has too many things/styles that you could get use too when moving to another language like the one function per file or its array and vector notations (the array notations are the same as in fortran)

Personally i think the pointers in C/C++ is the hardest concept to grasp in programming (besides asm coding and hardware optimization like utilizing cache) ...as a student you should take the time to learn the hardest stuff when you have the time. And as transport said you can grasp MATLAB faster than C when learning the other language. ALso if you plan to do any advance graphics with those numerical simulations...too my knowledge MATLAB isn't very good at it though they have a parallel toolbox.

Out of curiosity for all the other posters what order have you learned these language and used them.

edit: LOL my bad, forgot to erase what was below because i moved it to another thread...
Jeff reid, if you can do the same ...its in the programming subforum. entitled something like
"when did you learn what language..."
 
Last edited:
  • #11
stay away from MatLab
Depends if the goal is to use a tool to help with school, or to learn a programming language. Matlab is going to be much more useful, in a shorter period of time for quick projects.

I've never used MatLab myself, but I have co-workers who swear by it.
 
Last edited:
  • #12
learn ksh

Its the most useful, well to me it is... But I am a network engineer not a coder :)
 
  • #13
Thanks much to all for the advice. I'm not really sure to what ends I will need to be programming (I'm just starting grad school for astrophysics in the fall), but I've already started plodding through on C, and will go at that for a bit and then try out some python.

I was also wondering how much programming skills the average physics student has when coming into grad school. Just out of curiosity. I've always had the impression that my undergrad school physics dept. didn't focus anywhere near enough on the computational side of things but I really have nothing to compare it to. There's one required computer science class but it was a while ago and I barely remember it now, and in calc 3 we use MATLAB a bit and that's it really.


Thanks again.
 
  • #14
depends if your starting grad school look at the core courses and perhaps talk to your supervisor. It also dependson the area of astrophysics your going to.
 
  • #15
neurocomp2003 said:
Out of curiosity for all the other posters what order have you learned these language and used them.

Although I can't claim to be able to use them with any significant amount of proficiency: (enough to cobble together small little programs that suit my needs)

*Applesoft BASIC
*Pascal
*F77
*C
*Objective C
*Shell
*PHP
*A smattering of Perl
 
  • #16
Matlab may b e a tool, but it's sintax is very much like C, matter a fact I've heard it called "C-light". Matlab has almost all of the perks of C and the functinoality to be useful right away. The best part about it is that although not a compiled language, it is optimized for running matrix computations and you don't need to program loops to do those types of operations, something you'll never see in C.
 
  • #17
"it is optimized for running matrix computations and you don't need to program loops to do those types of operations, something you'll never see in C"

but can't you just make BLAS calls and avoid the loops yourself?
syntax may be similar to both C and F but its file layout IMO is horrid...only one global function per file? And the file name has to be the same as the function name IMO is horrid for a coder.
 
  • #18
MATLAB's syntax, in my opinion, bears no resemblance at all to C. Nor do its features.

- Warren
 
  • #19
I think he should learn Visual Basic. It's really easy.

Ok, that was a joke, sorry I couldn't help it.
 

1. Which programming language is the best to learn?

The answer to this question depends on several factors, such as your personal goals, the type of projects you want to work on, and the job market in your area. Some popular languages to consider are Python, Java, C++, and JavaScript.

2. How do I choose the right programming language for me?

First, consider your goals and the type of projects you want to work on. Then, research the languages that are commonly used in those areas. You can also try learning a few different languages and see which one feels the most intuitive for you.

3. Is it better to learn multiple programming languages or specialize in one?

It depends on your career goals. Some jobs may require knowledge of multiple languages, while others may value specialization in one language. It's always beneficial to have a broad understanding of different languages, but it's also important to have in-depth knowledge of at least one.

4. How long does it take to learn a programming language?

The time it takes to learn a programming language varies depending on your prior experience, dedication, and the complexity of the language. On average, it can take a few months to a year to become proficient in a language.

5. Can I learn a programming language on my own?

Yes, it is possible to learn a programming language on your own, but it may take more time and effort compared to taking a structured course. There are many online resources and tutorials available, but it's important to stay motivated and consistent in your learning journey.

Similar threads

  • Programming and Computer Science
Replies
15
Views
1K
  • Science and Math Textbooks
Replies
4
Views
972
  • Programming and Computer Science
Replies
8
Views
832
  • Programming and Computer Science
12
Replies
397
Views
13K
  • Programming and Computer Science
4
Replies
107
Views
5K
  • Programming and Computer Science
Replies
16
Views
1K
  • Computing and Technology
2
Replies
44
Views
3K
  • STEM Academic Advising
Replies
12
Views
1K
  • Computing and Technology
Replies
3
Views
2K
  • Programming and Computer Science
Replies
1
Views
705
Back
Top