I have an anecdote relating to this subject...
At a previous job, I was involved in maintaining a big inventory management, CRM, order processing thing. It was mostly written in PHP with a web interface, with a PostgreSQL back-end, and also interacted with some legacy AS/400 systems. It was pretty terrible, but typical for the kind of code you see in the wild, written by incompetent programmers for an ossified, disorganized company.
There were certain reports generated by the system that would sometimes take hours to complete. Some very clever programmer in the distant past thought to themselves "Ah, well, this is written in PHP, and everyone knows C is much faster, so I'll rewrite this part in C and bolt it on." Sadly it didn't get any faster at all, and we were all left with some really crappy C code to maintain in addition to everything else.
The problem wasn't the choice of language. The problem was that the programmers didn't understand SQL at all, and SQL joins and subqueries specifically, and didn't know how to design a database schema that makes any kind of sense. Instead of using joins, they issued thousands of queries inside nested loops. It was something like:
Code: Select all
query list of customers
for each customer {
query list of orders
for each order {
query list of parts in order
for each part {
query part information
if order was in the last week and customer is a distributor {
total_distributor_sales += whatever
}
}
}
}
Once we rewrote it to just issue one query with joins, it took like 100ms to run instead of an hour, with 1/5 the number of lines of code.