C vs Python

Pages: 12
May 4, 2012 at 12:06am
http://www.daniweb.com/community-center/geeks-lounge/threads/383422/what-would-win-in-a-fight-c-or-c

cwarn23 wrote:
I vote for C because Python was written in C there for is limited to C's capabilities and is there by more recourse hungry than C as it another level of compilation of computer interpretation for reading the binary sequence. Things were sooo much simpler with punch cards.


First, C has no capabilities it is limited to. It is Turing complete. The first Python compiler was probably written in C, but the C was then compiled into the machine's native code, so technically, it was run in the machine's native code, not C. Probably a mix-up about Python being a superset of C.

Anyone agree? Any cons at all Python has that C doesn't? (More keywords, so your variable names are more limited.)
Last edited on May 4, 2012 at 12:10am
May 4, 2012 at 3:33am
closed account (oN3AqMoL)
I think Python is better. C is actually when tested out SLOWER than Python and Python does have new functions and can do stuff that C cant.

I don't want to start a firewar or anything, but STRONGLY sugest you move to Python. It is the standard language for gaming and regular programming, and if you want a job as a programmer, you are DEFINITELY going to have to learn it.
Thanks for listening
-dean:)
Last edited on May 4, 2012 at 3:35am
May 4, 2012 at 1:29pm
Well, yea. I was, frankly, getting mad at the person who voted for C, and I couldn't find any good arguments they raised. "C Hacker Syndrome," maybe. :)
May 4, 2012 at 1:37pm
As pointed out in the thread- there are situations in which C is better. But you're right that that particular argument was kind of silly.

Although:

First, C has no capabilities it is limited to. It is Turing complete.


That IS a limitation.
Last edited on May 4, 2012 at 1:53pm
May 4, 2012 at 2:14pm
Just to be completely sure we're on the same page here, how is being Turing Complete a limitation?

And yes, I have heard there is the occasional case where C is better. One would think Python is strictly better than C, due to being an (almost) superset of C, but there was something about some areas where a good Python compiler doesn't exist yet, but a good C one does.

James Kanze wrote:
Among the things that you can do in C, but not in Python, are:

-- not declare external functions, then call them with the
wrong number or type of arguments,

-- assign a void* to a typed pointer, regardless of type, with
no explicit conversion to warn you that something extremely
dangerous is going on.


