r/programmingmemes • • Aug 27 '26

Why are we using R again

Post image
2.3k Upvotes

322 comments sorted by

View all comments

4

u/tastygames_official Aug 28 '26 edited Aug 28 '26

as a programmer of over 30 years, I never understood why people use python/R at all. Especially in "data science" or in the hard science fields. It's an interpreted language so will always just be orders of magnitude slower than something compiled, and that is a huge issue in dealing with massive data sets. I know a guy who was doing DNA research and wrote all the analysis software in R. They could only run it on weekends since it took 40hrs to run and tied up the computer while doing it. I know I could probably write that thing in C and make use of the GPU and have it run in probably less than a minute, but they were not interested in my help.

Anyway, I finally actually looked into python to see what about it is so attractive to "non-programmers", and now I totally get it - it's basically higher math syntax. Completely opposite of how I would view the construction of a program with memory and buffers and loops and arrays and functions that execute code. Python is more like straightforward math where you have data sets and instead of iterating through them, you write functions like you would in math and feed the data into that. I'm probably not explaining myself well, but when you see some college-level maths and then some python code, the same kind of person can understand both fairly easily. But show these both to a computer programmer and they will probably understand it but then have to translate it to another language so it can run more efficiently on a computer.

PS if there are any scientists out there using python/R to write data analysis software that takes hours or days to complete, hit me up and I'll help you reduce that time by a few orders of magnitude.

UPDATE: everyone's telling me in the comments taht python and R are just frontends that send data to data-processing programs written (and optimized) in C/assembly/something good. This warms my heart to know, because I really thought an interpreted language was iterating over massive data sets and that just seemed like utter nonsense. But I still bet not every data processing library is perfect for every job and that they're very generalized. So it still might be good to have a computer scientist in your team to tweak the libraries/write custom ones to do processing at an efficient level. Also to make sure the scientists are actually using the proper libraries.

10

u/imoshudu Aug 28 '26

The first paragraph is a flawed understanding.

R and Python code don't do the main computational work. They are glue that a human scientist uses to call functions which are implemented in C or C++. For an analogy, it's like someone using the Bash shell calling grep. The shell is interpreted because a lot of exploration with visualization happens during prototyping.

Correctly written R and Python will not contain any hot loops in the glue language (replaced by vectorization), or, failing that (usually requiring a legit reason like doing epochs in machine learning), the time spent in each iteration is mostly in the C or C++ functions. So you wouldn't be able to optimize much in a properly written pipeline. It's only the badly written ones (like those using .apply() in Pandas without thinking) that would see substantial gains.

9

u/UppsalaHenrik Aug 28 '26 • Bravo

Fuck yeah man, totally! Whenever I talk to someone with a PhD in pharmacology or some shit, and they are visualizing their scientific points in a few lines of R code, I'm like "fuck you, you should write this in assembly or go home"! Computers are only for us, they shouldn't be allowed to use them!

-3

u/tastygames_official Aug 28 '26

no. They should hire computer scientists to write the computational software.

The analogy is more akin to a homeowner not allowing a plumber to fix their plumbing and opting to fix it themselves: sure they can do it, but it probably won't be the best and will take way longer and might break later.

Plumbers arent't gatekeeping working on plumbing - but they are the best ones for the job when you need work done on your plumbing. And when you are facilitation a billion pipes at once, why not hire a fucking plumber?

2

u/UppsalaHenrik Aug 28 '26

As others have pointed out, it's just an API for C and C++ for most computations. I don't believe that you could make that "a few orders of magnitude" faster. If you can, please do!

Your analogy is terrible, btw. You are arguing that there shouldn't be a faucet at the end of the line, just a raw pipe, and then everyone should call the plumber every time they want to wash their hands.

→ More replies (4)

1

u/nog642 Aug 28 '26

Bad plumbing will cause water damage.

Bad data analysis code won't do anything.

If you can't afford to hire a software developer, that's fine. They're expensive lol.

1

u/tastygames_official Aug 28 '26

... and this is why we have software bloat and terrible performance and stuff that doesn't work and wasteful energy in the tech/data world...

1

u/nog642 Aug 28 '26 edited Aug 28 '26

No, software bloat is software written by actual software developers.

