3 ms·
I do python where your question applies too. It is significantly quicker to write code in a higher level language, since the primitives and libraries do more p
by rogerbinns 10y ago
I do python where your question applies too.
It is significantly quicker to write code in a higher level language, since the primitives and libraries do more per line of code. The cost is that it doesn't run as fast. But consider these two scenarios:
1 It takes 2 hours to write the code, and 1 hour for it to run.
2 It takes 2 days to write the code, and 1 minute for it to run
Note that "write the code" includes the actual writing, as well as debugging, testing etc. The first scenario is the most immediately productive. But the more you have to run the code, the more the second scenario applies.
Which is why you combine the approaches. Write the parts that aren't performance sensitive quickly in your high level language, and take longer on the performance parts in C. That works better than exclusively approach 1 or 2.
- labrador 10y agoThanks, I think you make a good case for using a language like Lua or Python with an excellent C interface. In some sense, writing everything in C could be a case of premature optimization.
- rogerbinns 10y agoAnother benefit of Lua/Python is that it is considerably easier to write testing and debugging versus C. They support introspection and similar techniques. A very typical example is something I did a while back. I wrote the processing in Python first. The core was 10 lines of code and took about 5 minutes to run on a unit of data. It took about an hour to write, and was correct. It then took two days to rewrite in C and was 400 lines of code, executing in a second or so. Much of the time was finding and fixing minor bugs. But having the "correct" Python code made it very easy to feed the same test data to both implementations and verify the output. Writing test code in C would have taken even longer than just the algorithm!