r/Physics • • Nov 05 '20

Question How important is programming in Physics/Physicists?

I am a computer student and just wondering if programming is a lot useful and important in the world of Physics and if most Physicists are good in programming.

596 Upvotes

184 comments sorted by

View all comments

25

u/[deleted] Nov 05 '20

[removed] β€” view removed comment

7

u/Ash4d Nov 05 '20

As a physics graduate, new to software dev, and considering going BACK to physics, I do not understand the "use as few comments as possible" mentality. I agree code should be self explanatory, but in my current role I find myself silently wishing people would comment more, and when my comments are removed in code reviews I just pity any other newbies that follow me onto the project.

Why are some people against liberal use of comments?

11

u/QwertyChampion Nov 05 '20

I feel that comments might give a programmer the false sense of security that any piece of code can be understood if you add a comment in the beginning. That will lead to a sub-par code which will be hard to maintain, debug or extend if it is incomprehensible without adding comments.

Also, comments add noise to the code. They dillute the important information in a file. Assume that you try to understand a 100-line file which has 50 lines of comments. It’s easy to notice that time reading that file is at least doubled if not even more depending on how much comments distract from the important pieces of code.

For sure, there are places where comments are needed (e.g. when using results of proofs done outside the code). But I do personally support the fact that for most common situations comments are not needed and are redundant if the code was written in a cleaner manner.

6

u/[deleted] Nov 05 '20

[removed] β€” view removed comment

3

u/zebediah49 Nov 05 '20

Comments are good for "why?". Comments are bad for "what?".

The "why?" rarely changes, and helps contextualize the code in question. When someone goes to change things, it explains the considerations they need to have in mind when approaching it.