(from http://www.velocityreviews.com/forums/t641348-is-c-only-better-c.html )

I laughed.

I'd also argue that C and Objective-C being (pretty much) supersets of C (I thought D was, too, at one point, but I probably got that mixed up with Objective-C) makes comparing them with C the only valid comparison without any sort of context. (Technically, no, they're not strict supersets of C, but they're pretty darn close.)
Last edited on May 4, 2012 at 4:22pm
May 4, 2012 at 3:58pm

-- not declare external functions, then call them with the
wrong number or type of arguments,
-- assign a void* to a typed pointer, regardless of type, with
no explicit conversion to warn you that something extremely
dangerous is going on.


I'm pretty sure that you can't do that in C99 nor C1x, and even before those any decent compiler would've given you a warning (with the option to treat it as an error).

And of course Turing-completeness isn't a limitation per se, but in the case of Python we have Turing-equivalence which is.

Oh, and if you're writing C code you're writing C code, independent of whether you're compiling with a C, Obj-C or a Python compiler. Just saying.
Last edited on May 4, 2012 at 4:06pm
May 4, 2012 at 4:08pm
c and Python are designed for different purpose

in strictly critical real time embeded system development , c is always better than Python;

May 4, 2012 at 6:42pm
lukecian wrote:
c and Python are designed for different purpose


True ... but with few exceptions, C code is valid Python code, and does the same thing.

lukecian wrote:
in strictly critical real time embeded system development , c is always better than Python;


Just to be sure, do you mean runtime or time that it takes to develop? For how long a program takes to run, a lot more effort has gone into Python, so I'd claim that Python is faster. For development time, again, C code is valid Python code, and I find Python much simpler, at the cost of having more keywords and such.
May 4, 2012 at 7:06pm
In the end, programs run on machines. Most of the time with a (modified) harvard architecture that caches data and instruction access. To get full speed, you need to avoid cache misses as much as you can. And once you do that, your code ends up looking like C no matter what language you write it in (well, and C code starts looking like assembly).
Jun 23, 2012 at 11:04pm

lukecian wrote:

in strictly critical real time embeded system development , c is always better than Python;


Nonsense. Incidentally our company does embedded programming in Python and personally I can't think of _ANY_ reasons why C should be better suited for this purpose than Python, the only exception being if there isn't a decent Python compiler available on the platform you're coding for.

Jun 24, 2012 at 3:12am
Well to be silly, if C and Python were actual people and fought each other in a battle Python would win. Python has the abilities of C in it and then augmented enhancements (the Python features). So Python would expect everything C could do and use the new abilities to destroy C.

More on topic, it really doesn't matter as you can't really compare any language to another language for one fact. Every language was designed for a specific reason or purpose which makes them all different even if they pull their syntax behaviour from another language.
Jun 24, 2012 at 6:38am
closed account (o1vk4iN6)
The only Python feature I think personally Python has an advantage over C are templates. Some features like virtual classes can be implemented in C, although it won't be pretty it is still possible. Python just standardizes it and hides it from the user. So in some situations, such as programming a compiler, it'll be easier to create a C compiler than a Python compiler because of said wonderful features.

Pick the right tool for the right job. Some programming languages are specialized to do specific takes. If you try to make a programming language do too much it becomes too complex to program in and thus will have no user base. The argument of C being faster than Python or vis-versa is irrelevant, go argue with the people saying Java is faster than C/Python. Point being with how fast hardware is the difference in speed is so minute it doesn't matter at the application level on PC's anyways (note: android uses Java, although they hacked on C/Python [ note: horribly supported ] cause of performance issues for some things).

OpenCL/Cuda > C/Python (read: flops)
Last edited on Jun 24, 2012 at 6:41am
Jun 24, 2012 at 6:48am
The only Python feature I think personally Python has an advantage over C are templates. Some features like virtual classes can be implemented in C, although it won't be pretty it is still possible


Anything Python does can be implemented in C, even templates (typically the same thing is done with macros in C). Yeah it isn't pretty, but it's possible.

Drawing a line for templates and nothing else is rather arbitrary.

Generally speaking, comparing languages is a waste of time. Comparing languages based on what it can do is an even bigger waste of time because all turing complete languages can do everything. What you're really comparing is how the language does it.
Jun 24, 2012 at 7:16am
closed account (o1vk4iN6)
Well said, although templates are also turing complete. I don't think it's possible to use the preprocessor for meta programming, this is something that cannot be replicated in C, to my knowledge. I'd be happy if you can prove me wrong though, can always learn something new.
Last edited on Jun 24, 2012 at 7:18am
Jun 24, 2012 at 1:14pm
xerci wrote:
The only Python feature I think personally Python has an advantage over C are templates. Some features like virtual classes can be implemented in C, although it won't be pretty it is still possible.


And what about RAII? I find it really hard to take seriously any language that doesn't offer such a trivial but immensely powerful thing. I'd hate be forced to adhere to something silly like single-entry, single-exit just because the language doesn't offer me a simple, reliable way of telling the compiler to "do-this-on-scope-exit".

Also, how is the fact that Python supports runtime polymorphism NATIVELY not an advantage?

Disch wrote:

Generally speaking, comparing languages is a waste of time. Comparing languages based on what it can do is an even bigger waste of time because all turing complete languages can do everything. What you're really comparing is how the language does it.


No, it's not. I hear that said a lot, but it's not. If language A and B both support feature X in some shape or form but language A makes it easy and straight-forward whereas language B makes you jump through hoops then language A is quite simply superior in that particular aspect.
Jun 24, 2012 at 1:53pm
Whovian wrote:
[quote=James Kanze]Among the things that you can do in C, but not in Python, are:

-- not declare external functions, then call them with the
wrong number or type of arguments,
[/quote]
How is that an advantage? It just shows how bad C is!
Jun 24, 2012 at 2:34pm
@antred:

When deciding on a language for a specific task, examining the language's strengths and choosing which one is best for the task is worthwhile. I agree with that.

But the general theme with these threads are "which language is better", which is a fruitless debate because each language has its own strengths and weaknesses.
Jun 24, 2012 at 3:05pm
closed account (3TXyhbRD)
Hello,

Don't forget that besides templates, Python offers try... catch statements. Ofc you can emulate that mechanism with line tickets and some goto's in C, however line naming can be problematic from one point.

Like it was said, C was designed for one thing and Python for another. C was designed to rewrite Unix, it also is a really good tool for programming servers where Python is not, it doesn't even have sockets, you need to use C sockets (ofc using the respective OS libraries, but still they are from C and not made object oriented in Python). Same goes for IPCs.

Usually, you compare two languages to know which to use in a given context.
For instance, when you're programming a microprocessor you won't be using Python, you will be using C (given that the producer offers a library where you have a few functions implemented for you to use and not get in assembly stuff, even if you have to write assembly stuff you will still probably end up in C code rather than Python).
If you're designing an application with lots of features we see these days, you will be using Python (or other object oriented languages) since OOD makes life much more easier and any design pattern is harder to apply in C than in Python. You can bypass C's structured form and make "objects" and emulate almost anything Python has, but still it's not meant for that.

C vs Python = win - win scenario, they're both excellent tools and very good for what they're designed to do. Trying to know only one of them (even if C is included in Python) in an attempt to learn less and it's a fools quest. Emulating Python in C is rubbish for a real application (but a good programming exercise), using only Python stuff is limiting because of above statements (sockets, IPCs, fork etc.). Using a C, Python combo may prove a lack of knowledge between the both (horrible for a professional, but acceptable for a beginner).

Just my tuppence worth,
Good day!
Jun 24, 2012 at 3:32pm
LilJoe wrote:
C was designed to rewrite Unix, it also is a really good tool for programming servers where Python is not, it doesn't even have sockets, you need to use C sockets (ofc using the respective OS libraries, but still they are from C and not made object oriented in Python). Same goes for IPCs.


You're using a C library. You're not necessarily writing C just because you use a C library. Writing a server in Python is perfectly viable and, I find, a heck of a lot easier and less error-prone than doing the same in C.
Jun 24, 2012 at 4:08pm
Python offers try... catch statements. Ofc you can emulate that mechanism with line tickets and some goto's in C
I don't think you can. You can simulate the transfer of control, but you can't simulate the management of objects and dealing with the error class hierarchy. OpenSSL has an extensible error hierarchy in C for example, but you can't handle the error at the level of your choosing.

C was designed to rewrite Unix, it also is a really good tool for programming servers where Python is not
That's an interesting perspective. Can you explain why you think this is the case?

it doesn't even have sockets, you need to use C sockets
The sockets library is written in C because Unix is written in C. The sockets library does have an OO design, but because C doesn't support OO, the burden is pushed back onto programmers to enforce, making it difficult to use.

For example, you wouldn't expect to use send/recv with a UDP socket, but there's nothing to stop you making the call. A decent Python sockets library will not have send/recv methods on a UDP socket, eliminating that kind of error. And all this extra type checking doesn't have a run-time cost.

Same goes for IPCs.
Agreed, same argument for sockets goes for IPCs.

Clearly features like templates generate more code and the exceptions require a more complicated run-time environment. So there's a price for some things, some things like Classes for implementing abstract data types with RAII is free.
Pages: 12