12

I started my programming language journey with the C/C++ family of languages (i.e., D, Java, C#, etc.).

In the machine learning field, the most popular tools are written in the Python programming language.

I hate the Python language for many reasons, the primary of which is that it is dynamically typed. Keeping track of its function parameters is a daunting task for me. I am unable to remember these parameters naturally. So, it creates a dilemma: "should I repeatedly look for the documentation" or "should I focus on the algorithm I am trying to solve?"

Should I learn and use Python in my research, even if I dislike it?

I am a 2nd-year PhD student, and I want to remain in academia.

Will it be a risk for my research career if I avoid Python and its likes (e.g., MATLAB, etc.) altogether?

4
  • Which country are you in and how long is a PhD program there ?
    – Trunk
    Feb 26 at 21:02
  • We get it, there are ways to make Python act like a statically-typed language. Comments have been moved to chat; please do not continue the discussion here. Before posting a comment below this one, please review the purposes of comments. Comments that do not request clarification or suggest improvements usually belong as an answer, on Academia Meta, or in Academia Chat. Comments continuing discussion may be removed.
    – cag51
    Feb 27 at 16:16
  • I would say the question at the end of your statement should be in the title if your question is whether you should follow your supervisor and do it in Python. Then we can say, it depends on your supervisor and also on how big the project is. If small, you can propose a different approach. Otherwise, you have to follow the approach set. But if the question is about programming itself, it better go to Stack Overflow or similar.
    – Juandev
    Mar 1 at 10:13
  • oh wow an off-topic CS question with a bunch of upvotes and answers?? 🙄 Mar 9 at 18:48

7 Answers 7

27

It is not a career problem to have a preference or dislike for a language. It is a problem if you cannot work with it if it is required.

You are not working in isolation.

Even as an academic researcher, you are going to collaborate with other people. You will build on work that others have already done, and you will want others to build on your work. All those people have their own tooling preferences. If you aren’t willing to work with the commonly used tools, this is going to put you at a disadvantage.

How do you choose a language for your project?

The first thing to consider is then whether someone else (either in your group or in open source software) has already solved a significant part of that problem. You might for example be continuing a colleague’s work. In that case, the default choice would be to stick with the programming language that has already been used. If that language is a really bad choice you can still choose another language and either re-implement (which takes time and can introduce errors) or use the existing software as a library (which means you still have to work with that language if you have to fix bugs or sometimes if you want to extend functionality, and makes it harder to debug).

If you are starting from scratch then there are some things you should consider:

  • The language has to allow you to do what you need it to do, in a reasonably efficient way. So if you want to write a web service you might not want to use assembler and if you want to write a hardware driver, maybe Java isn’t the best choice either. Do you have any constraints regarding runtime, memory usage, compile time etc. that are easier to solve in some languages?
  • You should already be familiar with the language or expect that you can learn it in a reasonable time (with regard to the time frame of your project).
  • What are your collaborators familiar with? Or those who might want to use your work?
  • Consider what is already available in the standard library and in other libraries (depending on your use case you might have to be careful about licences, although I think it’s usually not much of a problem in academic research). Anything that is already available is something that you don’t have to do and is likely to be faster and better tested than whatever you would produce.
  • What tooling is available for development? E.g. a good debugger helps a lot, especially if you’re running code not only on your PC but also on some embedded device and have to debug remotely.

If after considering these points you still have multiple language candidates, then you can choose the one you like best.

Give new languages a chance.

At first, any new language is going to be harder to use than what you are already familiar with. It takes some time to get to know the language-specific concepts, get familiar with what functionality is already offered by libraries, learn the language-specific coding conventions, learn how to use the documentation effectively etc.

This simply takes time. I switched over from mainly working in C++ to mainly working in Python a few years ago, and I know that it takes some getting used to. But when you are coming from another language, your view is skewed: you mainly notice the things you can't do easily that you could do before, and the new types of errors you encounter. You don't notice the things you can do better (or at all) in the new language unless you go looking for them.

Other people have the same problems. There might be ways to solve or mitigate them.

Look around a bit. For example, for Python you can use Type Hints to indicate which type(s) an input parameter / variable / return parameter is supposed to have. Python itself doesn't check if those make sense, but there are tools to do so.

Implementation is rarely the hard part.

In my experience, the most time consuming part about programming is not the implementation itself but deciding on what you implement. That is, how is your algorithm going to work? What are you optimizing for? Where does your data come from? What do you need to do to clean it? How can you construct representative datasets? How do you evaluate your algorithm?

That’s the hard part. Programming it is easy, even if you have to look up interfaces a bit more often than you're used to.

15

The success of your career will depend more on the results you obtain and their verifiability than on the specific set of tools you use, whether programming languages than otherwise.

However, using nonstandard tools will make replication, verification, and extension of your work more difficult for many users. It will make your papers harder to read and understand for some. There is value, of course, in independent verification of results, especially, perhaps, when they use different tools.

But maybe a better solution for yourself is to improve your Python skills. There are ways to use the language so that your concerns will be minimized. But less-than-skilled practices are a problem in any language. The potential error sets in C and Python are very different, but neither language makes errors impossible to "achieve". Up your game.

One issue is that Python requires a different mental model than C or C++. If your Python code is just misspelled-C code it will have issues. Python requires a higher level abstraction mentality than many earlier languages, which was the point of creating it.

2
  • 7
    +1 for "Python requires a higher level abstraction mentality than many earlier languages, which was the point of creating it." Feb 26 at 13:14
  • 5
    C++ is really something completely different from C. It is no longer just C with classes it used to be 25 years ago. The mental model of C and modern C++ is fundamentally different with template metaprogramming, traits, functional programming features and what not (I am not really a C++ programmer, but even I can see the huge difference). Scientific C++ libraries offer much higher level of abstraction compared to C and often comparable to Python. Feb 26 at 21:50
9

Well, yes, though maybe not for the reasons you think. Let me give a more, ahem, high level view than the current answers.

I don’t use technique X because I hate it.

This is a really dangerous mindset for a scientist, be it in academia or industry. Thinking like this will easily lead you into misjudging situations in terms of options and constraints. It will also isolate you from collaborators and peers who approach their tasks more practical minded and goal oriented.
None of this is good for you. Work on challenging your assumptions and it will make you a better scientist.

As a practical example, you mention types on parameters. Well, that alone means your thinking on this topic is almost 10 years outdated (almost 20 if you count the cutting edge). That’s not some hidden knowledge, that’s one internet search - provided that you are willing to look for it.
As a scientist, it’s really dangerous for your career to be in a mindset in which you aren’t willing not even to look, but to not even glance at what you could do.

5

On the one hand, as Buffy writes, what is important is your results, not your toolset.

On the other hand(s)...

  • As Buffy also writes, you will have a harder time communicating with others. There are already journals that put a premium on authors' submitting code along with their manuscript, and they may even try re-running your code. That works if the field has essentially converged on one language. Using something non-standard will close this possibility off to you.

  • In addition, this will make it hard on other people to collaborate with you. Co-authoring papers between LaTeX and MS Word users is hard enough; co-writing code between C++ and Python users is even harder.

  • Python by now has a huge ecosystem of user-generated packages for pretty much any use case you might imagine. Yes, C++ has also been around for a while... but I would assume that if you want to leverage someone else's tools, you will need to use their Python.

  • Since you want to stay in academia, at some point you will need to teach students. In principle, you may have some leeway what to do here. However, if 95% of the data science community uses Python (and another 4.9% uses R), then teaching your data science students C++ will likely have them feel like you are not adequately preparing them for the workplace. You will need to work in a "mainstream" language in your teaching at least.

  • If you leave academia, yes, there are places where you can use C++. But like it or not, again, most data science is done in Python. (Then again, if you have been doing C++, nobody will question your ability to learn Python.)

5
  • C++ has improved with and since C++11. It has become a much more convenient language. Certainly, the rest of the argument is fine, but no need to diss C++. Not that it needs protection, but I feel the lack of insight of a language closer to the machine memory model has substantially weakened the understanding of computation by students. It does not need to be C++, languages such as Rust or Pascal would also be fine. Feb 26 at 13:14
  • 1
    @CaptainEmacs: for the life of me, I can't tell where I am dissing C++. That was absolutely not my intention. Feb 26 at 13:16
  • dissing C++ - "then inflicting C++ on your students". I know it is meant to be humorous, but it does not sound flattering. I see where you come from, and can imagine that something like Rust may ultimately replace C++, but we are not there yet. Feb 26 at 13:19
  • 1
    @CaptainEmacs: I edited. Feb 26 at 13:46
  • Funny, as a numerical person, I remember numerical mathematics/scientific computation conferences were all about C++, some Fortran. I really could feel what the OP feels (myself using mostly Fortran) but with C++ instead of Python. And not such a long time ago. Feb 26 at 21:43
4

If you're dead set against Python and similar languages, it might make things a bit tougher for you in academia, especially in data science and ML, but it's not the end of the world. What matters most are your research and results. However, teamwork and sharing findings might get more complicated since most people there use Python. So, maybe consider giving Python another chance?

3

"Will it be a career risk for me if I avoid Python?"

As a data scientist? Yes. Undoubtedly.

Tools like Tensorflow and Pytorch offer huge advantages compared with C++, or even base Python. If you don't use these tools then you will work much more slowly and won't be able to access the work of peers who will almost certainly use these tools.

Python also gives you access to some great web and database tools, which enable you to load data and deploy your algorithms.

"I hate the Python language for many reasons, the primary of which is that it is dynamically typed."

The bits of python that you will use most often are not dynamically typed.

Python extensions such as numpy and tensorflow allow you to define multidimensional array objects but they also force you to select the datatype held in the array. Once the array is created you can't change the datatype, although you can still re-assign the variable name to a new object.

import numpy as np
my_array = np.arange(8, dtype=np.float)    # ndarray(0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0)
my_array[3:5] = 1                          # ndarray(0.0, 1.0, 2.0, 1.0, 1.0, 5.0, 6.0, 7.0, 8.0)
my_array[6] = False                        # ndarray(0.0, 1.0, 2.0, 1.0, 1.0, 5.0, 0.0, 7.0, 8.0)
other_array = my_array
other_array is my_array                    # True (i.e. the two variable names are pointing at the same memory location)
my_array = None                            # None
other_array is my_array                    # False
print(other_array)                         # ndarray(0.0, 1.0, 2.0, 1.0, 1.0, 5.0, 0.0, 7.0, 8.0)

Notice that my_array contains doubles, even after we assign integer or other exotic non-floating point values to it (assuming that numpy will accept an implicit conversion for the given datatype).

"Keeping track of its function parameters is a daunting task for me. I am unable to remember these parameters naturally."

This sounds like the real issue here. It can be tricky but here are some pointers that might help:

  • Try not to write functions with a large number of parameters
  • If you have such a function, consider breaking it down into smaller components, or capturing the parameters in a dictionary object (look up how to use the * and ** symbols to unpack a dictionary within a function call)
  • Choose better parameter names
  • Use type hinting
  • Keep an eye out for Mojo https://www.modular.com/max/mojo (under development, but could be very useful once it matures)
4
  • 2
    "The bits of python that you will use most often are not dynamically typed." That is false. All typing in Python is done at run time. Variables are untyped. Only values have type. Libraries and preprocessors might do things differently but you need to use those consistently. my_array = 42 would be legal at the end of your example. The fact that you originally assigned it to be an object that has control over its own state and provides conversions doesn't change the fact that my_array itself (as a variable) has no type at all. Only an object it references has type, hence behavior.
    – Buffy
    Feb 26 at 23:11
  • @Buffy it's false in some senses but true in others. "dynamically typed" vs "statically typed" isn't always a useful dichotomy and IMO it won't hurt to show the OP that there is a level of nuance present which may or may not appeal to them. Feb 26 at 23:20
  • 1
    You don't "overwrite" an object. You change a reference to a different object. It will hurt the OP to give them a poor thinking model of Python or any other language. I'm dropping the mic here as arguing in comments isn't appropriate, but I think you need to up your own game a bit. Much of the advice you give here is fine, but be careful about possibly misleading folks.
    – Buffy
    Feb 26 at 23:25
  • You're correct. I've made an edit to try to make it a bit more precise. Feb 26 at 23:43
1

My opinionated take:

Should I learn and use Python in my research, even if I dislike it?

I'm going to call this an XY situation1. In my opinion, the question should be instead:

Why don't I currently find Python likable and how I can I reverse this?

The Earth has sort-of converged on Python as a scripting language and wrapper for all that is good in software.

I use it to download YouTube videos and grab their transcript text, generate PowerPoint slides, format stuff, do simple math etc. in addition to all the heavy lifting in databases, numerical calculations, etc.

There is very little out there that can't be accessed via some Python wrapper or API. Even if all your hard work and excellent coding is in a compiled language like some flavor of C or FORTRAN, if you wrap it in at least a thin veneer of Python it is much easier to share with the rest of the world.

I think the real problem is that you have not yet had a positive exposure to it, either you haven't attended a good PyCon meeting or a local Python Users Group get-together, or just sat down with a Python enthusiast and been exposed to the wonders and power of this scripting language.

Should I learn and use Python in my research...

Yes!

...even if I dislike it?

You will almost certainly like it once you learn it in a positive way

Find the right way to get help and encouragement, and you'll find it so empowering you'll wonder why you previously thought you wouldn't like it.


1from FAQ see What is the XY problem?

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .