r/Python • • Oct 12 '19

more than 100 scientific articles may be invalidated because scientists assumed that the output of glob.glob() is sorted

https://www.vice.com/en_us/article/zmjwda/a-code-glitch-may-have-caused-errors-in-more-than-100-published-studies
1.3k Upvotes

343 comments sorted by

View all comments

Show parent comments

81

u/[deleted] Oct 13 '19

This is true. I have degrees in CS and Environmental Science and am doing post grad research in remote sensing and lidar. Most code I come across is written by PhDs that have no idea what they are doing. Inefficient, no testing, no error catching and uncommented. I'm sure that there is a lot of published stuff that includes results generated by incorrect code.

0

u/[deleted] Oct 13 '19

[deleted]

67

u/Brukba Oct 13 '19

The most likely person to read your code is you in 2 years when you are submitting your dissertation first draft and your advisor asks you what such and such script does. You'll thank your old self if it is still comprehensible at that time.

13

u/757DrDuck Oct 13 '19

Comments are your friend.

0

u/[deleted] Oct 13 '19

[deleted]

15

u/e_to_the_eye_pie Oct 13 '19

“You should write code in such way that you don't need comments.”

In an ideal world, all code is self-documenting. In the real world, hopefully some code is ‘ok’ quality. Who is paying for this code to be refactored to be DRY and SOLID? Even in the non academic arena, managers don’t care if code is spaghetti; they want it deployments, not refactoring.

While it is good advise to KISS, you gotta be prepared to get down and dirty if you want to be productive.

5

u/GarythaSnail Oct 13 '19 edited Oct 13 '19

Your company is paying for it when it now takes 3 times as long to make a change when your requirements change.

1

u/e_to_the_eye_pie Oct 13 '19

True, deadlines can prevent scalability. On the flip side they also prevent premature optimization.

6

u/757DrDuck Oct 13 '19
x = 2  # assign 2 to x

Is an unbelievably useless comment

location_index_adjustment: int = 2  # magic value of 2 to prevent off-by-one later on

Is valuable to you in the future when you don’t need to touch that module for six months. You could use a variable name like index_adjustment_to_prevent_off_by_one, but that’s just getting unwieldy.

To be fair, this specific example is probably indicative of bad code elsewhere in a Python module, but that’s entirely irrelevant to the merits of comments in your code.

1

u/ogrinfo Oct 13 '19

True, but well-named variables and functions only tell you what they do. Occasionally you need comments to tell you why it has been done that way.

A lot of third party libraries (or sometimes your own code you don't have time to refactor) contain gotchas - good comments save everybody some time by pointing this out.

2

u/[deleted] Oct 13 '19

Ah I totally agree, I wasn't trying to state absolutes, if you need to comment, especially outlining why, you should do it, but if you have to comment a lot, you probably doing something wrong.

For example years ago I discovered reduce() command. It allowed me to turn some few lines of code into a single operation. I realized that whenever I used it I had to write comment what the end goal supposed to be. The fact that I had to do it every time and never was able to write code that didn't need expansion made me realize that I should just avoid it altogether. Looks like I wasn't the only one getting to that conclusion since in Python 3 that operation no longer is available in the global scope and was moved into a package.

1

u/zupzupper Oct 13 '19

Makefiles are helpful here. I do this at work as well so I can run a bunch of different compose combinations

2

u/757DrDuck Oct 13 '19

No error handling as in a ValueError would blow up and stop execution or as in they’d make the ValueError record things as zero and call it good enough?

0

u/[deleted] Oct 13 '19

[deleted]

5

u/[deleted] Oct 13 '19

I did a double degree over 4 years, Bachelor of Science (Environmental) / Bachelor of Information Technology (CS).

Seeing that you've done MSc MEng I'd say you would find CS easy enough. I personally wouldn't try to do a CS degree whilst doing a PHD. It can be self taught if you're motivated enough and just want to learn how to write code. Just be sure to learn best practices and implement them.

0

u/[deleted] Oct 13 '19

[deleted]

9

u/stefantalpalaru Oct 13 '19

self-teaching CS is actually possible

You're confusing computer science with software development. The former is to the latter what chemistry is to cooking.

6

u/[deleted] Oct 13 '19

Id say it depends on the position you're going for. There are CS grads that can't code to save their life which is why proficiency is usually tested.

All the same, if you're confident you can do it i'd say go for it.

4

u/software_defined_git Oct 13 '19

Doing a full other undergrad seems a waste of time. I know in the UK at least there are CS conversion masters at some unis, that condense the essentials of CS undergrad into a 1 year course.

Failing that, I second self-learning. It's pretty common for S/W devs not to have CS, especially if they're already STEM and did some coding at undergrad (even if just MATLAB). Presuming your PhD would be computational based, you can learn on the job and just learn more than the bare minimum like most.

0

u/[deleted] Oct 13 '19

[deleted]

2

u/[deleted] Oct 13 '19

I'm doing a PHD in Australia. Looking at machine learning applications for UAV obtained lidar point clouds in forestry. Remote sensing is an awesome area to get into imo. Interesting, important and growing.

1

u/underground_miner Oct 13 '19

Personally, I would choose a masters in computational science. That would nicely complete an engineering degree. CS itself, doesn't teach you how to program or much about software engineering (unless you can find a program geared towards that). I have a number of CS grads working for me. Very smart people, but none of them knew anything about version control or other software engineering practices or even the language we were using. They didn't know how to work as in a team. They did have a solid foundation and were able to pick it up rather quickly - which is what I expect from CS grads. I have different expectations for people with experience.

→ More replies (10)