# which is more useful in the real world? Python or C++...

## which is more useful? Python or C++

• ### C++

Results are only viewable after voting.

#### Bill Sun

##### Member
C++ Student
I must say python is more pretty and young

#### Daniel Duffy

##### C++ author, trainer
Not all MSc students know C++, so to learn PDE/FDM Python is fine. For production, C++ is the only choice.
The two sweeps of the ADE scheme are:

        for i in range(1, len(self.u) - 1):
x = self.u[i - 1]
y = self.uold[i]
z = self.uold[i + 1]

self.u[i] = (self.up1[i][I](z - x) + self.up2[/I] y +  self.up3[i]*(x - y + z)) / self.up4[i]

for i in reversed(range(1, len(self.v) - 1)):
y = self.vold[i]
x = self.vold[i - 1]
z = self.v[i + 1]

self.v[i] = (self.down1[i] * (z - x) + self.down2[I]y + self.down3[i][/I](z - y + x)) / self.down4[i]

#### Daniel Duffy

##### C++ author, trainer
If history is anything to go on, at some stage we will encounter the same software maintenance problems with ML applications as with 99.99% of legacy code. The root cause is not the choice of language but the fact that these applications are created by non-programmers who are in all probability not familiar with software design (making blueprints before you jump into code). It is an accident waiting to happen..

Don't take my word for it; hear what Google has to say.

Good, forthright interview! Anyone who has read Brooks' "Mythical Man Month" will know that one of the biggest challenges in software projects is maintainability and eventually products become a big ball of mud. This is an ubiquitous problem since many years and it is caused by well-known problems such as bottom-up work practices, programming from the start blocks (no design) and not defining component interfaces up-front. It is one of the unfortunate OOP legacies. This issue is acknowledged and discussed following @41.30

Last edited:

#### quantsmodelsbottles

##### Active Member
are apples better than oranges?

#### Daniel Duffy

##### C++ author, trainer
are apples better than oranges?
Interesting (and kind of scary). Green or red?

Last edited:

#### Daniel Duffy

##### C++ author, trainer
People tend to compare languages based on many kinds of metrics, e.g. cute features, easy to use, functionality etc.

A possible bad scenario is Python code becoming unmaintainable because those writing the software (for example, applied mathematicians) have had no exposure to design principles of Design Patterns.

C++ v Python? the latter is (much) more difficult to maintain. And there's an associated price tag.

Corollary: discussions on software maintainability tend to fall on deaf ears.

Last edited:

#### David.Wan

##### Member
C++ Student
People tend to compare languages based on many kinds of metrics, e.g. cute features, easy to use, functionality etc.

A possible bad scenario is Python code becoming unmaintainable because those writing the software (for example, applied mathematicians) have had no exposure to design principles of Design Patterns.

C++ v Python? the latter is (much) more difficult to maintain. And there's an associated price tag.

Corollary: discussions on software maintainability tend to fall on deaf ears.
On the other hand, I have seen (many) professional quants who wrote memory issue codes in C++.. use const_cast in order to make things easier for themselves.. forgot to initialize variable in constructor.. no concept of modulization so very long body of function or even worse copy paste code everywhere.. assign auto_ptr which causes the object to be destroyed(luckily we have unique_ptr now in C++ 11...)

Then it sometimes makes me wonder that at least they will not make this mistake in a dumber language. Many quants I have worked with do not have the concept of “stability” coding. You would be lucky if they simply don’t write memory issue code, let alone all these strategy pattern type of stuff... in reality, if you fortunately meet one who can write scallable and stable code, he/she is a super star...

#### Daniel Duffy

##### C++ author, trainer
auto_ptr is deprecated..

#### Onegin

##### Active Member
C++ Student
@Daniel Duffy what can we do as quants to get on the path of righteousness, short of CS studies?

The problems you mention seem like problems because I think you are credible, but I can’t say I understand them.

How much of the theory do we need? Where is the line?

I don’t want to be part of the problem.

#### quantsmodelsbottles

##### Active Member
I minored in CS, didn’t learn any of that stuff. I think those are things you learn on the job.

#### Daniel Duffy

##### C++ author, trainer
I minored in CS, didn’t learn any of that stuff. I think those are things you learn on the job.
This is quite anecdotal.

//
CS education tends to focus on theoretical things (can be useful) and less on software engineering/programming.
CS does not mean you can create maintainable software.

And you may or may not learn good software practice on the job. It depends.

Last edited:

#### Daniel Duffy

##### C++ author, trainer
@Daniel Duffy what can we do as quants to get on the path of righteousness, short of CS studies?

The problems you mention seem like problems because I think you are credible, but I can’t say I understand them.