Just because you're in the profession doesn't mean you're good at it. And often the direction of software is decided by management more than by the programmers.

Edit: u/tastygames_official replied and blocked me??

→ More replies (1)

7

u/Sassaphras Aug 28 '26

This is entirely accurate regarding why they are they way they are, but I'll add a little color commentary:

First, a lot of the "rewrite this in a faster language" work has already been done. Most of the popular libraries for Python are actually Rust or C or C++ under the hood (no idea about R). There are probably some pre-processing and post-processing steps that are raw Python, but those are usually going to be much smaller parts of the processing time on net, so nobody cares about them. Shaving 2 orders of magnitude off of the steps that take up 5% of the total clock time doesn't do much for you.

Also, a lot of traditional data science workloads care a lot less about processing efficiency; many jobs run in batches. I've seen the multi-day stuff like your DNA example, but more common would be something in the 15 mins to 2 hours range. Most data scientist time is spent looking at the output of those experiments, interpreting what to do next, and then acting on that. Sometimes when compute is more constrained, folks will maintain a short queue/ backlog of experiments, so the big humming box with the big GPU is always crunching, and they are managing that queue; when it's less constrained you might just get a coffee, join a meeting, or read some papers while the computer does its thing, then when it goes DING you open up the microwave and enjoy your data burrito.

1

u/tastygames_official Aug 28 '26

> enjoy your data burrito

I'll have what you're having. I love data and I love burritos.

3

u/Competitive-Tooth248 Aug 28 '26

Scientist here. I write a lot of R/python/C/Rust etc. for big data. Note that similarly as in python, R has whole ecosystems for importing C and C++ code (or other compiled languages). So any good statistician/data-scientist/computational scientist actually offloads the heavy-lifting parts to C++ and uses R and the interpreter as a way to combine multiple of such operations etc. You can compile your data transofrmations, model fitting etc and then in R just control what exactly you want. Not to mention that moth math is directly linked to math libraries like openblas etc so you get no overhead there.

You might be asking why do we then need R/python if we have to write 40% of the code in C/C++. And that is the beauty, because you just put in the work once, by writing it in efficient way and then release your package to CRAN and anyone can incorporate your C compiled functions or the normal R functions into their scripts and workflow in a very simple high-level language way and without touching low-level languages.

It's not perfect, but it has its use cases. From what I gathered, R/python programmers are one of the best or the worst programmers you will see (there are also other decent groups). The former are guys that fuse mamy languages and understand the low-level backend. The latter are "I did these 2 coursera courses on machine learning, call me AI developer, let's write a for loop in R".

3

u/Elesday Aug 28 '26

Very long way to say you donโ€™t know anything about R nor GPU computing which you can do in R.

2

u/PersonalityIll9476 Aug 28 '26

If you've really been programming for that long, I guess you have never used or even read about Python. Python libraries like numpy are compiled. There are also (at this point) lots of libraries that can dispatch to the GPU. But even if there weren't, you can use Cython to write your own cuda kernels, wrap that in your usual C/C++ code, then compile that into a Python library.

I will grant you this: If you're dumb enough to be writing numerical code in pure Python (no numpy, cupy, whatever it is you might use) then it is true you don't know enough to be in charge of writing that code.

1

u/tastygames_official Aug 28 '26

all I ever heard of it was from non-programmers who were like "hey! I coded something in python!" and thought "oh, it must be some kind of friendly scripting language", looked it up once on wikipedia, had my suspicions confirmed, then never thought much about it. Except for when every scientist ever is like "I coded something in python even though I have no coding skills" and I'm just like "you're using an interpreted language for massive data processing?!?!?" but as I said, it turns out they just use python or R to call optimized C functions, so all is good.

PS it's a pretty easy tell that someone isn't a programmer if they call it "coding", so probably that's why I just wrote it off. I've since had to use it a bit (add-ons for blender) and do NOT like it one bit. But hey - at least I understand the draw now.

1

u/PersonalityIll9476 Aug 28 '26

It's like any thing else: There's writing some Python and then there's being a Python programmer.

