7

I know python is not suitable for things like microcontrolers, make drivers etc, but besides that, you can do everything using python, companys get stuck with speed optimizations for real hard time system but does forget other factors which one you can just upgrade your hardware for speed proposes in order to get your python program fit in it, if you think how much cust can the company have to maintain a system written in C, the comparison is like that: for example: 10 programmers to mantain a system written in c and just one programmer to mantain a system written in python, with python you can buy some better hardware to fit your python program, I think that low level languages tend to get more cost, since programmers aren't so cheaply than a hardware upgrade, then, this is my point, why should a system be written in c instead of python?

Animesh
  • 165
  • 1
  • 12
killown
  • 1,466
  • 3
  • 15
  • 18
  • 47
    Is that all one sentence? – TheLQ Oct 19 '10 at 01:20
  • 15
    @TheLQ: I would edit it, but it's a marvel, isn't it? – Jon Purdy Oct 19 '10 at 02:02
  • 2
    Do you have any actual evidence for a 10:1 maintenance cost ratio? – David Thornley Oct 19 '10 at 15:28
  • 8
    Why Python instead of something more powerful? –  Oct 23 '10 at 12:05
  • 1
    Python does not do multi-threading well, and hence it sucks. The real question is why do we not use Clojure for everything? – Job Dec 05 '10 at 16:03
  • What is a 'make driver'? – Dark Templar Oct 09 '11 at 18:00
  • [Yup! Python is great.](http://i.stack.imgur.com/6aIWc.png) [But for some things you still need](http://i.stack.imgur.com/SzFny.jpg) – Rook Oct 23 '10 at 12:19
  • One answer: **A Compiler!** Statically typed, compiled languages are essential for large systems. The compiler is **the most powerful debugger** in every programmer's toolkit. (Although C is not the best choice - there are other compiled languages that are far better) – Vector Nov 19 '13 at 02:35
  • The thing you are getting REALLY wrong is the supposition that programmers cost more than hardware upgrades. It can well be true for small enterprisey programs, but is most often wrong. What is the programmer cost for a web service that will be used for years? – Shautieh Sep 12 '14 at 11:01
  • 1
    That's because a main characteristic of a high-level language is that it has a fanatic community that is usually blind for everyone else's needs. – NaN Aug 26 '15 at 16:31

6 Answers6

24

The main reason is because the software was already written in C (or C++ or whatever) before Python became a legitimate choice.

If it's a question of rewriting your million lines of C code into Python or continuing with the C code, then the choice is clear. If you spend 12 month rewriting the code in Python, then that's 12 months where you're not adding new features and you'll basically spend 12 months getting back to exactly where you were.

Not to mention that fact that you'll probably have missed all those corner-case bugs that had been fixed over the years in the C version, but not really called out in the code so when your Python dev comes along to port it and says "why does the code do this? That seems wierd... I'll just do it this other way" he's actually forgetting about that customer from 6 years ago who lost 12 months worth of payroll because of this obscure bug in their RAID controller that was worked around with just that specific piece of code.

It's basically the same answer people get when they ask "Why doesn't Microsoft rewrite Windows or Office or (insert-product-here) in .NET? I thought .NET was the poster-child for all Microsoft development these days?"

Now, when it comes to developing new products, then Python (and all the other possible choices) become a more viable option. But you've still to weigh the benefit of going with Python (or whatever) over C or C++, particularly when your new product may be interfacing with lots of existing code that you've already got written in C or C++.

Dean Harding
  • 19,871
  • 3
  • 51
  • 70
  • 1
    in case of make a new software, what do you choice for? c or python? – killown Oct 18 '10 at 23:40
  • 3
    For new software, your choices are pretty much limitless (C, C++, C#, Java, Python, PHP, Ruby, etc etc) whatever makes the most sense for the particular project – Dean Harding Oct 18 '10 at 23:42
  • 2
    Obligatory Joel on Software link: http://www.joelonsoftware.com/articles/fog0000000069.html – Tim Goodman Oct 19 '10 at 03:35
  • 5
    "If it's a question of rewriting your million lines of C code into Python or continuing with the C code, then the choice is clear." Not really; if you can (for example) replace 1 000 000 lines of C with 5 000 lines of Python in a few months (and can afford the performance hit + few months), there's a good argument that doing so will increase your speed in the long run. 5ksloc is much easier to maintain, optimize, develop against and debug (and is less likely to be concealing bugs) than 1 million sloc. Now if the choice was 1 000 000 of C vs 900 000 of Python, that's certainly not worth it. – Inaimathi Oct 23 '10 at 15:05
  • @Inaimathi : Is there really a case where 1 000 000 lines of C can be translated to 5 000 lines of Python ? – marco-fiset Nov 24 '11 at 16:58
  • @marcof - As an illustrative example, I refer you to the first ~35 seconds of [this video](http://www.youtube.com/watch?v=uKfKtXYLG78). Joking aside, I don't know if you could compress 1 000 000 lines of idiomatic C down to 5k lines of idiomatic python, but my point was that the choice is not as simple as `if plan.scan /rewrit(e|ing)/ false end`; there is a benefit conferred by rewriting in a more expressive, less verbose language with the obvious performance cost. If you can afford it, it *might* be a good idea. – Inaimathi Nov 25 '11 at 02:22
  • 6
    It's not just a matter of writing a few thousand lines of Python. You first need to *understand* all 1M lines of C code before you can begin. You need to understand why each line does what it does (for example, does it fix some obscure bug that everybody's forgotten about? Or is it just some vestigial bit of code from some refactoring that was done 15 years ago?) Writing a few thousand lines of Python can be done relatively quickly. But understanding 1,000,000 lines of C code *in order to be able to write those thousand lines of Python* is much more work. – Dean Harding Nov 26 '11 at 00:54
  • However I do agree that sometimes it is worthwhile to just drop what you have and start anew. But the reason shouldn't just be because some new and "better" language is available. You need to do it because there's an actual tangible *benefit*, and that you'll come out of it again with something that is more valuable than what you went in with, and that's also more valuable than what you could have achieved in the same time with the original code base (i.e. the opportunity cost). – Dean Harding Nov 26 '11 at 00:56
  • 1
    You shouldn't randomly rewrite code that you plan to make no further changes to (that's a waste of effort no matter what you're rewriting to) but I'm not sure how wide the gulf is between "understanding a million lines of C for the purposes of adding features/making significant changes" and "understanding a million lines of C for the purposes of rewriting it in something else". Having that much code that your team doesn't understand already sounds like quite the liability to me. – Inaimathi Nov 27 '11 at 18:42
  • It depends on what your team like most and is most fluent in. In a friend's company, they had to rewrite all their C# code (written by employees who wanted to play with c# and then left the company) in C++, because C++ is simply their preferred language. – Shautieh Sep 12 '14 at 11:05
9

Because even when you're not writing "low-level applications" such as device drivers, the need for low-level code tends to show up in all sorts of places, especially for performance optimizations in computation-intensive parts of your app. This is common enough even in apps written in C and other static, fully-compiled languages, and it only gets worse when you start throwing inherently slow "high-level" language features such as dynamic typing and managed pointers into the equation.

When you have a language that abstracts away all the low-level details, such as Python, you are not able to get down to the level required to fix problems like this. That's why you tend to see the pattern of writing the core code in a compiled language, and then implementing lightweight business logic in a scripting language that runs on top of the core code, increasing in popularity quite a bit lately.

Mason Wheeler
  • 82,151
  • 24
  • 234
  • 309
  • 4
    Another solution for the same problem is writing your system quickly in a higher level language, then using a C FFI to replace those pieces that don't profile well. To be fair, I don't have experience doing this, but there doesn't seem to be an a priori argument that writing things in C first, then extending it in a more flexible language is the clear winner. – Inaimathi Oct 23 '10 at 15:13
7

Well I understood your question as "Why continue to write things in C/C++ when better alternatives are present." Not let's rewrite everything just because we have a better hammer. And I agree with you in theory. Why write new things in C or ASM anymore because it turns out there are vastly more problems that work better for "high-level" languages than not.

I think about a story that James Gosling recalled about the Java team. They were looking at huge sections of code in the VM that was originally written in C because they thought it was faster. As time went on and they had to improve it, maintain it, and add new features. The team began to wonder why not move it to Java. They did and it turned out to be just as performant, simpler, and easier to modify. I do think new development should not be done in C/C++, except for those exceptions noted, but what makes our industry continue to grow is the platform change. We haven't really answered any new questions about computer science since the 70s, but we continue to grow in amazing directions. That's largely because every 10 years or so we create new platforms where we have to re-implement everything over there opening up opportunities to transition from previous languages to new ones. That's the secret to our industries success.

Here's a simple wrap up from 1980-2010: Unix C->Windows C++->Web Java/Javascript/Python/Ruby->mobile Objective C/Java).

chubbsondubs
  • 664
  • 3
  • 6
7

Because if the "system" is a scientific library or a go playing program it might require top performances, that's why. If you buy hardware that's 10 times faster, the low level implementation will still perform better.

And then there's a quite philosophic reason, in my opinion: we have to keep in touch with the lowest level of our machines. Losing the knowledge of basic instruments like the C language would be like covering every inch of the earth with cement and build a perfectly working "system" upon it, forgetting about what was down there once that gave us birth and condemning the human race to eternal ignorance.

Kernighan and Ritchie would be very upset about it.

Lorenzo Stella
  • 259
  • 1
  • 4
4

Some observations:

  • The huge trend in computing is mobile, which from several aspects is not far from microcontroller and embedded system development. Python is not yet the dedicated language for iOS, Android or Windows Phone 7.

  • In desktop computing, getting faster hardware is more and more difficult: CPU speed is stuck aroud 3GHz and getting all the power of multiple cores is far from easy. Low level languages have an advantage over Python here.

  • About maintainability, the 10:1 ratio may be true with just-graduated people who have never been exposed to C but know Python and Ruby and all other new languages. For the majority of senior developers, the ratio doesn't favour Python.

  • Some years ago, everything could be made in Java and be portable at the same time. Some years before, it was Perl. Clearly the actual winners these days are C, C++, C# and Objective-C.

mouviciel
  • 15,473
  • 1
  • 37
  • 64
  • 4
    "CPU speed is stuck aroud 3GHz and getting all the power of multiple cores is far from easy." Isn't this pretty much the explicit goal of higher level languages like Erlang and Haskell? Erlang through a one-character "new process" operator, and Haskell with purely functional (and therefore theoretically fully parallelizable) programming? +1 for the mobile computing point, that seems to be the first well-reasoned argument I read here. – Inaimathi Oct 23 '10 at 15:20
  • @Inaimathi: Why's it that fully-functional programming languages are easily parallelizable? – Dark Templar Oct 09 '11 at 18:20
  • @mouviciel: How come you say that C, C++, C# and Objective-C are more portable these days than JAVA and Perl? O_O – Dark Templar Oct 09 '11 at 18:23
  • 2
    @Dark Templar - Because the components of a purely functional program have no dependency on external state and have no assumptions about what order they will run in. This makes it easier (though not easy) to reason about how to efficiently break such a program up across different processes. Have a [Haskell-related link in which Simon Peyton Jones explains his approach in-depth](http://www.youtube.com/watch?v=NWSZ4c9yqW8). – Inaimathi Oct 11 '11 at 00:26
-1

There are some systems that link in C directly. Sure you can proxy your function calls and embed an interpreter, but I can do that with nearly any language.

Jé Queue
  • 3,937
  • 2
  • 29
  • 37