How much of the theory do we need? Where is the line?

I don’t want to be part of the problem.
There are many scenarios. One is that the originator of undocumented and unstructured code has moved on and someone has to maintain it.

Anonymous but real quote from the trenches...

"The usual suspect: obviously clever applied mathematician, but otherwise completely untrained as software developer “writes a script to do thing X”. As soon as this newly-born wonder has passed some tests (meaning that the program does not crash anymore) and taken into production, previously observed insignificant symptoms will be escalating over time into serious signs of deadly plague (runtime issues, maintainability issues, you name it).

People, who are usually so proudly describing themselves as “Applied Mathematician” are almost surely building some type of time bombs with their scripts, because they (usually, but there are exceptions) have no interest on software design issues on any level."

I also have a zillion examples from my own past.

Last edited:

#### Daniel Duffy

##### C++ author, trainer
I like this one

“A Big Ball of Mud is a haphazardly structured, sprawling, sloppy, duct-tape-and-baling-wire, spaghetti-code jungle. These systems show unmistakable signs of unregulated growth, and repeated, expedient repair. Information is shared promiscuously among distant elements of the system, often to the point where nearly all the important information becomes global or duplicated. The overall structure of the system may never have been well defined. If it was, it may have eroded beyond recognition. Programmers with a shred of architectural sensibility shun these quagmires. Only those who are unconcerned about architecture, and, perhaps, are comfortable with the inertia of the day-to-day chore of patching the holes in these failing dikes, are content to work on such systems.”

#### David.Wan

##### Member
C++ Student
There are many scenarios. One is that the originator of undocumented and unstructured code has moved on and someone has to maintain it.

Anonymous but real quote from the trenches...

"The usual suspect: obviously clever applied mathematician, but otherwise completely untrained as software developer “writes a script to do thing X”. As soon as this newly-born wonder has passed some tests (meaning that the program does not crash anymore) and taken into production, previously observed insignificant symptoms will be escalating over time into serious signs of deadly plague (runtime issues, maintainability issues, you name it).

People, who are usually so proudly describing themselves as “Applied Mathematician” are almost surely building some type of time bombs with their scripts, because they (usually, but there are exceptions) have no interest on software design issues on any level."

I also have a zillion examples from my own past.
LMAO, your comment just made my day... I have seen this everyday at my work.. even worse, there are idiots failing the regression tests but since such model feature is not used in production, they would sneakily remove the test case.

Speaking of which, this works both way when you have a pure software engineer working in the model library but completely lack of understanding of the theory.. this folks simply blindly re-uses existing code and able to spit out some numbers and then that's it...

A good Quant should be all around (yet I know this is unreasonable sometimes) but it is true.. Programming + Math are required. Lacking either one won't work...

P.S.: that is why you see so many fake quants nowadays...

Last edited:

#### ExSan

##### Active Member
I minored in CS, didn’t learn any of that stuff. I think those are things you learn on the job.
Among other courses Compilers I and II would had helped you a lot

#### Daniel Duffy

##### C++ author, trainer
The following has to be said is the arrogance of some applied mathematicians who think software design is easy (FYI I am a mathematician, 1st program written in 1971).

Analogy: I know judokas who are USELESS in karate and ju-jutsu.

“A little learning is a dangerous thing.
Drink deep, or taste not the Pierian Spring;
There shallow draughts intoxicate the brain,
and drinking largely sobers us again.”
― Alexander Pope, An Essay on Criticism

And I am being deadly serious!

#### Shiqin Tang

##### Member
C++ Student
How about Julia, the future king of machine learning? I didn't see no one mention it.

#### Daniel Duffy

##### C++ author, trainer
How about Julia, the future king of machine learning? I didn't see no one mention it.
It's just another language.
Other recent languages on the catwalk are Swift, Go, Rust, etc. etc. They rise and fall.

BTW, Julia is #44 in the TIOBE index.

The essential difficulty is avoiding big balls of software mud. Quiche languages won't help in this regard IMHO.

The management question, therefore, is not whether to build a pilot system and throw it away. You will do that. […] Hence plan to throw one away; you will, anyhow.
Fred Brooks

Last edited:

#### Daniel Duffy

##### C++ author, trainer
On a somewhat related comparison, I ported C++ code to price financial derivatives (options) to Python to get a feeling for relative run-time performance., This is essentially a one-step algorithm in a double nested 'for' loop and random number generators are used in both cases (Mersenne Twister 19937)
Conclusion C++ is 60 times faster!

Just looking at the random number generator part, using Numba improves performance appreciably (Python is 1 1/2 times slower). In more complicated code it is not obvious how to use numba. In this case 'pure' Python would not be suitable for production purposes but it would be useful for prototyping.