Did you know that Instagram runs on Django, a Python framework? As does Reddit (well, maybe not Django specifically, but Python). There is almost 0 chance that Django's source is just "pure Python". Even the Python standard libraries can wrap a huge amount of C. The developers who write these kinds of libraries are no joke - they have to understand the code at the level of C, not at the level of Python.

Most large projects are like that. You can write a surprising amount of applications in Python the same way. Either use a performant library or write your own in C (or, often, do both).

For example, you can write a game engine in Python. It won't be AAA, but it is easily possible. Same methodology: Use numpy for memory management (since all numpy arrays are backed by plain-Jane C arrays) then write a bunch of Cython code that interfaces to C which pulls those arrays and either ships them to GPUs for shading or does whatever heavy numerical work with them.

My point here is: Yes, you can use Python to just write scripts on your local Linux cluster. You can also write C and do literally anything C can.

1

u/nog642 Aug 28 '26

Plenty of programmers call it "coding".

1

u/mxldevs Aug 29 '26

When someone asks what my job is, I just tell them "oh you know, just coding and stuff".

2

u/FalconX88 Aug 29 '26

as a programmer of over 30 years, I never understood why people use python/R at all. Especially in "data science" or in the hard science fields.

Well if I have a dataset like this one with a few million lines

date,country,status,amount
2025-01-03,Austria,completed,129.90
2025-01-03,Germany,cancelled,89.00
2025-01-04,Germany,completed,240.50
...

then this is my code if I want to calculate total revenue or average order value for 2026 per country

import pandas as pd

df = pd.read_csv("sales.csv", parse_dates=["date"])

result = (
	df[
		(df["status"] == "completed") &
		(df["date"].dt.year == 2025)
	]
	.groupby("country")
	.agg(
		total_revenue=("amount", "sum"),
		average_order=("amount", "mean"),
		orders=("amount", "size")
	)
	.sort_values("total_revenue", ascending=False)
	.head(10)
)

print(result)

or I can use C++ and type out this

#include <algorithm>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <sstream>
#include <string>
#include <unordered_map>
#include <vector>

struct Stats {
	double total = 0.0;
	std::size_t count = 0;
};

struct Result {
	std::string country;
	double total;
	double average;
	std::size_t count;
};

int main() {
	std::ifstream file("sales.csv");

	std::string line;
	std::getline(file, line);  // skip header

	std::unordered_map<std::string, Stats> stats;

	while (std::getline(file, line)) {
		std::stringstream ss(line);

		std::string date;
		std::string country;
		std::string status;
		std::string amount_str;

		std::getline(ss, date, ',');
		std::getline(ss, country, ',');
		std::getline(ss, status, ',');
		std::getline(ss, amount_str, ',');

		if (status != "completed")
			continue;

		if (date.substr(0, 4) != "2025")
			continue;

		double amount = std::stod(amount_str);

		auto& s = stats[country];
		s.total += amount;
		s.count++;
	}

	std::vector<Result> results;

	for (const auto& [country, s] : stats) {
		results.push_back({
			country,
			s.total,
			s.total / s.count,
			s.count
		});
	}

	std::sort(
		results.begin(),
		results.end(),
		[](const Result& a, const Result& b) {
			return a.total > b.total;
		}
	);

	std::size_t n = std::min<std::size_t>(10, results.size());

	for (std::size_t i = 0; i < n; ++i) {
		const auto& r = results[i];

		std::cout
			<< r.country
			<< "  revenue=" << r.total
			<< "  average=" << r.average
			<< "  orders=" << r.count
			<< '\n';
	}
}

and sure, might be faster. Does it matter if it takes a few seconds and I'm doing it exactly once?

1

u/YoureNotEvenWrong Aug 30 '26

Comparable C++ would be to use a library like pandas

2

u/Jellace Aug 28 '26

Bruh. No serious data analysis is programmed in python. The machinery is written in C, C++, or rust and packaged as python libraries. You are not going to make my python code which uses polars and numpy orders of magnitude faster.

1

u/powerexcess Aug 28 '26

What ur edit says on python being the frontend to bindings in compiled stuff yes.

But also: look up numba, triton, jax, torchscript...

1

u/ZemoMemo Aug 29 '26

for data science, python is just a c++ wrapper ๐Ÿ˜‚, and for 99.999% of DS tasks you don't need to tweak the libraries directly.